Source Code Cross Referenced for A_CmsListDialog.java in  » Content-Management-System » opencms » org » opencms » workplace » list » 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.list 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/A_CmsListDialog.java,v $
0003:         * Date   : $Date: 2008-02-27 12:05:28 $
0004:         * Version: $Revision: 1.39 $
0005:         *
0006:         * This library is part of OpenCms -
0007:         * the Open Source Content Management System
0008:         *
0009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
0010:         *
0011:         * This library is free software; you can redistribute it and/or
0012:         * modify it under the terms of the GNU Lesser General Public
0013:         * License as published by the Free Software Foundation; either
0014:         * version 2.1 of the License, or (at your option) any later version.
0015:         *
0016:         * This library is distributed in the hope that it will be useful,
0017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0019:         * Lesser General Public License for more details.
0020:         *
0021:         * For further information about Alkacon Software GmbH, please see the
0022:         * company website: http://www.alkacon.com
0023:         *
0024:         * For further information about OpenCms, please see the
0025:         * project website: http://www.opencms.org
0026:         * 
0027:         * You should have received a copy of the GNU Lesser General Public
0028:         * License along with this library; if not, write to the Free Software
0029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0030:         */
0031:
0032:        package org.opencms.workplace.list;
0033:
0034:        import org.opencms.i18n.CmsMessageContainer;
0035:        import org.opencms.jsp.CmsJspActionElement;
0036:        import org.opencms.main.CmsException;
0037:        import org.opencms.main.CmsLog;
0038:        import org.opencms.main.CmsRuntimeException;
0039:        import org.opencms.util.CmsStringUtil;
0040:        import org.opencms.workplace.CmsDialog;
0041:        import org.opencms.workplace.CmsWorkplaceSettings;
0042:        import org.opencms.workplace.tools.CmsToolDialog;
0043:
0044:        import java.io.IOException;
0045:        import java.util.ArrayList;
0046:        import java.util.HashMap;
0047:        import java.util.Hashtable;
0048:        import java.util.Iterator;
0049:        import java.util.List;
0050:        import java.util.Map;
0051:
0052:        import javax.servlet.ServletException;
0053:        import javax.servlet.http.HttpServletRequest;
0054:        import javax.servlet.jsp.JspException;
0055:        import javax.servlet.jsp.JspWriter;
0056:
0057:        import org.apache.commons.logging.Log;
0058:
0059:        /**
0060:         * Provides a dialog with a list widget.<p> 
0061:         *
0062:         * @author  Michael Moossen 
0063:         * 
0064:         * @version $Revision: 1.39 $ 
0065:         * 
0066:         * @since 6.0.0 
0067:         */
0068:        public abstract class A_CmsListDialog extends CmsDialog {
0069:
0070:            /** Value for the action: execute a list item independent action of the list. */
0071:            public static final int ACTION_LIST_INDEPENDENT_ACTION = 83;
0072:
0073:            /** Value for the action: execute an multi action of the list. */
0074:            public static final int ACTION_LIST_MULTI_ACTION = 85;
0075:
0076:            /** Value for the action: search the list. */
0077:            public static final int ACTION_LIST_SEARCH = 81;
0078:
0079:            /** Value for the action: go to a page. */
0080:            public static final int ACTION_LIST_SELECT_PAGE = 82;
0081:
0082:            /** Value for the action: execute a single action of the list. */
0083:            public static final int ACTION_LIST_SINGLE_ACTION = 84;
0084:
0085:            /** Value for the action: sort the list. */
0086:            public static final int ACTION_LIST_SORT = 80;
0087:
0088:            /** Standard list button location. */
0089:            public static final String ICON_ACTIVE = "list/active.png";
0090:
0091:            /** Standard list button location. */
0092:            public static final String ICON_ADD = "list/add.png";
0093:
0094:            /** Standard list button location. */
0095:            public static final String ICON_DELETE = "list/delete.png";
0096:
0097:            /** Standard list button location. */
0098:            public static final String ICON_DETAILS_HIDE = "list/details_hide.png";
0099:
0100:            /** Standard list button location. */
0101:            public static final String ICON_DETAILS_SHOW = "list/details_show.png";
0102:
0103:            /** Standard list button location. */
0104:            public static final String ICON_DISABLED = "list/disabled.png";
0105:
0106:            /** Standard list button location. */
0107:            public static final String ICON_INACTIVE = "list/inactive.png";
0108:
0109:            /** Standard list button location. */
0110:            public static final String ICON_MINUS = "list/minus.png";
0111:
0112:            /** Standard list button location. */
0113:            public static final String ICON_MULTI_ACTIVATE = "list/multi_activate.png";
0114:
0115:            /** Standard list button location. */
0116:            public static final String ICON_MULTI_ADD = "list/multi_add.png";
0117:
0118:            /** Standard list button location. */
0119:            public static final String ICON_MULTI_DEACTIVATE = "list/multi_deactivate.png";
0120:
0121:            /** Standard list button location. */
0122:            public static final String ICON_MULTI_DELETE = "list/multi_delete.png";
0123:
0124:            /** Standard list button location. */
0125:            public static final String ICON_MULTI_MINUS = "list/multi_minus.png";
0126:
0127:            /** Request parameter value for the list action: a list item independent action has been triggered. */
0128:            public static final String LIST_INDEPENDENT_ACTION = "listindependentaction";
0129:
0130:            /** Request parameter value for the list action: a multi action has been triggered. */
0131:            public static final String LIST_MULTI_ACTION = "listmultiaction";
0132:
0133:            /** Request parameter value for the list action: search/filter. */
0134:            public static final String LIST_SEARCH = "listsearch";
0135:
0136:            /** Request parameter value for the list action: select a page. */
0137:            public static final String LIST_SELECT_PAGE = "listselectpage";
0138:
0139:            /** Request parameter value for the list action: a single action has been triggered. */
0140:            public static final String LIST_SINGLE_ACTION = "listsingleaction";
0141:
0142:            /** Request parameter value for the list action: sort. */
0143:            public static final String LIST_SORT = "listsort";
0144:
0145:            /** Request parameter key for the requested page. */
0146:            public static final String PARAM_FORMNAME = "formname";
0147:
0148:            /** Request parameter key for the list action. */
0149:            public static final String PARAM_LIST_ACTION = "listaction";
0150:
0151:            /** Request parameter key for the requested page. */
0152:            public static final String PARAM_PAGE = "page";
0153:
0154:            /** Request parameter key for search the filter. */
0155:            public static final String PARAM_SEARCH_FILTER = "searchfilter";
0156:
0157:            /** Request parameter key for the selected item(s). */
0158:            public static final String PARAM_SEL_ITEMS = "selitems";
0159:
0160:            /** Request parameter key for the column to sort the list. */
0161:            public static final String PARAM_SORT_COL = "sortcol";
0162:
0163:            /** The log object for this class. */
0164:            private static final Log LOG = CmsLog.getLog(A_CmsListDialog.class);
0165:
0166:            /** metadata map for all used list metadata objects. */
0167:            private static Map m_metadatas = new HashMap();
0168:
0169:            /** Activation decision Flag. */
0170:            private boolean m_active;
0171:
0172:            /** the internal list. */
0173:            private CmsHtmlList m_list;
0174:
0175:            /** The id of the list. */
0176:            private String m_listId;
0177:
0178:            /** Cached List state in case of {@link #refreshList()} method call. */
0179:            private CmsListState m_listState;
0180:
0181:            /** The displayed page. */
0182:            private String m_paramFormName;
0183:
0184:            /** The list action. */
0185:            private String m_paramListAction;
0186:
0187:            /** The displayed page. */
0188:            private String m_paramPage;
0189:
0190:            /** The search filter text. */
0191:            private String m_paramSearchFilter;
0192:
0193:            /** The selected items, comma separated list. */
0194:            private String m_paramSelItems;
0195:
0196:            /** The column to sort the list. */
0197:            private String m_paramSortCol;
0198:
0199:            /** The column to search the list. */
0200:            private String m_searchColId;
0201:
0202:            /**
0203:             * Public constructor.<p>
0204:             * 
0205:             * @param jsp an initialized JSP action element
0206:             * @param listId the id of the displayed list
0207:             * @param listName the name of the list
0208:             * @param sortedColId the a priory sorted column
0209:             * @param sortOrder the order of the sorted column
0210:             * @param searchableColId the column to search into
0211:             */
0212:            protected A_CmsListDialog(CmsJspActionElement jsp, String listId,
0213:                    CmsMessageContainer listName, String sortedColId,
0214:                    CmsListOrderEnum sortOrder, String searchableColId) {
0215:
0216:                super (jsp);
0217:
0218:                if (LOG.isDebugEnabled()) {
0219:                    LOG.debug(Messages.get().getBundle().key(
0220:                            Messages.LOG_START_INIT_LIST_1, listId));
0221:                }
0222:                // set list id
0223:                m_listId = listId;
0224:                // set active flag for 2 lists dialog
0225:                m_active = (getListId() + "-form").equals(getParamFormName());
0226:                setParamFormName(getListId() + "-form");
0227:                // abort if already forwarded
0228:                if (isForwarded()) {
0229:                    return;
0230:                }
0231:                m_searchColId = searchableColId;
0232:                // try to read the list from the session
0233:                listRecovery(listId);
0234:                // initialization 
0235:                if (getList() == null) {
0236:                    // create the list
0237:                    setList(new CmsHtmlList(listId, listName, getMetadata(this 
0238:                            .getClass().getName(), listId)));
0239:                    // set the number of items per page from the user settings
0240:                    getList().setMaxItemsPerPage(
0241:                            getSettings().getUserSettings()
0242:                                    .getExplorerFileEntries());
0243:                    // sort the list
0244:                    if ((sortedColId != null)
0245:                            && (getList().getMetadata().getColumnDefinition(
0246:                                    sortedColId) != null)) {
0247:                        getList().setWp(this );
0248:                        getList().setSortedColumn(sortedColId);
0249:                        if ((sortOrder != null)
0250:                                && (sortOrder == CmsListOrderEnum.ORDER_DESCENDING)) {
0251:                            getList().setSortedColumn(sortedColId);
0252:                        }
0253:                    }
0254:                    // save the current state of the list
0255:                    listSave();
0256:                }
0257:                getList().setWp(this );
0258:                if (LOG.isDebugEnabled()) {
0259:                    LOG.debug(Messages.get().getBundle().key(
0260:                            Messages.LOG_END_INIT_LIST_1, listId));
0261:                }
0262:            }
0263:
0264:            /**
0265:             * Returns the list object for the given list dialog, or <code>null</code>
0266:             * if no list object has been set.<p>
0267:             * 
0268:             * @param listDialog the list dialog class
0269:             * @param settings the wp settings for accessing the session
0270:             * 
0271:             * @return the list object for this list dialog, or <code>null</code>
0272:             */
0273:            public static CmsHtmlList getListObject(Class listDialog,
0274:                    CmsWorkplaceSettings settings) {
0275:
0276:                return (CmsHtmlList) getListObjectMap(settings).get(
0277:                        listDialog.getName());
0278:            }
0279:
0280:            /**
0281:             * Returns the list metadata object for the given dialog.<p>
0282:             * 
0283:             * @param listDialogName the dialog class name
0284:             * 
0285:             * @return the list metadata object
0286:             */
0287:            public static CmsListMetadata getMetadata(String listDialogName) {
0288:
0289:                return (CmsListMetadata) m_metadatas.get(listDialogName);
0290:            }
0291:
0292:            /**
0293:             * Returns the (internal use only) map of list objects.<p>
0294:             * 
0295:             * @param settings the wp settings for accessing the session 
0296:             * 
0297:             * @return the (internal use only) map of list objects 
0298:             */
0299:            private static Map getListObjectMap(CmsWorkplaceSettings settings) {
0300:
0301:                Map objects = (Map) settings.getListObject();
0302:                if (objects == null) {
0303:                    // using hashtable as most efficient version of a synchronized map
0304:                    objects = new Hashtable();
0305:                    settings.setListObject(objects);
0306:                }
0307:                return objects;
0308:            }
0309:
0310:            /**
0311:             * Performs the dialog actions depending on the initialized action.<p>
0312:             * 
0313:             * @throws JspException if dialog actions fail
0314:             * @throws IOException in case of errors forwarding to the required result page
0315:             * @throws ServletException in case of errors forwarding to the required result page
0316:             */
0317:            public void actionDialog() throws JspException, ServletException,
0318:                    IOException {
0319:
0320:                if (isForwarded()) {
0321:                    return;
0322:                }
0323:                if (getAction() == ACTION_CANCEL) {
0324:                    // ACTION: cancel button pressed
0325:                    actionCloseDialog();
0326:                    return;
0327:                }
0328:
0329:                if (LOG.isDebugEnabled()) {
0330:                    LOG.debug(Messages.get().getBundle().key(
0331:                            Messages.LOG_START_ACTION_LIST_2, getListId(),
0332:                            new Integer(getAction())));
0333:                }
0334:                switch (getAction()) {
0335:                //////////////////// ACTION: default actions
0336:                case ACTION_LIST_SEARCH:
0337:                case ACTION_LIST_SORT:
0338:                case ACTION_LIST_SELECT_PAGE:
0339:                    executeDefaultActions();
0340:                    break;
0341:
0342:                //////////////////// ACTION: execute single list action
0343:                case ACTION_LIST_SINGLE_ACTION:
0344:                    if (getSelectedItem() != null) {
0345:                        executeListSingleActions();
0346:                    }
0347:                    break;
0348:
0349:                //////////////////// ACTION: execute multiple list actions
0350:                case ACTION_LIST_MULTI_ACTION:
0351:                    executeListMultiActions();
0352:                    break;
0353:
0354:                //////////////////// ACTION: execute independent list actions
0355:                case ACTION_LIST_INDEPENDENT_ACTION:
0356:                    executeListIndepActions();
0357:                    break;
0358:
0359:                case ACTION_DEFAULT:
0360:                default:
0361:                    // ACTION: show dialog (default)
0362:                    setParamAction(DIALOG_INITIAL);
0363:                }
0364:                if (LOG.isDebugEnabled()) {
0365:                    LOG.debug(Messages.get().getBundle().key(
0366:                            Messages.LOG_END_ACTION_LIST_2, getListId(),
0367:                            new Integer(getAction())));
0368:                }
0369:                refreshList();
0370:            }
0371:
0372:            /**
0373:             * Generates the dialog starting html code.<p>
0374:             * 
0375:             * @return html code
0376:             */
0377:            public String defaultActionHtml() {
0378:
0379:                if ((getList() != null) && getList().getAllContent().isEmpty()) {
0380:                    // TODO: check the need for this
0381:                    refreshList();
0382:                }
0383:                StringBuffer result = new StringBuffer(2048);
0384:                result.append(defaultActionHtmlStart());
0385:                result.append(customHtmlStart());
0386:                result.append(defaultActionHtmlContent());
0387:                result.append(customHtmlEnd());
0388:                result.append(defaultActionHtmlEnd());
0389:                return result.toString();
0390:            }
0391:
0392:            /**
0393:             * Performs the dialog actions depending on the initialized action and displays the dialog form.<p>
0394:             * 
0395:             * @throws JspException if dialog actions fail
0396:             * @throws IOException if writing to the JSP out fails, or in case of errors forwarding to the required result page
0397:             * @throws ServletException in case of errors forwarding to the required result page
0398:             */
0399:            public void displayDialog() throws JspException, IOException,
0400:                    ServletException {
0401:
0402:                displayDialog(false);
0403:            }
0404:
0405:            /**
0406:             * Performs the dialog actions depending on the initialized action and displays the dialog form if needed.<p>
0407:             * 
0408:             * @param writeLater if <code>true</code> no output is written, 
0409:             *                   you have to call manually the <code>{@link #defaultActionHtml()}</code> method.
0410:             * 
0411:             * @throws JspException if dialog actions fail
0412:             * @throws IOException if writing to the JSP out fails, or in case of errors forwarding to the required result page
0413:             * @throws ServletException in case of errors forwarding to the required result page
0414:             */
0415:            public void displayDialog(boolean writeLater) throws JspException,
0416:                    IOException, ServletException {
0417:
0418:                actionDialog();
0419:                if (writeLater) {
0420:                    return;
0421:                }
0422:                writeDialog();
0423:            }
0424:
0425:            /**
0426:             * This method execute the default actions for searching, sorting and paging.<p>
0427:             */
0428:            public void executeDefaultActions() {
0429:
0430:                switch (getAction()) {
0431:
0432:                case ACTION_LIST_SEARCH:
0433:                    executeSearch();
0434:                    break;
0435:                case ACTION_LIST_SORT:
0436:                    executeSort();
0437:                    break;
0438:                case ACTION_LIST_SELECT_PAGE:
0439:                    executeSelectPage();
0440:                    break;
0441:                default:
0442:                    // ignore
0443:                }
0444:                listSave();
0445:            }
0446:
0447:            /**
0448:             * This method should handle the default list independent actions,
0449:             * by comparing <code>{@link #getParamListAction()}</code> with the id 
0450:             * of the action to execute.<p> 
0451:             * 
0452:             * if you want to handle additional independent actions, override this method,
0453:             * handling your actions and FINALLY calling <code>super.executeListIndepActions();</code>.<p> 
0454:             */
0455:            public void executeListIndepActions() {
0456:
0457:                if (getList().getMetadata().getItemDetailDefinition(
0458:                        getParamListAction()) != null) {
0459:                    // toggle item details
0460:                    getList().getMetadata().toogleDetailState(
0461:                            getParamListAction());
0462:                    // lazy initialization
0463:                    initializeDetail(getParamListAction());
0464:                }
0465:                listSave();
0466:            }
0467:
0468:            /**
0469:             * This method should handle every defined list multi action,
0470:             * by comparing <code>{@link #getParamListAction()}</code> with the id 
0471:             * of the action to execute.<p> 
0472:             *
0473:             * @throws IOException in case of errors when including a required sub-element
0474:             * @throws ServletException in case of errors when including a required sub-element
0475:             * @throws CmsRuntimeException to signal that an action is not supported
0476:             */
0477:            public abstract void executeListMultiActions() throws IOException,
0478:                    ServletException, CmsRuntimeException;
0479:
0480:            /**
0481:             * This method should handle every defined list single action,
0482:             * by comparing <code>{@link #getParamListAction()}</code> with the id 
0483:             * of the action to execute.<p> 
0484:             * 
0485:             * @throws IOException in case of errors when including a required sub-element
0486:             * @throws ServletException in case of errors when including a required sub-element
0487:             * @throws CmsRuntimeException to signal that an action is not supported
0488:             */
0489:            public abstract void executeListSingleActions() throws IOException,
0490:                    ServletException, CmsRuntimeException;
0491:
0492:            /**
0493:             * Returns the list.<p>
0494:             *
0495:             * @return the list
0496:             */
0497:            public CmsHtmlList getList() {
0498:
0499:                if ((m_list != null) && (m_list.getMetadata() == null)) {
0500:                    m_list.setMetadata(getMetadata(getClass().getName(), m_list
0501:                            .getId()));
0502:                }
0503:                return m_list;
0504:            }
0505:
0506:            /**
0507:             * Returns the Id of the list.<p>
0508:             *
0509:             * @return the list Id
0510:             */
0511:            public final String getListId() {
0512:
0513:                return m_listId;
0514:            }
0515:
0516:            /**
0517:             * Returns the form name.<p>
0518:             *
0519:             * @return the form name
0520:             */
0521:            public String getParamFormName() {
0522:
0523:                return m_paramFormName;
0524:            }
0525:
0526:            /**
0527:             * Returns the List Action.<p>
0528:             *
0529:             * @return the List Action
0530:             */
0531:            public String getParamListAction() {
0532:
0533:                return m_paramListAction;
0534:            }
0535:
0536:            /**
0537:             * Returns the current Page.<p>
0538:             *
0539:             * @return the current Page
0540:             */
0541:            public String getParamPage() {
0542:
0543:                return m_paramPage;
0544:            }
0545:
0546:            /**
0547:             * Returns the Search Filter.<p>
0548:             *
0549:             * @return the Search Filter
0550:             */
0551:            public String getParamSearchFilter() {
0552:
0553:                return m_paramSearchFilter;
0554:            }
0555:
0556:            /**
0557:             * Returns the selected Items.<p>
0558:             *
0559:             * @return the selected Items
0560:             */
0561:            public String getParamSelItems() {
0562:
0563:                return m_paramSelItems;
0564:            }
0565:
0566:            /**
0567:             * Returns the sorted Column.<p>
0568:             *
0569:             * @return the sorted Column
0570:             */
0571:            public String getParamSortCol() {
0572:
0573:                return m_paramSortCol;
0574:            }
0575:
0576:            /**
0577:             * Returns the current selected item.<p>
0578:             * 
0579:             * @return the current selected item
0580:             */
0581:            public CmsListItem getSelectedItem() {
0582:
0583:                try {
0584:                    return getList().getItem(
0585:                            CmsStringUtil.splitAsArray(getParamSelItems(),
0586:                                    CmsHtmlList.ITEM_SEPARATOR)[0].trim());
0587:                } catch (Exception e) {
0588:                    try {
0589:                        return getList().getItem("");
0590:                    } catch (Exception e1) {
0591:                        return null;
0592:                    }
0593:                }
0594:            }
0595:
0596:            /**
0597:             * Returns a list of current selected items.<p>
0598:             * 
0599:             * @return a list of current selected items
0600:             */
0601:            public List getSelectedItems() {
0602:
0603:                Iterator it = CmsStringUtil.splitAsList(getParamSelItems(),
0604:                        CmsHtmlList.ITEM_SEPARATOR, true).iterator();
0605:                List items = new ArrayList();
0606:                while (it.hasNext()) {
0607:                    String id = (String) it.next();
0608:                    items.add(getList().getItem(id));
0609:                }
0610:                return items;
0611:            }
0612:
0613:            /**
0614:             * Returns the activation flag.<p>
0615:             *
0616:             * Useful for dialogs with several lists.<p>
0617:             * 
0618:             * Is <code></code> if the original <code>formname</code> parameter 
0619:             * is equals to <code>${listId}-form</code>.<p>
0620:             * 
0621:             * @return the activation flag
0622:             */
0623:            public boolean isActive() {
0624:
0625:                return m_active;
0626:            }
0627:
0628:            /**
0629:             * This method re-read the rows of the list, the user should call this method after executing an action
0630:             * that add or remove rows to the list.<p>
0631:             */
0632:            public synchronized void refreshList() {
0633:
0634:                if (getList() == null) {
0635:                    return;
0636:                }
0637:                if (LOG.isDebugEnabled()) {
0638:                    LOG.debug(Messages.get().getBundle().key(
0639:                            Messages.LOG_START_REFRESH_LIST_1, getListId()));
0640:                }
0641:                m_listState = getList().getState();
0642:                getList().clear();
0643:                fillList();
0644:                getList().setState(m_listState);
0645:                m_listState = null;
0646:                listSave();
0647:                if (LOG.isDebugEnabled()) {
0648:                    LOG.debug(Messages.get().getBundle().key(
0649:                            Messages.LOG_END_REFRESH_LIST_1, getListId()));
0650:                }
0651:            }
0652:
0653:            /**
0654:             * Removes the list from the workplace settings.<p>
0655:             * 
0656:             * Next time the list is displayed the list will be reloaded.<p>
0657:             */
0658:            public void removeList() {
0659:
0660:                setList(null);
0661:                listSave();
0662:            }
0663:
0664:            /**
0665:             * Sets the list.<p>
0666:             *
0667:             * @param list the list to set
0668:             */
0669:            public void setList(CmsHtmlList list) {
0670:
0671:                m_list = list;
0672:            }
0673:
0674:            /**
0675:             * Stores the given object as "list object" for the given list dialog in the current users session.<p> 
0676:             * 
0677:             * @param listDialog the list dialog class
0678:             * @param listObject the list to store
0679:             */
0680:            public void setListObject(Class listDialog, CmsHtmlList listObject) {
0681:
0682:                if (listObject == null) {
0683:                    // null object: remove the entry from the map
0684:                    getListObjectMap(getSettings())
0685:                            .remove(listDialog.getName());
0686:                } else {
0687:                    if ((listObject.getMetadata() != null)
0688:                            && listObject.getMetadata().isVolatile()) {
0689:                        listObject.setMetadata(null);
0690:                    }
0691:                    getListObjectMap(getSettings()).put(listDialog.getName(),
0692:                            listObject);
0693:                }
0694:            }
0695:
0696:            /**
0697:             * Sets the form name.<p>
0698:             *
0699:             * @param formName the form name to set
0700:             */
0701:            public void setParamFormName(String formName) {
0702:
0703:                m_paramFormName = formName;
0704:            }
0705:
0706:            /**
0707:             * Sets the List Action.<p>
0708:             *
0709:             * @param listAction the list Action to set
0710:             */
0711:            public void setParamListAction(String listAction) {
0712:
0713:                m_paramListAction = listAction;
0714:            }
0715:
0716:            /**
0717:             * Sets the current Page.<p>
0718:             *
0719:             * @param page the current Page to set
0720:             */
0721:            public void setParamPage(String page) {
0722:
0723:                m_paramPage = page;
0724:            }
0725:
0726:            /**
0727:             * Sets the Search Filter.<p>
0728:             *
0729:             * @param searchFilter the Search Filter to set
0730:             */
0731:            public void setParamSearchFilter(String searchFilter) {
0732:
0733:                m_paramSearchFilter = searchFilter;
0734:            }
0735:
0736:            /**
0737:             * Sets the selected Items.<p>
0738:             *
0739:             * @param paramSelItems the selected Items to set
0740:             */
0741:            public void setParamSelItems(String paramSelItems) {
0742:
0743:                m_paramSelItems = paramSelItems;
0744:            }
0745:
0746:            /**
0747:             * Sets the sorted Column.<p>
0748:             *
0749:             * @param sortCol the sorted Column to set
0750:             */
0751:            public void setParamSortCol(String sortCol) {
0752:
0753:                m_paramSortCol = sortCol;
0754:            }
0755:
0756:            /**
0757:             * Writes the dialog html code, only if the <code>{@link #ACTION_DEFAULT}</code> is set.<p>
0758:             * 
0759:             * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
0760:             */
0761:            public void writeDialog() throws IOException {
0762:
0763:                if (isForwarded()) {
0764:                    return;
0765:                }
0766:                if (LOG.isDebugEnabled()) {
0767:                    LOG.debug(Messages.get().getBundle().key(
0768:                            Messages.LOG_START_WRITE_LIST_1, getListId()));
0769:                }
0770:                JspWriter out = getJsp().getJspContext().getOut();
0771:                out.print(defaultActionHtml());
0772:                if (LOG.isDebugEnabled()) {
0773:                    LOG.debug(Messages.get().getBundle().key(
0774:                            Messages.LOG_END_WRITE_LIST_1, getListId()));
0775:                }
0776:            }
0777:
0778:            /**
0779:             * Can be overwritten to add some code after the list.<p>
0780:             * 
0781:             * @return custom html code
0782:             */
0783:            protected String customHtmlEnd() {
0784:
0785:                return dialogContentEnd();
0786:            }
0787:
0788:            /**
0789:             * Can be overwritten to add some code before the list.<p>
0790:             * 
0791:             * @return custom html code
0792:             */
0793:            protected String customHtmlStart() {
0794:
0795:                return "";
0796:            }
0797:
0798:            /**
0799:             * Returns the html code for the default action content.<p>
0800:             * 
0801:             * @return html code
0802:             */
0803:            protected String defaultActionHtmlContent() {
0804:
0805:                StringBuffer result = new StringBuffer(2048);
0806:                result.append("<form name='");
0807:                result.append(getList().getId());
0808:                result.append("-form' action='");
0809:                result.append(getDialogRealUri());
0810:                result.append("' method='post' class='nomargin'");
0811:                if (getList().getMetadata().isSearchable()) {
0812:                    result.append(" onsubmit=\"listSearchAction('");
0813:                    result.append(getList().getId());
0814:                    result.append("', '");
0815:                    result.append(getList().getMetadata().getSearchAction()
0816:                            .getId());
0817:                    result.append("', '");
0818:                    result.append(getList().getMetadata().getSearchAction()
0819:                            .getConfirmationMessage().key(getLocale()));
0820:                    result.append("');\"");
0821:                }
0822:                result.append(">\n");
0823:                result.append(allParamsAsHidden());
0824:                result.append("\n");
0825:                getList().setWp(this );
0826:                result.append(getList().listHtml());
0827:                result.append("\n</form>\n");
0828:                return result.toString();
0829:            }
0830:
0831:            /**
0832:             * Generates the dialog ending html code.<p>
0833:             * 
0834:             * @return html code
0835:             */
0836:            protected String defaultActionHtmlEnd() {
0837:
0838:                StringBuffer result = new StringBuffer(2048);
0839:                result.append(dialogEnd());
0840:                result.append(bodyEnd());
0841:                result.append(htmlEnd());
0842:                return result.toString();
0843:            }
0844:
0845:            /**
0846:             * Generates the dialog starting html code.<p>
0847:             * 
0848:             * @return html code
0849:             */
0850:            protected String defaultActionHtmlStart() {
0851:
0852:                StringBuffer result = new StringBuffer(2048);
0853:                result.append(htmlStart(null));
0854:                result.append(getList().listJs());
0855:                result.append(bodyStart("dialog", null));
0856:                result.append(dialogStart());
0857:                result.append(dialogContentStart(getParamTitle()));
0858:                return result.toString();
0859:            }
0860:
0861:            /**
0862:             * Filter a list, given the action is set to <code>LIST_SEARCH</code> and
0863:             * the filter text is set in the <code>PARAM_SEARCH_FILTER</code> parameter.<p>
0864:             */
0865:            protected void executeSearch() {
0866:
0867:                getList().setSearchFilter(getParamSearchFilter());
0868:            }
0869:
0870:            /**
0871:             * Select a page, given the action is set to <code>LIST_SELECT_PAGE</code> and 
0872:             * the page to go to is set in the <code>PARAM_PAGE</code> parameter.<p>
0873:             */
0874:            protected void executeSelectPage() {
0875:
0876:                int page = Integer.valueOf(getParamPage()).intValue();
0877:                getList().setCurrentPage(page);
0878:            }
0879:
0880:            /**
0881:             * Sort the list, given the action is set to <code>LIST_SORT</code> and
0882:             * the sort column is set in the <code>PARAM_SORT_COL</code> parameter.<p>
0883:             */
0884:            protected void executeSort() {
0885:
0886:                getList().setSortedColumn(getParamSortCol());
0887:            }
0888:
0889:            /**
0890:             * Lazy initialization for detail data.<p>
0891:             * 
0892:             * Should fill the given detail column for every list item in <code>{@link CmsHtmlList#getContent()}</code>
0893:             * 
0894:             * Should not throw any kind of exception.<p>
0895:             * 
0896:             * @param detailId the id of the detail to initialize
0897:             */
0898:            protected abstract void fillDetails(String detailId);
0899:
0900:            /**
0901:             * Calls the <code>{@link #getListItems}</code> method and catches any exception.<p>
0902:             */
0903:            protected void fillList() {
0904:
0905:                try {
0906:                    getList().setContent(getListItems());
0907:                    // initialize detail columns
0908:                    Iterator itDetails = getList().getMetadata()
0909:                            .getItemDetailDefinitions().iterator();
0910:                    while (itDetails.hasNext()) {
0911:                        initializeDetail(((CmsListItemDetails) itDetails.next())
0912:                                .getId());
0913:                    }
0914:                } catch (Exception e) {
0915:                    throw new CmsRuntimeException(Messages.get().container(
0916:                            Messages.ERR_LIST_FILL_1,
0917:                            getList().getName().key(getLocale()), null), e);
0918:                }
0919:            }
0920:
0921:            /**
0922:             * Should generate a list with the list items to be displayed.<p>
0923:             * 
0924:             * @return a list of <code>{@link CmsListItem}</code>s
0925:             * 
0926:             * @throws CmsException if something goes wrong
0927:             */
0928:            protected abstract List getListItems() throws CmsException;
0929:
0930:            /**
0931:             * Returns the current list state.<p>
0932:             * 
0933:             * @return the current list state
0934:             */
0935:            protected CmsListState getListState() {
0936:
0937:                if (m_listState != null) {
0938:                    // in case of refreshList call
0939:                    return m_listState;
0940:                }
0941:                return getList().getState();
0942:            }
0943:
0944:            /**
0945:             * Should generate the metadata definition for the list, and return the 
0946:             * corresponding <code>{@link CmsListMetadata}</code> object.<p>
0947:             * 
0948:             * @param listDialogName the name of the class generating the list
0949:             * @param listId the id of the list
0950:             * 
0951:             * @return The metadata for the given list
0952:             */
0953:            protected synchronized CmsListMetadata getMetadata(
0954:                    String listDialogName, String listId) {
0955:
0956:                if ((m_metadatas.get(listDialogName) == null)
0957:                        || ((CmsListMetadata) m_metadatas.get(listDialogName))
0958:                                .isVolatile()) {
0959:                    if (LOG.isDebugEnabled()) {
0960:                        LOG.debug(Messages.get().getBundle()
0961:                                .key(Messages.LOG_START_METADATA_LIST_1,
0962:                                        getListId()));
0963:                    }
0964:                    CmsListMetadata metadata = new CmsListMetadata(listId);
0965:
0966:                    setColumns(metadata);
0967:                    // always check the search action
0968:                    setSearchAction(metadata, m_searchColId);
0969:                    setIndependentActions(metadata);
0970:                    metadata.addIndependentAction(new CmsListPrintIAction());
0971:                    setMultiActions(metadata);
0972:                    metadata.checkIds();
0973:                    m_metadatas.put(listDialogName, metadata);
0974:                    if (LOG.isDebugEnabled()) {
0975:                        LOG.debug(Messages.get().getBundle().key(
0976:                                Messages.LOG_END_METADATA_LIST_1, getListId()));
0977:                    }
0978:                }
0979:                return getMetadata(listDialogName);
0980:            }
0981:
0982:            /**
0983:             * Lazy details initialization.<p>
0984:             * 
0985:             * @param detailId the id of the detail column
0986:             */
0987:            protected void initializeDetail(String detailId) {
0988:
0989:                // if detail column visible
0990:                if (getList().getMetadata().getItemDetailDefinition(detailId)
0991:                        .isVisible()) {
0992:                    // if the list is not empty
0993:                    if (getList().getTotalSize() > 0) {
0994:                        // if the detail column has not been previously initialized
0995:                        if (((CmsListItem) getList().getAllContent().get(0))
0996:                                .get(detailId) == null) {
0997:                            if (LOG.isDebugEnabled()) {
0998:                                LOG.debug(Messages.get().getBundle().key(
0999:                                        Messages.LOG_START_DETAILS_LIST_2,
1000:                                        getListId(), detailId));
1001:                            }
1002:                            fillDetails(detailId);
1003:                            if (LOG.isDebugEnabled()) {
1004:                                LOG.debug(Messages.get().getBundle().key(
1005:                                        Messages.LOG_END_DETAILS_LIST_2,
1006:                                        getListId(), detailId));
1007:                            }
1008:                        }
1009:                    }
1010:                }
1011:            }
1012:
1013:            /**
1014:             * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
1015:             */
1016:            protected void initWorkplaceRequestValues(
1017:                    CmsWorkplaceSettings settings, HttpServletRequest request) {
1018:
1019:                super .initWorkplaceRequestValues(settings, request);
1020:                // set the action for the JSP switch 
1021:                if (LIST_SEARCH.equals(getParamAction())) {
1022:                    setAction(ACTION_LIST_SEARCH);
1023:                } else if (LIST_SORT.equals(getParamAction())) {
1024:                    setAction(ACTION_LIST_SORT);
1025:                } else if (LIST_SELECT_PAGE.equals(getParamAction())) {
1026:                    setAction(ACTION_LIST_SELECT_PAGE);
1027:                } else if (LIST_INDEPENDENT_ACTION.equals(getParamAction())) {
1028:                    setAction(ACTION_LIST_INDEPENDENT_ACTION);
1029:                } else if (LIST_SINGLE_ACTION.equals(getParamAction())) {
1030:                    setAction(ACTION_LIST_SINGLE_ACTION);
1031:                } else if (LIST_MULTI_ACTION.equals(getParamAction())) {
1032:                    setAction(ACTION_LIST_MULTI_ACTION);
1033:                }
1034:                setParamStyle(CmsToolDialog.STYLE_NEW);
1035:                // test the needed parameters
1036:                try {
1037:                    validateParamaters();
1038:                } catch (Exception e) {
1039:                    // redirect to parent if parameters not available
1040:                    setAction(ACTION_CANCEL);
1041:                    try {
1042:                        actionCloseDialog();
1043:                    } catch (JspException e1) {
1044:                        // noop
1045:                    }
1046:                    return;
1047:                }
1048:            }
1049:
1050:            /**
1051:             * Recover the last list instance that is read from the request attributes.<p>
1052:             * 
1053:             * This is required for keep the whole list in memory while you browse a page.<p>
1054:             * 
1055:             * @param listId the id of the expected list
1056:             */
1057:            protected synchronized void listRecovery(String listId) {
1058:
1059:                CmsHtmlList list = getListObject(this .getClass(), getSettings());
1060:                if ((list != null) && !list.getId().equals(listId)) {
1061:                    list = null;
1062:                }
1063:                setList(list);
1064:            }
1065:
1066:            /**
1067:             * Save the state of the list in the session.<p>
1068:             */
1069:            protected synchronized void listSave() {
1070:
1071:                setListObject(this .getClass(), getList());
1072:            }
1073:
1074:            /**
1075:             * Should create the columns and add them to the given list metadata object.<p>
1076:             * 
1077:             * This method will be just executed once, the first time the constructor is called.<p> 
1078:             * 
1079:             * @param metadata the list metadata
1080:             */
1081:            protected abstract void setColumns(CmsListMetadata metadata);
1082:
1083:            /**
1084:             * Should add the independent actions to the given list metadata object.<p>
1085:             * 
1086:             * This method will be just executed once, the first time the constructor is called.<p> 
1087:             * 
1088:             * @param metadata the list metadata
1089:             */
1090:            protected abstract void setIndependentActions(
1091:                    CmsListMetadata metadata);
1092:
1093:            /**
1094:             * Should add the multi actions to the given list metadata object.<p>
1095:             * 
1096:             * This method will be just executed once, the first time the constructor is called.<p> 
1097:             * 
1098:             * @param metadata the list metadata
1099:             */
1100:            protected abstract void setMultiActions(CmsListMetadata metadata);
1101:
1102:            /**
1103:             * Creates the default search action.<p>
1104:             * 
1105:             * Can be overridden for more sophisticated search.<p>
1106:             * 
1107:             * @param metadata the metadata of the list to do searchable
1108:             * @param columnId the if of the column to search into
1109:             */
1110:            protected void setSearchAction(CmsListMetadata metadata,
1111:                    String columnId) {
1112:
1113:                CmsListColumnDefinition col = metadata
1114:                        .getColumnDefinition(columnId);
1115:                if ((columnId != null) && (col != null)) {
1116:                    if (metadata.getSearchAction() == null) {
1117:                        // makes the list searchable
1118:                        CmsListSearchAction searchAction = new CmsListSearchAction(
1119:                                col);
1120:                        searchAction.useDefaultShowAllAction();
1121:                        metadata.setSearchAction(searchAction);
1122:                    }
1123:                }
1124:            }
1125:
1126:            /**
1127:             * A convenient method to throw a list unsupported
1128:             * action runtime exception.<p>
1129:             * 
1130:             * Should be triggered if your list implementation does not 
1131:             * support the <code>{@link #getParamListAction()}</code>
1132:             * action.<p>
1133:             * 
1134:             * @throws CmsRuntimeException always to signal that this operation is not supported
1135:             */
1136:            protected void throwListUnsupportedActionException()
1137:                    throws CmsRuntimeException {
1138:
1139:                throw new CmsRuntimeException(Messages.get().container(
1140:                        Messages.ERR_LIST_UNSUPPORTED_ACTION_2,
1141:                        getList().getName().key(getLocale()),
1142:                        getParamListAction()));
1143:            }
1144:
1145:            /**
1146:             * Should be overridden for parameter validation.<p>
1147:             * 
1148:             * @throws Exception if the parameters are not valid
1149:             */
1150:            protected void validateParamaters() throws Exception {
1151:
1152:                // valid by default
1153:            }
1154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.