Source Code Cross Referenced for CmsTabDialog.java in  » Content-Management-System » opencms » org » opencms » workplace » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsTabDialog.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:45 $
004:         * Version: $Revision: 1.24 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.workplace;
033:
034:        import org.opencms.i18n.CmsEncoder;
035:        import org.opencms.jsp.CmsJspActionElement;
036:        import org.opencms.main.CmsLog;
037:        import org.opencms.util.CmsStringUtil;
038:
039:        import java.util.Iterator;
040:        import java.util.List;
041:        import java.util.Map;
042:
043:        import javax.servlet.http.HttpServletRequest;
044:        import javax.servlet.http.HttpServletResponse;
045:        import javax.servlet.jsp.PageContext;
046:
047:        import org.apache.commons.logging.Log;
048:
049:        /**
050:         * Provides methods for tab styled dialogs.<p> 
051:         * 
052:         * Extend this class in order to create a tab styled dialog and provide the methods
053:         * getTabs() and getTabParameterOrder() in the new dialog class which should return lists
054:         * which represent the tabs of the dialog.<p> 
055:         * 
056:         * This class is used for the following dialogs:
057:         * <ul>
058:         * <li>User preferences (CmsPreferences.java)
059:         * </ul>
060:         * <p>
061:         *
062:         * @author  Andreas Zahner 
063:         * 
064:         * @version $Revision: 1.24 $ 
065:         * 
066:         * @since 6.0.0 
067:         */
068:        public abstract class CmsTabDialog extends CmsDialog {
069:
070:            /** Value for the action: switch the tab. */
071:            public static final int ACTION_SWITCHTAB = 100;
072:
073:            /** Request parameter value for the action: switch the tab. */
074:            public static final String DIALOG_SWITCHTAB = "switchtab";
075:
076:            /** Name of the request parameter for the set button pressed flag. */
077:            public static final String PARAM_SETPRESSED = "setpressed";
078:            /** Name of the request parameter for the current tab. */
079:            public static final String PARAM_TAB = "tab";
080:
081:            /** The log object for this class. */
082:            private static final Log LOG = CmsLog.getLog(CmsTabDialog.class);
083:
084:            /** Stores the currently active tab. */
085:            private int m_activeTab = -1;
086:            /** Determines if the "set" button was pressed. */
087:            private String m_paramSetPressed;
088:
089:            /** Stores the current tab. */
090:            private String m_paramTab;
091:
092:            /**
093:             * Public constructor.<p>
094:             * 
095:             * @param jsp an initialized JSP action element
096:             */
097:            public CmsTabDialog(CmsJspActionElement jsp) {
098:
099:                super (jsp);
100:            }
101:
102:            /**
103:             * Public constructor with JSP variables.<p>
104:             * 
105:             * @param context the JSP page context
106:             * @param req the JSP request
107:             * @param res the JSP response
108:             */
109:            public CmsTabDialog(PageContext context, HttpServletRequest req,
110:                    HttpServletResponse res) {
111:
112:                this (new CmsJspActionElement(context, req, res));
113:            }
114:
115:            /**
116:             * Builds the tab content area of the dialog window.<p>
117:             * 
118:             * @param segment the HTML segment (START / END)
119:             * @param title the title String for the dialog window
120:             * @param attributes additional attributes for the content &lt;div&gt; area of the tab dialog
121:             * @return a tab content area start / end segment
122:             */
123:            public String dialogTabContent(int segment, String title,
124:                    String attributes) {
125:
126:                if (segment == HTML_START) {
127:                    StringBuffer result = new StringBuffer(512);
128:                    // null title is ok, we always want the title headline
129:                    result.append(dialogHead(title));
130:                    result
131:                            .append("<div class=\"dialogtabstart\" unselectable=\"on\">\n");
132:                    result.append("<!-- dialogtabs start -->\n");
133:                    result.append(dialogTabRow());
134:                    result.append("<div class=\"dialogtabcontent\"");
135:                    if (attributes != null) {
136:                        result.append(" " + attributes);
137:                    }
138:                    result.append(">\n");
139:                    result.append("<!-- dialogcontent start -->\n");
140:                    return result.toString();
141:                } else {
142:                    return "\n<!-- dialogcontent end --></div>\n<!-- dialogtabs end --></div>";
143:                }
144:            }
145:
146:            /**
147:             * Returns the end html for the tab content area of the dialog window.<p>
148:             * 
149:             * @return the end html for the tab content area of the dialog window
150:             */
151:            public String dialogTabContentEnd() {
152:
153:                return dialogTabContent(HTML_END, null, null);
154:            }
155:
156:            /**
157:             * Returns the start html for the tab content area of the dialog window.<p>
158:             * 
159:             * @param title the title for the dialog
160:             * @return the start html for the tab content area of the dialog window
161:             */
162:            public String dialogTabContentStart(String title) {
163:
164:                return dialogTabContent(HTML_START, title, null);
165:            }
166:
167:            /**
168:             * Returns the start html for the tab content area of the dialog window.<p>
169:             * 
170:             * @param title the title for the dialog
171:             * @param attributes additional attributes for the content &lt;div&gt; area of the tab dialog
172:             * @return the start html for the tab content area of the dialog window
173:             */
174:            public String dialogTabContentStart(String title, String attributes) {
175:
176:                return dialogTabContent(HTML_START, title, attributes);
177:            }
178:
179:            /**
180:             * Builds the html for the tab row of the tab dialog.<p>
181:             * 
182:             * @return the html for the tab row
183:             */
184:            public String dialogTabRow() {
185:
186:                StringBuffer result = new StringBuffer(512);
187:                StringBuffer lineRow = new StringBuffer(256);
188:                List tabNames = getTabs();
189:                if (tabNames.size() < 2) {
190:                    // less than 2 tabs present, do not show them and create a border line
191:                    result
192:                            .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\" style=\"empty-cells: show;\">\n");
193:                    result.append("<tr>\n");
194:                    result.append("\t<td class=\"dialogtabrow\"></td>\n");
195:                    result.append("</tr>\n");
196:                    result.append("</table>\n");
197:                    return result.toString();
198:                }
199:                Iterator i = tabNames.iterator();
200:                int counter = 1;
201:                int activeTab = getActiveTab();
202:                result
203:                        .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\" style=\"empty-cells: show;\">\n");
204:                result.append("<tr>\n");
205:                while (i.hasNext()) {
206:                    // build a tab entry
207:                    String curTab = (String) i.next();
208:                    String curTabLink = "javascript:openTab('" + counter
209:                            + "');";
210:                    if (counter == activeTab) {
211:                        // create the currently active tab
212:                        int addDelta = 0;
213:                        result.append("\t<td class=\"dialogtabactive\"");
214:                        if (counter == 1) {
215:                            // for first tab, add special html for correct layout
216:                            result.append(" style=\"border-left-width: 1px;\"");
217:                            addDelta = 1;
218:                        }
219:                        result.append(">");
220:                        result
221:                                .append("<span class=\"tabactive\" unselectable=\"on\"");
222:                        result.append(" style=\"width: "
223:                                + (curTab.length() * 8 + addDelta) + "px;\"");
224:                        result.append(">");
225:                        result.append(curTab);
226:                        result.append("</span></td>\n");
227:                        lineRow.append("\t<td></td>\n");
228:                    } else {
229:                        // create an inactive tab
230:                        result
231:                                .append("\t<td class=\"dialogtab\" unselectable=\"on\">");
232:                        result.append("<a class=\"tab\" href=\"" + curTabLink
233:                                + "\"");
234:                        result.append(" style=\"width: "
235:                                + (curTab.length() * 8) + "px;\"");
236:                        result.append(">");
237:                        result.append(curTab);
238:                        result.append("</a></td>\n");
239:                        lineRow.append("\t<td class=\"dialogtabrow\"></td>\n");
240:                    }
241:
242:                    counter++;
243:                }
244:                result.append("\t<td class=\"maxwidth\"></td>\n");
245:                result.append("</tr>\n");
246:                result.append("<tr>\n");
247:                result.append(lineRow);
248:                result.append("\t<td class=\"dialogtabrow\"></td>\n");
249:                result.append("</tr>\n");
250:                result.append("</table>\n");
251:                return result.toString();
252:            }
253:
254:            /**
255:             * Returns the number of the currently active tab depending on the request parameter.<p>
256:             * 
257:             * This method has to be called once in initWorkplaceRequestValues after filling the request parameters.<p>
258:             * 
259:             * @return the number of the currently active tab
260:             */
261:            public int getActiveTab() {
262:
263:                if (m_activeTab < 0) {
264:                    String paramTab = getParamTab();
265:                    int tab = 1;
266:                    if (CmsStringUtil.isNotEmpty(paramTab)) {
267:                        try {
268:                            tab = Integer.parseInt(paramTab);
269:                        } catch (NumberFormatException e) {
270:                            // do nothing, the first tab is returned
271:                            if (LOG.isInfoEnabled()) {
272:                                LOG.info(e.getLocalizedMessage());
273:                            }
274:                        }
275:                    }
276:                    setParamTab("" + tab);
277:                    m_activeTab = tab;
278:                    return tab;
279:                } else {
280:                    return m_activeTab;
281:                }
282:            }
283:
284:            /**
285:             * Returns the localized name of the currently active tab.<p>
286:             * 
287:             * @return the localized name of the currently active tab or null if no tab name was found
288:             */
289:            public String getActiveTabName() {
290:
291:                if (m_activeTab < 0) {
292:                    getActiveTab();
293:                }
294:                List tabNames = getTabs();
295:                try {
296:                    return (String) tabNames.get(m_activeTab - 1);
297:                } catch (IndexOutOfBoundsException e) {
298:                    // should usually never happen
299:                    if (LOG.isInfoEnabled()) {
300:                        LOG.info(e.getLocalizedMessage());
301:                    }
302:                    return null;
303:                }
304:            }
305:
306:            /**
307:             * Returns the value of the setpressed parameter.<p>
308:             * 
309:             * @return the value of the setpressed parameter
310:             */
311:            public String getParamSetPressed() {
312:
313:                return m_paramSetPressed;
314:            }
315:
316:            /**
317:             * Returns the value of the tab parameter.<p>
318:             * 
319:             * @return the value of the tab parameter
320:             */
321:            public String getParamTab() {
322:
323:                return m_paramTab;
324:            }
325:
326:            /**
327:             * Returns the order of the parameter prefixes for each tab.<p>
328:             * 
329:             * For example, all parameters stored in tab 1 have the prefix "Tab1", i.e.
330:             * the getter and setter methods must be getParam<b>Tab1</b>MyParameterName().<p>
331:             * 
332:             * To change the tab order, simply change the order in the String array 
333:             * and in the generated tab list.<p> 
334:             * 
335:             * @return the ordered parameter prefix List
336:             * @see org.opencms.workplace.CmsTabDialog#getTabs()
337:             */
338:            public abstract List getTabParameterOrder();
339:
340:            /**
341:             * Returns a list with localized Strings representing the names of the tabs.<p>
342:             * 
343:             * @return list with localized String for the tabs
344:             */
345:            public abstract List getTabs();
346:
347:            /**
348:             * Builds the start html of the page, including setting of DOCTYPE and 
349:             * inserting a header with the content-type.<p>
350:             * 
351:             * This overloads the default method of the parent class.<p>
352:             * 
353:             * @return the start html of the page
354:             */
355:            public String htmlStart() {
356:
357:                return htmlStart(null);
358:            }
359:
360:            /**
361:             * Builds the start html of the page, including setting of DOCTYPE and 
362:             * inserting a header with the content-type.<p>
363:             * 
364:             * This overloads the default method of the parent class.<p>
365:             * 
366:             * @param helpUrl the key for the online help to include on the page
367:             * @return the start html of the page
368:             */
369:            public String htmlStart(String helpUrl) {
370:
371:                String stylesheet = null;
372:                if (isPopup()) {
373:                    stylesheet = "popup.css";
374:                }
375:                StringBuffer result = new StringBuffer(super .pageHtmlStyle(
376:                        HTML_START, null, stylesheet));
377:                if (getSettings().isViewExplorer()) {
378:                    result.append("<script type=\"text/javascript\" src=\"");
379:                    result.append(getSkinUri());
380:                    result.append("commons/explorer.js\"></script>\n");
381:                }
382:                result.append("<script type=\"text/javascript\">\n");
383:                if (helpUrl != null) {
384:                    result.append("top.head.helpUrl=\"");
385:                    result.append(helpUrl + "\";\n");
386:
387:                }
388:                // js to switch the dialog tabs
389:                result.append("function openTab(tabValue) {\n");
390:                result.append("\tdocument.forms[0]." + PARAM_TAB
391:                        + ".value = tabValue;\n");
392:                result.append("\tdocument.forms[0]." + PARAM_ACTION
393:                        + ".value = \"" + DIALOG_SWITCHTAB + "\";\n");
394:                result.append("\tdocument.forms[0].submit();\n");
395:                result.append("}\n");
396:                // js for the button actions, overwrites CmsDialog.dialogScriptSubmit() js method
397:                result
398:                        .append("function submitAction(actionValue, theForm, formName) {\n");
399:                result.append("\tif (theForm == null) {\n");
400:                result.append("\t\ttheForm = document.forms[formName];\n");
401:                result.append("\t}\n");
402:                result.append("\ttheForm." + PARAM_FRAMENAME
403:                        + ".value = window.name;\n");
404:                result.append("\tif (actionValue == \"" + DIALOG_SET
405:                        + "\") {\n");
406:                result.append("\t\ttheForm." + PARAM_ACTION + ".value = \""
407:                        + DIALOG_SET + "\";\n");
408:                result.append("\t} else if (actionValue == \"" + DIALOG_CANCEL
409:                        + "\") {\n");
410:                result.append("\t\ttheForm." + PARAM_ACTION + ".value = \""
411:                        + DIALOG_CANCEL + "\";\n");
412:                result.append("\t}\n");
413:                result.append("\ttheForm.submit();\n");
414:                result.append("\treturn false;\n");
415:                result.append("}\n");
416:                result.append("//-->\n</script>\n");
417:                return result.toString();
418:            }
419:
420:            /**
421:             * Returns all initialized parameters of the current workplace class 
422:             * as hidden field tags that can be inserted in a form.<p>
423:             * 
424:             * This overwrites the method in CmsWorkplace because for each tab, 
425:             * only the hidden parameters of the non displayed tabs are added.<p> 
426:             * 
427:             * @return all initialized parameters of the current workplace class
428:             * as hidden field tags that can be inserted in a html form
429:             */
430:            public String paramsAsHidden() {
431:
432:                StringBuffer result = new StringBuffer(512);
433:                String activeTab = (String) getTabParameterOrder().get(
434:                        getActiveTab() - 1);
435:                Map params = paramValues();
436:                Iterator i = params.entrySet().iterator();
437:                while (i.hasNext()) {
438:                    Map.Entry entry = (Map.Entry) i.next();
439:                    String param = (String) entry.getKey();
440:                    if (!param.startsWith(activeTab)) {
441:                        // add only parameters which are not displayed in currently active tab
442:                        result.append("<input type=\"hidden\" name=\"");
443:                        result.append(param);
444:                        result.append("\" value=\"");
445:                        result.append(CmsEncoder.encode(entry.getValue()
446:                                .toString(), getCms().getRequestContext()
447:                                .getEncoding()));
448:                        result.append("\">\n");
449:                    }
450:                }
451:                return result.toString();
452:            }
453:
454:            /**
455:             * Sets the value of the setpressed parameter.<p>
456:             * 
457:             * @param value the value to set
458:             */
459:            public void setParamSetPressed(String value) {
460:
461:                m_paramSetPressed = value;
462:            }
463:
464:            /**
465:             * Sets the value of the tab parameter.<p>
466:             * 
467:             * @param value the value to set
468:             */
469:            public void setParamTab(String value) {
470:
471:                m_paramTab = value;
472:            }
473:
474:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.