001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListMetadata.java,v $
003: * Date : $Date: 2008-02-27 12:05:28 $
004: * Version: $Revision: 1.26 $
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.list;
033:
034: import org.opencms.main.CmsIllegalStateException;
035: import org.opencms.util.CmsStringUtil;
036: import org.opencms.workplace.tools.CmsIdentifiableObjectContainer;
037:
038: import java.util.Iterator;
039: import java.util.List;
040: import java.util.Set;
041: import java.util.TreeSet;
042:
043: /**
044: * This is class contains all the information for defining a whole html list.<p>
045: *
046: * @author Michael Moossen
047: *
048: * @version $Revision: 1.26 $
049: *
050: * @since 6.0.0
051: */
052: public class CmsListMetadata {
053:
054: /** the html id for the input element of the search bar. */
055: public static final String SEARCH_BAR_INPUT_ID = "listSearchFilter";
056:
057: /** Container for column definitions. */
058: private CmsIdentifiableObjectContainer m_columns = new CmsIdentifiableObjectContainer(
059: true, false);
060:
061: /** Container for of independent actions. */
062: private CmsIdentifiableObjectContainer m_indepActions = new CmsIdentifiableObjectContainer(
063: true, false);
064:
065: /** Container for item detail definitions. */
066: private CmsIdentifiableObjectContainer m_itemDetails = new CmsIdentifiableObjectContainer(
067: true, false);
068:
069: /** The id of the list. */
070: private String m_listId;
071:
072: /** Container for multi actions. */
073: private CmsIdentifiableObjectContainer m_multiActions = new CmsIdentifiableObjectContainer(
074: true, false);
075:
076: /** Search action. */
077: private CmsListSearchAction m_searchAction;
078:
079: /** if the data is self managed (sorted and filtered by {@link A_CmsListDialog#getListItems()} method). */
080: private boolean m_selfManaged = false;
081:
082: /** if this metadata object should not be cached.<p>. */
083: private boolean m_volatile = false;
084:
085: /** The related workplace dialog object. */
086: private transient A_CmsListDialog m_wp;
087:
088: /**
089: * Default Constructor.<p>
090: *
091: * @param listId the id of the list
092: */
093: public CmsListMetadata(String listId) {
094:
095: m_listId = listId;
096: }
097:
098: /**
099: * Adds a new column definition at the end.<p>
100: *
101: * By default a column is printable if it is the first column in the list,
102: * or if it is sorteable.<p>
103: *
104: * If you want to override this behaviour, use the
105: * {@link CmsListColumnDefinition#setPrintable(boolean)}
106: * method after calling this one.
107: *
108: * @param listColumn the column definition
109: *
110: * @see CmsIdentifiableObjectContainer
111: */
112: public void addColumn(CmsListColumnDefinition listColumn) {
113:
114: addColumn(listColumn, m_columns.elementList().size());
115: }
116:
117: /**
118: * Adds a new column definition at the given position.<p>
119: *
120: * By default a column is printable if it is the first column in the list,
121: * or if it is sorteable.<p>
122: *
123: * If you want to override this behaviour, use the
124: * {@link CmsListColumnDefinition#setPrintable(boolean)}
125: * method after calling this one.
126: *
127: * @param listColumn the column definition
128: * @param position the position
129: *
130: * @see CmsIdentifiableObjectContainer
131: */
132: public void addColumn(CmsListColumnDefinition listColumn,
133: int position) {
134:
135: setListIdForColumn(listColumn);
136: if (m_columns.elementList().isEmpty()) {
137: listColumn.setPrintable(true);
138: } else {
139: listColumn.setPrintable(listColumn.isSorteable());
140: }
141: if ((listColumn.getName() == null) && listColumn.isPrintable()) {
142: listColumn.setPrintable(false);
143: }
144: m_columns.addIdentifiableObject(listColumn.getId(), listColumn,
145: position);
146: }
147:
148: /**
149: * Adds a list item independent action.<p>
150: *
151: * @param action the action
152: */
153: public void addIndependentAction(I_CmsListAction action) {
154:
155: action.setListId(getListId());
156: m_indepActions.addIdentifiableObject(action.getId(), action);
157: }
158:
159: /**
160: * Adds a new item detail definition at the end.<p>
161: *
162: * @param itemDetail the item detail definition
163: *
164: * @see CmsIdentifiableObjectContainer
165: */
166: public void addItemDetails(CmsListItemDetails itemDetail) {
167:
168: itemDetail.setListId(getListId());
169: m_itemDetails.addIdentifiableObject(itemDetail.getId(),
170: itemDetail);
171: }
172:
173: /**
174: * Adds a new item detail definition at the given position.<p>
175: *
176: * @param itemDetail the item detail definition
177: * @param position the position
178: *
179: * @see CmsIdentifiableObjectContainer
180: */
181: public void addItemDetails(CmsListItemDetails itemDetail,
182: int position) {
183:
184: itemDetail.setListId(getListId());
185: m_itemDetails.addIdentifiableObject(itemDetail.getId(),
186: itemDetail, position);
187: }
188:
189: /**
190: * Adds an action applicable to more than one list item at once.<p>
191: *
192: * It will be executed with a list of <code>{@link CmsListItem}</code>s.<p>
193: *
194: * @param multiAction the action
195: */
196: public void addMultiAction(CmsListMultiAction multiAction) {
197:
198: multiAction.setListId(getListId());
199: m_multiActions.addIdentifiableObject(multiAction.getId(),
200: multiAction);
201: }
202:
203: /**
204: * Generates the csv output for an empty table.<p>
205: *
206: * @return csv output
207: */
208: public String csvEmptyList() {
209:
210: StringBuffer html = new StringBuffer(512);
211: html.append("\n");
212: return html.toString();
213: }
214:
215: /**
216: * Returns the csv output for the header of the list.<p>
217: *
218: * @return csv output
219: */
220: public String csvHeader() {
221:
222: StringBuffer csv = new StringBuffer(1024);
223: Iterator itCols = m_columns.elementList().iterator();
224: while (itCols.hasNext()) {
225: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
226: .next();
227: if (!col.isVisible()) {
228: continue;
229: }
230: csv.append(col.csvHeader());
231: csv.append("\t");
232: }
233: csv.append("\n\n");
234: return csv.toString();
235: }
236:
237: /**
238: * Returns the csv output for a list item.<p>
239: *
240: * @param item the list item to render
241: *
242: * @return csv output
243: */
244: public String csvItem(CmsListItem item) {
245:
246: StringBuffer csv = new StringBuffer(1024);
247: Iterator itCols = m_columns.elementList().iterator();
248: while (itCols.hasNext()) {
249: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
250: .next();
251: if (!col.isVisible()) {
252: continue;
253: }
254: csv.append(col.csvCell(item));
255: csv.append("\t");
256: }
257: csv.append("\n");
258: return csv.toString();
259: }
260:
261: /**
262: * Returns a column definition object for a given column id.<p>
263: *
264: * @param columnId the column id
265: *
266: * @return the column definition, or <code>null</code> if not present
267: */
268: public CmsListColumnDefinition getColumnDefinition(String columnId) {
269:
270: return (CmsListColumnDefinition) m_columns.getObject(columnId);
271: }
272:
273: /**
274: * Returns all columns definitions.<p>
275: *
276: * @return a list of <code>{@link CmsListColumnDefinition}</code>s.
277: */
278: public List getColumnDefinitions() {
279:
280: return m_columns.elementList();
281: }
282:
283: /**
284: * Returns an independent action object for a given id.<p>
285: *
286: * @param actionId the id
287: *
288: * @return the independent action, or <code>null</code> if not present
289: */
290: public I_CmsListAction getIndependentAction(String actionId) {
291:
292: return (I_CmsListAction) m_indepActions.getObject(actionId);
293: }
294:
295: /**
296: * Returns the list of independent actions.<p>
297: *
298: * @return a list of <code>{@link I_CmsListAction}</code>s
299: */
300: public List getIndependentActions() {
301:
302: return m_indepActions.elementList();
303: }
304:
305: /**
306: * Returns the item details definition object for a given id.<p>
307: *
308: * @param itemDetailId the id
309: *
310: * @return the item details definition, or <code>null</code> if not present
311: */
312: public CmsListItemDetails getItemDetailDefinition(
313: String itemDetailId) {
314:
315: return (CmsListItemDetails) m_itemDetails
316: .getObject(itemDetailId);
317: }
318:
319: /**
320: * Returns all detail definitions.<p>
321: *
322: * @return a list of <code>{@link CmsListItemDetails}</code>.
323: */
324: public List getItemDetailDefinitions() {
325:
326: return m_itemDetails.elementList();
327: }
328:
329: /**
330: * Returns the id of the list.<p>
331: *
332: * @return the id of list
333: */
334: public String getListId() {
335:
336: return m_listId;
337: }
338:
339: /**
340: * Returns a multi action object for a given id.<p>
341: *
342: * @param actionId the id
343: *
344: * @return the multi action, or <code>null</code> if not present
345: */
346: public CmsListMultiAction getMultiAction(String actionId) {
347:
348: return (CmsListMultiAction) m_multiActions.getObject(actionId);
349: }
350:
351: /**
352: * Returns the list of multi actions.<p>
353: *
354: * @return a list of <code>{@link CmsListMultiAction}</code>s
355: */
356: public List getMultiActions() {
357:
358: return m_multiActions.elementList();
359: }
360:
361: /**
362: * Returns the search action.<p>
363: *
364: * @return the search action
365: */
366: public CmsListSearchAction getSearchAction() {
367:
368: return m_searchAction;
369: }
370:
371: /**
372: * Returns the total number of displayed columns.<p>
373: *
374: * @return the total number of displayed columns
375: */
376: public int getWidth() {
377:
378: return m_columns.elementList().size()
379: + (hasCheckMultiActions() ? 1 : 0);
380: }
381:
382: /**
383: * Returns the related workplace dialog.<p>
384: *
385: * @return the related workplace dialog
386: */
387: public A_CmsListDialog getWp() {
388:
389: return m_wp;
390: }
391:
392: /**
393: * Returns <code>true</code> if the list definition contains an action.<p>
394: *
395: * @return <code>true</code> if the list definition contains an action
396: */
397: public boolean hasActions() {
398:
399: return !m_indepActions.elementList().isEmpty();
400: }
401:
402: /**
403: * Returns <code>true</code> if at least 'check' multiaction has been set.<p>
404: *
405: * @return <code>true</code> if at least 'check' multiaction has been set
406: */
407: public boolean hasCheckMultiActions() {
408:
409: Iterator it = m_multiActions.elementList().iterator();
410: while (it.hasNext()) {
411: CmsListMultiAction action = (CmsListMultiAction) it.next();
412: if (!(action instanceof CmsListRadioMultiAction)) {
413: return true;
414: }
415: }
416: return false;
417: }
418:
419: /**
420: * Returns <code>true</code> if the list definition contains a multi action.<p>
421: *
422: * @return <code>true</code> if the list definition contains a multi action
423: */
424: public boolean hasMultiActions() {
425:
426: return !m_multiActions.elementList().isEmpty();
427: }
428:
429: /**
430: * Returns <code>true</code> if any column definition contains a single action.<p>
431: *
432: * @return <code>true</code> if any column definition contains a single action
433: */
434: public boolean hasSingleActions() {
435:
436: Iterator itCols = m_columns.elementList().iterator();
437: while (itCols.hasNext()) {
438: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
439: .next();
440: if (!col.getDefaultActions().isEmpty()
441: || !col.getDirectActions().isEmpty()) {
442: return true;
443: }
444: }
445: return false;
446: }
447:
448: /**
449: * Returns the html code for the action bar.<p>
450: *
451: * @return html code
452: */
453: public String htmlActionBar() {
454:
455: StringBuffer html = new StringBuffer(1024);
456: html.append("<td class='misc'>\n");
457: html.append("\t<div>\n");
458: Iterator itDetails = m_itemDetails.elementList().iterator();
459: while (itDetails.hasNext()) {
460: I_CmsListAction detailAction = ((CmsListItemDetails) itDetails
461: .next()).getAction();
462: html.append("\t\t");
463: html.append(detailAction.buttonHtml());
464: if (itDetails.hasNext()) {
465: html.append(" ");
466: }
467: html.append("\n");
468: }
469: Iterator itActions = m_indepActions.elementList().iterator();
470: while (itActions.hasNext()) {
471: I_CmsListAction indepAction = (I_CmsListAction) itActions
472: .next();
473: html.append("\t\t");
474: html.append(" ");
475: html.append(indepAction.buttonHtml());
476: html.append("\n");
477: }
478: html.append("\t</div>\n");
479: html.append("</td>\n");
480: return html.toString();
481: }
482:
483: /**
484: * Generates the hml code for an empty table.<p>
485: *
486: * @return html code
487: */
488: public String htmlEmptyTable() {
489:
490: StringBuffer html = new StringBuffer(512);
491: html.append("<tr class='oddrowbg'>\n");
492: html.append("\t<td align='center' colspan='");
493: html.append(getWidth());
494: html.append("'>\n");
495: html.append(Messages.get().getBundle(getWp().getLocale()).key(
496: Messages.GUI_LIST_EMPTY_0));
497: html.append("\t</td>\n");
498: html.append("</tr>\n");
499: return html.toString();
500: }
501:
502: /**
503: * Returns the html code for the header of the list.<p>
504: *
505: * @param list the list to generate the code for
506: *
507: * @return html code
508: */
509: public String htmlHeader(CmsHtmlList list) {
510:
511: StringBuffer html = new StringBuffer(1024);
512: html.append("<tr>\n");
513: Iterator itCols = m_columns.elementList().iterator();
514: while (itCols.hasNext()) {
515: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
516: .next();
517: if (!col.isVisible() && !list.isPrintable()) {
518: continue;
519: }
520: if (!col.isPrintable() && list.isPrintable()) {
521: continue;
522: }
523: html.append(col.htmlHeader(list));
524: }
525: if (!list.isPrintable() && hasCheckMultiActions()) {
526: html.append("\t<th width='0' class='select'>\n");
527: html
528: .append("\t\t<input type='checkbox' class='checkbox' name='listSelectAll' value='true' onClick=\"listSelect('");
529: html.append(list.getId());
530: html.append("')\">\n");
531: html.append("\t</th>\n");
532: }
533: html.append("</tr>\n");
534: return html.toString();
535: }
536:
537: /**
538: * Returns the html code for a list item.<p>
539: *
540: * @param item the list item to render
541: * @param odd if the position is odd or even
542: * @param isPrintable if the list is to be printed
543: *
544: * @return html code
545: */
546: public String htmlItem(CmsListItem item, boolean odd,
547: boolean isPrintable) {
548:
549: StringBuffer html = new StringBuffer(1024);
550: html.append("<tr ");
551: if (!isPrintable) {
552: html.append("class='");
553: html.append(odd ? "oddrowbg"
554: : (getWp().useNewStyle() ? "evenrowbg"
555: : "evenrowbgnew"));
556: html.append("'");
557: }
558: html.append(">\n");
559: Iterator itCols = m_columns.elementList().iterator();
560: int width = 0;
561: while (itCols.hasNext()) {
562: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
563: .next();
564: if (!col.isVisible() && !isPrintable) {
565: continue;
566: }
567: if (!col.isPrintable() && isPrintable) {
568: continue;
569: }
570: width++;
571: StringBuffer style = new StringBuffer(64);
572: html.append("<td");
573: CmsListColumnAlignEnum align = col.getAlign();
574: if ((align != CmsListColumnAlignEnum.ALIGN_LEFT)
575: && CmsStringUtil.isNotEmpty(align.toString())) {
576: style.append("text-align: ");
577: style.append(col.getAlign());
578: style.append("; ");
579: }
580: if (col.isTextWrapping()) {
581: style.append("white-space: normal;");
582: }
583: if (isPrintable) {
584: style.append("border-top: 1px solid black;");
585: }
586: if (style.length() > 0) {
587: html.append(" style='");
588: html.append(style);
589: html.append("'");
590: }
591: html.append(">\n");
592: html.append(col.htmlCell(item, isPrintable));
593: html.append("</td>\n");
594: }
595: if (!isPrintable && hasCheckMultiActions()) {
596: width++;
597: html
598: .append("\t<td class='select' style='text-align: center'>\n");
599: html
600: .append("\t\t<input type='checkbox' class='checkbox' name='listMultiAction' value='");
601: html.append(item.getId());
602: html.append("'>\n");
603: html.append("\t</td>\n");
604: }
605: html.append("</tr>\n");
606:
607: Iterator itDet = m_itemDetails.elementList().iterator();
608: while (itDet.hasNext()) {
609: CmsListItemDetails lid = (CmsListItemDetails) itDet.next();
610: if (lid.isVisible()
611: && (item.get(lid.getId()) != null)
612: && CmsStringUtil.isNotEmptyOrWhitespaceOnly(item
613: .get(lid.getId()).toString())) {
614: int padCols = 0;
615: itCols = m_columns.elementList().iterator();
616: while (itCols.hasNext()) {
617: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
618: .next();
619: if (col.getId().equals(lid.getAtColumn())) {
620: break;
621: }
622: if (!col.isVisible() && !isPrintable) {
623: continue;
624: }
625: if (!col.isPrintable() && isPrintable) {
626: continue;
627: }
628: padCols++;
629: }
630: int spanCols = width - padCols;
631:
632: html.append("<tr ");
633: if (!isPrintable) {
634: html.append("class='");
635: html.append(odd ? "oddrowbg" : (getWp()
636: .useNewStyle() ? "evenrowbg"
637: : "evenrowbgnew"));
638: html.append("'");
639: }
640: html.append(">\n");
641: if (padCols > 0) {
642: html.append("<td colspan='");
643: html.append(padCols);
644: html.append("'> </td>\n");
645: }
646: html.append("<td colspan='");
647: html.append(spanCols);
648: html
649: .append("' style='padding-left: 20px; white-space:normal;'>\n");
650: html.append(lid.htmlCell(item, isPrintable));
651: html.append("\n</td>\n");
652: html.append("\n");
653: html.append("</tr>\n");
654: }
655: }
656: return html.toString();
657: }
658:
659: /**
660: * Returns the html code for the multi action bar.<p>
661: *
662: * @return html code
663: */
664: public String htmlMultiActionBar() {
665:
666: StringBuffer html = new StringBuffer(1024);
667: html.append("<td class='misc'>\n");
668: html.append("\t<div>\n");
669: Iterator itActions = m_multiActions.elementList().iterator();
670: while (itActions.hasNext()) {
671: CmsListMultiAction multiAction = (CmsListMultiAction) itActions
672: .next();
673: html.append("\t\t");
674: html.append(multiAction.buttonHtml());
675: if (itActions.hasNext()) {
676: html.append(" ");
677: }
678: html.append("\n");
679: }
680: html.append("\t</div>\n");
681: html.append("</td>\n");
682: return html.toString();
683: }
684:
685: /**
686: * Generates the html code for the search bar.<p>
687: *
688: * @return html code
689: */
690: public String htmlSearchBar() {
691:
692: if (!isSearchable()) {
693: return "";
694: }
695: StringBuffer html = new StringBuffer(1024);
696: html.append("<td class='main'>\n");
697: html.append("\t<div>\n");
698: html
699: .append("\t\t<input type='text' name='listSearchFilter' id='"
700: + SEARCH_BAR_INPUT_ID
701: + "' value='' size='20' maxlength='245' style='vertical-align: bottom;'>\n");
702: html.append(m_searchAction.buttonHtml());
703: I_CmsListAction showAllAction = m_searchAction
704: .getShowAllAction();
705: if (showAllAction != null) {
706: html.append(" ");
707: html.append(showAllAction.buttonHtml());
708: }
709: html.append("\t</div>\n");
710: html.append("</td>\n");
711: return html.toString();
712: }
713:
714: /**
715: * Returns <code>true</code> if the list is searchable.<p>
716: *
717: * @return <code>true</code> if the list is searchable
718: */
719: public boolean isSearchable() {
720:
721: return m_searchAction != null;
722: }
723:
724: /**
725: * Returns the self Managed flag.<p>
726: *
727: * @return the self Managed flag
728: */
729: public boolean isSelfManaged() {
730:
731: return m_selfManaged;
732: }
733:
734: /**
735: * Returns <code>true</code> if any column is sorteable.<p>
736: *
737: * @return <code>true</code> if any column is sorteable
738: */
739: public boolean isSorteable() {
740:
741: Iterator itCols = m_columns.elementList().iterator();
742: while (itCols.hasNext()) {
743: CmsListColumnDefinition col = (CmsListColumnDefinition) itCols
744: .next();
745: if (col.isSorteable()) {
746: return true;
747: }
748: }
749: return false;
750: }
751:
752: /**
753: * Returns <code>true</code> if this metadata object should not be cached.<p>
754: *
755: * @return <code>true</code> if this metadata object should not be cached.<p>
756: */
757: public boolean isVolatile() {
758:
759: return m_volatile;
760: }
761:
762: /**
763: * Sets the search action.<p>
764: *
765: * @param searchAction the search action to set
766: */
767: public void setSearchAction(CmsListSearchAction searchAction) {
768:
769: m_searchAction = searchAction;
770: if (m_searchAction != null) {
771: m_searchAction.setListId(getListId());
772: }
773: }
774:
775: /**
776: * Sets the self Managed flag.<p>
777: *
778: * @param selfManaged the self Managed flag to set
779: */
780: public void setSelfManaged(boolean selfManaged) {
781:
782: this .m_selfManaged = selfManaged;
783: }
784:
785: /**
786: * Sets the volatile flag.<p>
787: *
788: * @param volatileFlag the volatile flag to set
789: */
790: public void setVolatile(boolean volatileFlag) {
791:
792: m_volatile = volatileFlag;
793: }
794:
795: /**
796: * Sets the related workplace dialog.<p>
797: *
798: * @param wp the related workplace dialog to set
799: */
800: public void setWp(A_CmsListDialog wp) {
801:
802: m_wp = wp;
803: Iterator itCols = getColumnDefinitions().iterator();
804: while (itCols.hasNext()) {
805: CmsListColumnDefinition column = (CmsListColumnDefinition) itCols
806: .next();
807: column.setWp(wp);
808: }
809: Iterator itDets = getItemDetailDefinitions().iterator();
810: while (itDets.hasNext()) {
811: CmsListItemDetails detail = (CmsListItemDetails) itDets
812: .next();
813: detail.setWp(wp);
814: }
815: Iterator itMultiActs = getMultiActions().iterator();
816: while (itMultiActs.hasNext()) {
817: CmsListMultiAction action = (CmsListMultiAction) itMultiActs
818: .next();
819: action.setWp(wp);
820: }
821: Iterator itIndActs = getIndependentActions().iterator();
822: while (itIndActs.hasNext()) {
823: I_CmsListAction action = (I_CmsListAction) itIndActs.next();
824: action.setWp(wp);
825: }
826: if (m_searchAction != null) {
827: m_searchAction.setWp(wp);
828: }
829: }
830:
831: /**
832: * Toggles the given item detail state from visible to hidden or
833: * from hidden to visible.<p>
834: *
835: * @param itemDetailId the item detail id
836: */
837: public void toogleDetailState(String itemDetailId) {
838:
839: CmsListItemDetails lid = (CmsListItemDetails) m_itemDetails
840: .getObject(itemDetailId);
841: lid.setVisible(!lid.isVisible());
842: }
843:
844: /**
845: * Throws a runtime exception if there are 2 identical ids.<p>
846: *
847: * This includes:<p>
848: * <ul>
849: * <li><code>{@link CmsListIndependentAction}</code>s</li>
850: * <li><code>{@link CmsListMultiAction}</code>s</li>
851: * <li><code>{@link CmsListItemDetails}</code></li>
852: * <li><code>{@link CmsListColumnDefinition}</code>s</li>
853: * <li><code>{@link CmsListDefaultAction}</code>s</li>
854: * <li><code>{@link CmsListDirectAction}</code>s</li>
855: * </ul>
856: */
857: /*package*/void checkIds() {
858:
859: Set ids = new TreeSet();
860: // indep actions
861: Iterator itIndepActions = getIndependentActions().iterator();
862: while (itIndepActions.hasNext()) {
863: String id = ((CmsListIndependentAction) itIndepActions
864: .next()).getId();
865: if (ids.contains(id)) {
866: throw new CmsIllegalStateException(Messages.get()
867: .container(Messages.ERR_DUPLICATED_ID_1, id));
868: }
869: ids.add(id);
870: }
871: // multi actions
872: Iterator itMultiActions = getMultiActions().iterator();
873: while (itMultiActions.hasNext()) {
874: String id = ((CmsListMultiAction) itMultiActions.next())
875: .getId();
876: if (ids.contains(id)) {
877: throw new CmsIllegalStateException(Messages.get()
878: .container(Messages.ERR_DUPLICATED_ID_1, id));
879: }
880: ids.add(id);
881: }
882: // details
883: Iterator itItemDetails = getItemDetailDefinitions().iterator();
884: while (itItemDetails.hasNext()) {
885: String id = ((CmsListItemDetails) itItemDetails.next())
886: .getId();
887: if (ids.contains(id)) {
888: throw new CmsIllegalStateException(Messages.get()
889: .container(Messages.ERR_DUPLICATED_ID_1, id));
890: }
891: ids.add(id);
892: }
893: // columns
894: Iterator itColumns = getColumnDefinitions().iterator();
895: while (itColumns.hasNext()) {
896: CmsListColumnDefinition col = (CmsListColumnDefinition) itColumns
897: .next();
898: if (ids.contains(col.getId())) {
899: throw new CmsIllegalStateException(Messages.get()
900: .container(Messages.ERR_DUPLICATED_ID_1,
901: col.getId()));
902: }
903: ids.add(col.getId());
904: // default actions
905: Iterator itDefaultActions = col.getDefaultActions()
906: .iterator();
907: while (itDefaultActions.hasNext()) {
908: CmsListDefaultAction action = (CmsListDefaultAction) itDefaultActions
909: .next();
910: if (ids.contains(action.getId())) {
911: throw new CmsIllegalStateException(Messages.get()
912: .container(Messages.ERR_DUPLICATED_ID_1,
913: action.getId()));
914: }
915: ids.add(action.getId());
916: }
917: // direct actions
918: Iterator itDirectActions = col.getDirectActions()
919: .iterator();
920: while (itDirectActions.hasNext()) {
921: CmsListDirectAction action = (CmsListDirectAction) itDirectActions
922: .next();
923: if (ids.contains(action.getId())) {
924: throw new CmsIllegalStateException(Messages.get()
925: .container(Messages.ERR_DUPLICATED_ID_1,
926: action.getId()));
927: }
928: ids.add(action.getId());
929: }
930: }
931: }
932:
933: /**
934: * Sets the list id for all column single actions.<p>
935: *
936: * @param col the column to set the list id for
937: */
938: private void setListIdForColumn(CmsListColumnDefinition col) {
939:
940: col.setListId(getListId());
941: // default actions
942: Iterator itDefaultActions = col.getDefaultActions().iterator();
943: while (itDefaultActions.hasNext()) {
944: ((CmsListDefaultAction) itDefaultActions.next())
945: .setListId(getListId());
946: }
947: // direct actions
948: Iterator itDirectActions = col.getDirectActions().iterator();
949: while (itDirectActions.hasNext()) {
950: ((CmsListDirectAction) itDirectActions.next())
951: .setListId(getListId());
952: }
953: }
954: }
|