KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > A_CmsListDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/A_CmsListDialog.java,v $
3  * Date : $Date: 2006/03/28 07:53:22 $
4  * Version: $Revision: 1.35 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.list;
33
34 import org.opencms.i18n.CmsMessageContainer;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsRuntimeException;
38 import org.opencms.util.CmsStringUtil;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWorkplaceSettings;
41
42 import java.io.IOException JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.Hashtable JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49
50 import javax.servlet.ServletException JavaDoc;
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52 import javax.servlet.jsp.JspException JavaDoc;
53 import javax.servlet.jsp.JspWriter JavaDoc;
54
55 /**
56  * Provides a dialog with a list widget.<p>
57  *
58  * @author Michael Moossen
59  *
60  * @version $Revision: 1.35 $
61  *
62  * @since 6.0.0
63  */

64 public abstract class A_CmsListDialog extends CmsDialog {
65
66     /** Value for the action: execute a list item independent action of the list. */
67     public static final int ACTION_LIST_INDEPENDENT_ACTION = 83;
68
69     /** Value for the action: execute an multi action of the list. */
70     public static final int ACTION_LIST_MULTI_ACTION = 85;
71
72     /** Value for the action: search the list. */
73     public static final int ACTION_LIST_SEARCH = 81;
74
75     /** Value for the action: go to a page. */
76     public static final int ACTION_LIST_SELECT_PAGE = 82;
77
78     /** Value for the action: execute a single action of the list. */
79     public static final int ACTION_LIST_SINGLE_ACTION = 84;
80
81     /** Value for the action: sort the list. */
82     public static final int ACTION_LIST_SORT = 80;
83
84     /** Standard list button location. */
85     public static final String JavaDoc ICON_ACTIVE = "list/active.png";
86
87     /** Standard list button location. */
88     public static final String JavaDoc ICON_ADD = "list/add.png";
89
90     /** Standard list button location. */
91     public static final String JavaDoc ICON_DELETE = "list/delete.png";
92
93     /** Standard list button location. */
94     public static final String JavaDoc ICON_DETAILS_HIDE = "list/details_hide.png";
95
96     /** Standard list button location. */
97     public static final String JavaDoc ICON_DETAILS_SHOW = "list/details_show.png";
98
99     /** Standard list button location. */
100     public static final String JavaDoc ICON_DISABLED = "list/disabled.png";
101
102     /** Standard list button location. */
103     public static final String JavaDoc ICON_INACTIVE = "list/inactive.png";
104
105     /** Standard list button location. */
106     public static final String JavaDoc ICON_MINUS = "list/minus.png";
107
108     /** Standard list button location. */
109     public static final String JavaDoc ICON_MULTI_ACTIVATE = "list/multi_activate.png";
110
111     /** Standard list button location. */
112     public static final String JavaDoc ICON_MULTI_ADD = "list/multi_add.png";
113
114     /** Standard list button location. */
115     public static final String JavaDoc ICON_MULTI_DEACTIVATE = "list/multi_deactivate.png";
116
117     /** Standard list button location. */
118     public static final String JavaDoc ICON_MULTI_DELETE = "list/multi_delete.png";
119
120     /** Standard list button location. */
121     public static final String JavaDoc ICON_MULTI_MINUS = "list/multi_minus.png";
122
123     /** Request parameter value for the list action: a list item independent action has been triggered. */
124     public static final String JavaDoc LIST_INDEPENDENT_ACTION = "listindependentaction";
125
126     /** Request parameter value for the list action: a multi action has been triggered. */
127     public static final String JavaDoc LIST_MULTI_ACTION = "listmultiaction";
128
129     /** Request parameter value for the list action: search/filter. */
130     public static final String JavaDoc LIST_SEARCH = "listsearch";
131
132     /** Request parameter value for the list action: select a page. */
133     public static final String JavaDoc LIST_SELECT_PAGE = "listselectpage";
134
135     /** Request parameter value for the list action: a single action has been triggered. */
136     public static final String JavaDoc LIST_SINGLE_ACTION = "listsingleaction";
137
138     /** Request parameter value for the list action: sort. */
139     public static final String JavaDoc LIST_SORT = "listsort";
140
141     /** Request parameter key for the requested page. */
142     public static final String JavaDoc PARAM_FORMNAME = "formname";
143
144     /** Request parameter key for the list action. */
145     public static final String JavaDoc PARAM_LIST_ACTION = "listaction";
146
147     /** Request parameter key for the requested page. */
148     public static final String JavaDoc PARAM_PAGE = "page";
149
150     /** Request parameter key for search the filter. */
151     public static final String JavaDoc PARAM_SEARCH_FILTER = "searchfilter";
152
153     /** Request parameter key for the selected item(s). */
154     public static final String JavaDoc PARAM_SEL_ITEMS = "selitems";
155
156     /** Request parameter key for the column to sort the list. */
157     public static final String JavaDoc PARAM_SORT_COL = "sortcol";
158
159     /** metadata map for all used list metadata objects. */
160     private static Map JavaDoc m_metadatas = new HashMap JavaDoc();
161
162     /** Activation decision Flag. */
163     private boolean m_active;
164
165     /** the internal list. */
166     private CmsHtmlList m_list;
167
168     /** The id of the list. */
169     private String JavaDoc m_listId;
170
171     /** The displayed page. */
172     private String JavaDoc m_paramFormName;
173
174     /** The list action. */
175     private String JavaDoc m_paramListAction;
176
177     /** The displayed page. */
178     private String JavaDoc m_paramPage;
179
180     /** The search filter text. */
181     private String JavaDoc m_paramSearchFilter;
182
183     /** The selected items, comma separated list. */
184     private String JavaDoc m_paramSelItems;
185
186     /** The column to sort the list. */
187     private String JavaDoc m_paramSortCol;
188
189     /** The column to search the list. */
190     private String JavaDoc m_searchColId;
191
192     /**
193      * Public constructor.<p>
194      * @param jsp an initialized JSP action element
195      * @param listId the id of the displayed list
196      * @param listName the name of the list
197      * @param sortedColId the a priory sorted column
198      * @param sortOrder the order of the sorted column
199      * @param searchableColId the column to search into
200      */

201     protected A_CmsListDialog(
202         CmsJspActionElement jsp,
203         String JavaDoc listId,
204         CmsMessageContainer listName,
205         String JavaDoc sortedColId,
206         CmsListOrderEnum sortOrder,
207         String JavaDoc searchableColId) {
208
209         super(jsp);
210         // set list id
211
m_listId = listId;
212         // set active flag for 2 lists dialog
213
m_active = (getListId() + "-form").equals(getParamFormName());
214         setParamFormName(getListId() + "-form");
215         // abort if already forwarded
216
if (isForwarded()) {
217             return;
218         }
219         m_searchColId = searchableColId;
220         // try to read the list from the session
221
listRecovery(listId);
222         // initialization
223
if (getList() == null) {
224             // create the list
225
setList(new CmsHtmlList(listId, listName, getMetadata(this.getClass().getName(), listId)));
226             // set the number of items per page from the user settings
227
getList().setMaxItemsPerPage(getSettings().getUserSettings().getExplorerFileEntries());
228             // sort the list
229
if (sortedColId != null && getList().getMetadata().getColumnDefinition(sortedColId) != null) {
230                 getList().setSortedColumn(sortedColId, getLocale());
231                 if (sortOrder != null && sortOrder == CmsListOrderEnum.ORDER_DESCENDING) {
232                     getList().setSortedColumn(sortedColId, getLocale());
233                 }
234             }
235             // save the current state of the list
236
listSave();
237         }
238     }
239
240     /**
241      * Returns the list object for the given list dialog, or <code>null</code>
242      * if no list object has been set.<p>
243      *
244      * @param listDialog the list dialog class
245      * @param settings the wp settings for accessing the session
246      *
247      * @return the list object for this list dialog, or <code>null</code>
248      */

249     public static CmsHtmlList getListObject(Class JavaDoc listDialog, CmsWorkplaceSettings settings) {
250
251         return (CmsHtmlList)getListObjectMap(settings).get(listDialog.getName());
252     }
253
254     /**
255      * Returns the (internal use only) map of list objects.<p>
256      *
257      * @param settings the wp settings for accessing the session
258      *
259      * @return the (internal use only) map of list objects
260      */

261     private static Map JavaDoc getListObjectMap(CmsWorkplaceSettings settings) {
262
263         Map JavaDoc objects = (Map JavaDoc)settings.getListObject();
264         if (objects == null) {
265             // using hashtable as most efficient version of a synchronized map
266
objects = new Hashtable JavaDoc();
267             settings.setListObject(objects);
268         }
269         return objects;
270     }
271
272     /**
273      * Performs the dialog actions depending on the initialized action.<p>
274      *
275      * @throws JspException if dialog actions fail
276      * @throws IOException in case of errros forwarding to the required result page
277      * @throws ServletException in case of errros forwarding to the required result page
278      */

279     public void actionDialog() throws JspException JavaDoc, ServletException JavaDoc, IOException JavaDoc {
280
281         if (getAction() == ACTION_CANCEL) {
282             // ACTION: cancel button pressed
283
actionCloseDialog();
284             return;
285         }
286         if (isForwarded()) {
287             return;
288         }
289         // TODO: check the need for this, improve caching
290
refreshList();
291         switch (getAction()) {
292             //////////////////// ACTION: default actions
293
case ACTION_LIST_SEARCH:
294             case ACTION_LIST_SORT:
295             case ACTION_LIST_SELECT_PAGE:
296                 executeDefaultActions();
297                 break;
298
299             //////////////////// ACTION: execute single list action
300
case ACTION_LIST_SINGLE_ACTION:
301                 if (getSelectedItem() != null) {
302                     executeListSingleActions();
303                 }
304                 break;
305
306             //////////////////// ACTION: execute multiple list actions
307
case ACTION_LIST_MULTI_ACTION:
308                 executeListMultiActions();
309                 break;
310
311             //////////////////// ACTION: execute independent list actions
312
case ACTION_LIST_INDEPENDENT_ACTION:
313                 executeListIndepActions();
314                 break;
315
316             case ACTION_DEFAULT:
317             default:
318                 // ACTION: show dialog (default)
319
setParamAction(DIALOG_INITIAL);
320         }
321     }
322
323     /**
324      * Performs the dialog actions depending on the initialized action and displays the dialog form.<p>
325      *
326      * @throws JspException if dialog actions fail
327      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
328      * @throws ServletException in case of errros forwarding to the required result page
329      */

330     public void displayDialog() throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
331
332         displayDialog(false);
333     }
334
335     /**
336      * Performs the dialog actions depending on the initialized action and displays the dialog form if needed.<p>
337      *
338      * @param writeLater if <code>true</code> no output is written,
339      * you have to call manually the <code>{@link #defaultActionHtml()}</code> method.
340      *
341      * @throws JspException if dialog actions fail
342      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
343      * @throws ServletException in case of errros forwarding to the required result page
344      */

345     public void displayDialog(boolean writeLater) throws JspException JavaDoc, IOException JavaDoc, ServletException JavaDoc {
346
347         actionDialog();
348         if (writeLater) {
349             return;
350         }
351         writeDialog();
352     }
353
354     /**
355      * This method execute the default actions for searching, sorting and paging.<p>
356      */

357     public void executeDefaultActions() {
358
359         switch (getAction()) {
360
361             case ACTION_LIST_SEARCH:
362                 executeSearch();
363                 break;
364             case ACTION_LIST_SORT:
365                 executeSort();
366                 break;
367             case ACTION_LIST_SELECT_PAGE:
368                 executeSelectPage();
369                 break;
370             default:
371         //noop
372
}
373         listSave();
374     }
375
376     /**
377      * This method should handle the default list independent actions,
378      * by comparing <code>{@link #getParamListAction()}</code> with the id
379      * of the action to execute.<p>
380      *
381      * if you want to handle additional independent actions, override this method,
382      * handling your actions and FINALLY calling <code>super.executeListIndepActions();</code>.<p>
383      */

384     public void executeListIndepActions() {
385
386         if (getList().getMetadata().getItemDetailDefinition(getParamListAction()) != null) {
387             // toogle item details
388
getList().getMetadata().toogleDetailState(getParamListAction());
389             // lazzy initialization
390
initializeDetail(getParamListAction());
391         }
392         listSave();
393     }
394
395     /**
396      * This method should handle every defined list multi action,
397      * by comparing <code>{@link #getParamListAction()}</code> with the id
398      * of the action to execute.<p>
399      *
400      * @throws IOException in case of errors when including a required sub-element
401      * @throws ServletException in case of errors when including a required sub-element
402      * @throws CmsRuntimeException to signal that an action is not supported
403      */

404     public abstract void executeListMultiActions() throws IOException JavaDoc, ServletException JavaDoc, CmsRuntimeException;
405
406     /**
407      * This method should handle every defined list single action,
408      * by comparing <code>{@link #getParamListAction()}</code> with the id
409      * of the action to execute.<p>
410      *
411      * @throws IOException in case of errors when including a required sub-element
412      * @throws ServletException in case of errors when including a required sub-element
413      * @throws CmsRuntimeException to signal that an action is not supported
414      */

415     public abstract void executeListSingleActions() throws IOException JavaDoc, ServletException JavaDoc, CmsRuntimeException;
416
417     /**
418      * Returns the list.<p>
419      *
420      * @return the list
421      */

422     public CmsHtmlList getList() {
423
424         if (m_list != null && m_list.getMetadata() == null) {
425             m_list.setMetadata(getMetadata(getClass().getName(), m_list.getId()));
426         }
427         return m_list;
428     }
429
430     /**
431      * Returns the Id of the list.<p>
432      *
433      * @return the list Id
434      */

435     public final String JavaDoc getListId() {
436
437         return m_listId;
438     }
439
440     /**
441      * Returns the form name.<p>
442      *
443      * @return the form name
444      */

445     public String JavaDoc getParamFormName() {
446
447         return m_paramFormName;
448     }
449
450     /**
451      * Returns the List Action.<p>
452      *
453      * @return the List Action
454      */

455     public String JavaDoc getParamListAction() {
456
457         return m_paramListAction;
458     }
459
460     /**
461      * Returns the current Page.<p>
462      *
463      * @return the current Page
464      */

465     public String JavaDoc getParamPage() {
466
467         return m_paramPage;
468     }
469
470     /**
471      * Returns the Search Filter.<p>
472      *
473      * @return the Search Filter
474      */

475     public String JavaDoc getParamSearchFilter() {
476
477         return m_paramSearchFilter;
478     }
479
480     /**
481      * Returns the Selected Items.<p>
482      *
483      * @return the Selelected Items
484      */

485     public String JavaDoc getParamSelItems() {
486
487         return m_paramSelItems;
488     }
489
490     /**
491      * Returns the sorted Column.<p>
492      *
493      * @return the sorted Column
494      */

495     public String JavaDoc getParamSortCol() {
496
497         return m_paramSortCol;
498     }
499
500     /**
501      * Returns the current selected item.<p>
502      *
503      * @return the current selected item
504      */

505     public CmsListItem getSelectedItem() {
506
507         try {
508             return getList().getItem(
509                 CmsStringUtil.splitAsArray(getParamSelItems(), CmsHtmlList.ITEM_SEPARATOR)[0].trim());
510         } catch (Exception JavaDoc e) {
511             return null;
512         }
513     }
514
515     /**
516      * Returns a list of current selected items.<p>
517      *
518      * @return a list of current selected items
519      */

520     public List JavaDoc getSelectedItems() {
521
522         Iterator JavaDoc it = CmsStringUtil.splitAsList(getParamSelItems(), CmsHtmlList.ITEM_SEPARATOR, true).iterator();
523         List JavaDoc items = new ArrayList JavaDoc();
524         while (it.hasNext()) {
525             String JavaDoc id = (String JavaDoc)it.next();
526             items.add(getList().getItem(id));
527         }
528         return items;
529     }
530
531     /**
532      * Returns the activation flag.<p>
533      *
534      * Useful for dialogs with several lists.<p>
535      *
536      * Is <code></code> if the original <code>formname</code> parameter
537      * is equals to <code>${listId}-form</code>.<p>
538      *
539      * @return the activation flag
540      */

541     public boolean isActive() {
542
543         return m_active;
544     }
545
546     /**
547      * This method re-read the rows of the list, the user should call this method after executing an action
548      * that add or remove rows to the list.
549      */

550     public synchronized void refreshList() {
551
552         if (getList() == null) {
553             return;
554         }
555         CmsListState ls = getList().getState();
556         getList().clear(getLocale());
557         fillList();
558         getList().setState(ls, getLocale());
559         listSave();
560     }
561
562     /**
563      * Removes the list from the workplace settings.<p>
564      *
565      * Next time the list is displayed the list will be reloaded.<p>
566      */

567     public void removeList() {
568
569         setList(null);
570         listSave();
571     }
572
573     /**
574      * Sets the list.<p>
575      *
576      * @param list the list to set
577      */

578     public void setList(CmsHtmlList list) {
579
580         m_list = list;
581     }
582
583     /**
584      * Stores the given object as "list object" for the given list dialog in the current users session.<p>
585      *
586      * @param listDialog the list dialog class
587      * @param listObject the list to store
588      */

589     public void setListObject(Class JavaDoc listDialog, CmsHtmlList listObject) {
590
591         if (listObject == null) {
592             // null object: remove the entry from the map
593
getListObjectMap(getSettings()).remove(listDialog.getName());
594         } else {
595             if (listObject.getMetadata() != null && listObject.getMetadata().isVolatile()) {
596                 listObject.setMetadata(null);
597             }
598             getListObjectMap(getSettings()).put(listDialog.getName(), listObject);
599         }
600     }
601
602     /**
603      * Sets the form name.<p>
604      *
605      * @param formName the form name to set
606      */

607     public void setParamFormName(String JavaDoc formName) {
608
609         m_paramFormName = formName;
610     }
611
612     /**
613      * Sets the List Action.<p>
614      *
615      * @param listAction the list Action to set
616      */

617     public void setParamListAction(String JavaDoc listAction) {
618
619         m_paramListAction = listAction;
620     }
621
622     /**
623      * Sets the current Page.<p>
624      *
625      * @param page the current Page to set
626      */

627     public void setParamPage(String JavaDoc page) {
628
629         m_paramPage = page;
630     }
631
632     /**
633      * Sets the Search Filter.<p>
634      *
635      * @param searchFilter the Search Filter to set
636      */

637     public void setParamSearchFilter(String JavaDoc searchFilter) {
638
639         m_paramSearchFilter = searchFilter;
640     }
641
642     /**
643      * Sets the Selelected Items.<p>
644      *
645      * @param paramSelItems the Selelected Items to set
646      */

647     public void setParamSelItems(String JavaDoc paramSelItems) {
648
649         m_paramSelItems = paramSelItems;
650     }
651
652     /**
653      * Sets the sorted Column.<p>
654      *
655      * @param sortCol the sorted Column to set
656      */

657     public void setParamSortCol(String JavaDoc sortCol) {
658
659         m_paramSortCol = sortCol;
660     }
661
662     /**
663      * Writes the dialog html code, only if the <code>{@link #ACTION_DEFAULT}</code> is set.<p>
664      *
665      * @throws IOException if writing to the JSP out fails, or in case of errros forwarding to the required result page
666      */

667     public void writeDialog() throws IOException JavaDoc {
668
669         if (isForwarded()) {
670             return;
671         }
672         JspWriter JavaDoc out = getJsp().getJspContext().getOut();
673         out.print(defaultActionHtml());
674     }
675
676     /**
677      * Can be overwritten to add some code after the list.<p>
678      *
679      * @return custom html code
680      */

681     protected String JavaDoc customHtmlEnd() {
682
683         return dialogContentEnd();
684     }
685
686     /**
687      * Can be overwritten to add some code before the list.<p>
688      *
689      * @return custom html code
690      */

691     protected String JavaDoc customHtmlStart() {
692
693         return "";
694     }
695
696     /**
697      * Generates the dialog starting html code.<p>
698      *
699      * @return html code
700      */

701     protected String JavaDoc defaultActionHtml() {
702
703         if (getList() != null && getList().getAllContent().isEmpty()) {
704             refreshList();
705         }
706         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
707         result.append(defaultActionHtmlStart());
708         result.append(customHtmlStart());
709         result.append(defaultActionHtmlContent());
710         result.append(customHtmlEnd());
711         result.append(defaultActionHtmlEnd());
712         return result.toString();
713     }
714
715     /**
716      * Returns the html code for the default action content.<p>
717      *
718      * @return html code
719      */

720     protected String JavaDoc defaultActionHtmlContent() {
721
722         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
723         result.append("<form name='");
724         result.append(getList().getId());
725         result.append("-form' action='");
726         result.append(getDialogRealUri());
727         result.append("' method='post' class='nomargin'");
728         if (getList().getMetadata().isSearchable()) {
729             result.append(" onsubmit=\"listSearchAction('");
730             result.append(getList().getId());
731             result.append("', '");
732             result.append(getList().getMetadata().getSearchAction().getId());
733             result.append("', '");
734             result.append(getList().getMetadata().getSearchAction().getConfirmationMessage().key(getLocale()));
735             result.append("');\"");
736         }
737         result.append(">\n");
738         result.append(allParamsAsHidden());
739         result.append("\n");
740         result.append(getList().listHtml(this));
741         result.append("\n</form>\n");
742         return result.toString();
743     }
744
745     /**
746      * Generates the dialog ending html code.<p>
747      *
748      * @return html code
749      */

750     protected String JavaDoc defaultActionHtmlEnd() {
751
752         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
753         result.append(dialogEnd());
754         result.append(bodyEnd());
755         result.append(htmlEnd());
756         return result.toString();
757     }
758
759     /**
760      * Generates the dialog starting html code.<p>
761      *
762      * @return html code
763      */

764     protected String JavaDoc defaultActionHtmlStart() {
765
766         StringBuffer JavaDoc result = new StringBuffer JavaDoc(2048);
767         result.append(htmlStart(null));
768         result.append(getList().listJs(getLocale()));
769         result.append(bodyStart("dialog", null));
770         result.append(dialogStart());
771         result.append(dialogContentStart(getParamTitle()));
772         return result.toString();
773     }
774
775     /**
776      * Filter a list, given the action is set to <code>LIST_SEARCH</code> and
777      * the filter text is set in the <code>PARAM_SEARCH_FILTER</code> parameter.<p>
778      */

779     protected void executeSearch() {
780
781         getList().setSearchFilter(getParamSearchFilter(), getLocale());
782     }
783
784     /**
785      * Select a page, given the action is set to <code>LIST_SELECT_PAGE</code> and
786      * the page to go to is set in the <code>PARAM_PAGE</code> parameter.<p>
787      */

788     protected void executeSelectPage() {
789
790         int page = Integer.valueOf(getParamPage()).intValue();
791         getList().setCurrentPage(page);
792     }
793
794     /**
795      * Sort the list, given the action is set to <code>LIST_SORT</code> and
796      * the sort column is set in the <code>PARAM_SORT_COL</code> parameter.<p>
797      */

798     protected void executeSort() {
799
800         getList().setSortedColumn(getParamSortCol(), getLocale());
801     }
802
803     /**
804      * Lazy initialization for detail data.<p>
805      *
806      * Should fill the given detail column for every list item in <code>{@link CmsHtmlList#getAllContent()}</code>
807      *
808      * Should not throw any kind of exception.<p>
809      *
810      * @param detailId the id of the detail to initialize
811      */

812     protected abstract void fillDetails(String JavaDoc detailId);
813
814     /**
815      * Calls the <code>{@link #getListItems}</code> method and catches any exception.<p>
816      */

817     protected void fillList() {
818
819         try {
820             getList().addAllItems(getListItems());
821             // initialize detail columns
822
Iterator JavaDoc itDetails = getList().getMetadata().getItemDetailDefinitions().iterator();
823             while (itDetails.hasNext()) {
824                 initializeDetail(((CmsListItemDetails)itDetails.next()).getId());
825             }
826         } catch (Exception JavaDoc e) {
827             throw new CmsRuntimeException(Messages.get().container(
828                 Messages.ERR_LIST_FILL_1,
829                 getList().getName().key(getLocale()),
830                 null), e);
831         }
832     }
833
834     /**
835      * Should generate a list with the list items to be displayed.<p>
836      *
837      * @return a list of <code>{@link CmsListItem}</code>s
838      *
839      * @throws CmsException if something goes wrong
840      */

841     protected abstract List JavaDoc getListItems() throws CmsException;
842
843     /**
844      * Should generate the metadata definition for the list, and return the
845      * corresponding <code>{@link CmsListMetadata}</code> object.<p>
846      *
847      * @param listDialogName the name of the class generating the list
848      * @param listId the id of the list
849      *
850      * @return The metadata for the given list
851      */

852     protected synchronized CmsListMetadata getMetadata(String JavaDoc listDialogName, String JavaDoc listId) {
853
854         if (m_metadatas.get(listDialogName) == null || ((CmsListMetadata)m_metadatas.get(listDialogName)).isVolatile()) {
855             CmsListMetadata metadata = new CmsListMetadata(listId);
856
857             setColumns(metadata);
858             // always check the search action
859
setSearchAction(metadata, m_searchColId);
860             setIndependentActions(metadata);
861             metadata.addIndependentAction(new CmsListPrintIAction());
862             setMultiActions(metadata);
863             metadata.checkIds();
864             m_metadatas.put(listDialogName, metadata);
865         }
866         return (CmsListMetadata)m_metadatas.get(listDialogName);
867     }
868
869     /**
870      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
871      */

872     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
873
874         super.initWorkplaceRequestValues(settings, request);
875         // set the action for the JSP switch
876
if (LIST_SEARCH.equals(getParamAction())) {
877             setAction(ACTION_LIST_SEARCH);
878         } else if (LIST_SORT.equals(getParamAction())) {
879             setAction(ACTION_LIST_SORT);
880         } else if (LIST_SELECT_PAGE.equals(getParamAction())) {
881             setAction(ACTION_LIST_SELECT_PAGE);
882         } else if (LIST_INDEPENDENT_ACTION.equals(getParamAction())) {
883             setAction(ACTION_LIST_INDEPENDENT_ACTION);
884         } else if (LIST_SINGLE_ACTION.equals(getParamAction())) {
885             setAction(ACTION_LIST_SINGLE_ACTION);
886         } else if (LIST_MULTI_ACTION.equals(getParamAction())) {
887             setAction(ACTION_LIST_MULTI_ACTION);
888         }
889         setParamStyle("new");
890         // test the needed parameters
891
try {
892             validateParamaters();
893         } catch (Exception JavaDoc e) {
894             // redirect to parent if parameters not available
895
setAction(ACTION_CANCEL);
896             try {
897                 actionCloseDialog();
898             } catch (JspException JavaDoc e1) {
899                 // noop
900
}
901             return;
902         }
903     }
904
905     /**
906      * Recover the last list instance that is read from the request attributes.<p>
907      *
908      * This is required for keep the whole list in memory while you browse a page.<p>
909      *
910      * @param listId the id of the expected list
911      */

912     protected synchronized void listRecovery(String JavaDoc listId) {
913
914         CmsHtmlList list = getListObject(this.getClass(), getSettings());
915         if (list != null && !list.getId().equals(listId)) {
916             list = null;
917         }
918         setList(list);
919     }
920
921     /**
922      * Save the state of the list in the session.<p>
923      */

924     protected synchronized void listSave() {
925
926         setListObject(this.getClass(), getList());
927     }
928
929     /**
930      * Should create the columns and add them to the given list metadata object.<p>
931      *
932      * This method will be just executed once, the first time the constructor is called.<p>
933      *
934      * @param metadata the list metadata
935      */

936     protected abstract void setColumns(CmsListMetadata metadata);
937
938     /**
939      * Should add the independent actions to the given list metadata object.<p>
940      *
941      * This method will be just executed once, the first time the constructor is called.<p>
942      *
943      * @param metadata the list metadata
944      */

945     protected abstract void setIndependentActions(CmsListMetadata metadata);
946
947     /**
948      * Should add the multi actions to the given list metadata object.<p>
949      *
950      * This method will be just executed once, the first time the constructor is called.<p>
951      *
952      * @param metadata the list metadata
953      */

954     protected abstract void setMultiActions(CmsListMetadata metadata);
955
956     /**
957      * Creates the default search action.<p>
958      *
959      * Can be overriden for more sofisticated search.<p>
960      *
961      * @param metadata the metadata of the list to do searchable
962      * @param columnId the if of the column to search into
963      */

964     protected void setSearchAction(CmsListMetadata metadata, String JavaDoc columnId) {
965
966         CmsListColumnDefinition col = metadata.getColumnDefinition(columnId);
967         if (columnId != null && col != null) {
968             if (metadata.getSearchAction() == null) {
969                 // makes the list searchable
970
CmsListSearchAction searchAction = new CmsListSearchAction(col);
971                 searchAction.useDefaultShowAllAction();
972                 metadata.setSearchAction(searchAction);
973             }
974         }
975     }
976
977     /**
978      * A convenient method to throw a list unsupported
979      * action runtime exception.<p>
980      *
981      * Should be triggered if your list implementation does not
982      * support the <code>{@link #getParamListAction()}</code>
983      * action.<p>
984      *
985      * @throws CmsRuntimeException always to signal that this operation is not supported
986      */

987     protected void throwListUnsupportedActionException() throws CmsRuntimeException {
988
989         throw new CmsRuntimeException(Messages.get().container(
990             Messages.ERR_LIST_UNSUPPORTED_ACTION_2,
991             getList().getName().key(getLocale()),
992             getParamListAction()));
993     }
994
995     /**
996      * Should be overriden for parameter validation.<p>
997      *
998      * @throws Exception if the parameters are not valid
999      */

1000    protected void validateParamaters() throws Exception JavaDoc {
1001
1002        // valid by default
1003
}
1004
1005    /**
1006     * Lazzy details initialization.<p>
1007     *
1008     * @param detailId the id of the detail column
1009     */

1010    private void initializeDetail(String JavaDoc detailId) {
1011
1012        // if detail column visible
1013
if (getList().getMetadata().getItemDetailDefinition(detailId).isVisible()) {
1014            // if the list is not empty
1015
if (!getList().getAllContent().isEmpty()) {
1016                // if the detail column has not been previously initialized
1017
if (((CmsListItem)getList().getAllContent().get(0)).get(detailId) == null) {
1018                    fillDetails(detailId);
1019                }
1020            }
1021        }
1022    }
1023}
Popular Tags