KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > explorer > CmsExplorerTypeSettings


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsExplorerTypeSettings.java,v $
3  * Date : $Date: 2006/03/27 14:52:30 $
4  * Version: $Revision: 1.17 $
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.explorer;
33
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplaceManager;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.List JavaDoc;
41
42 import org.apache.commons.logging.Log;
43
44 /**
45  * Holds all information to build the explorer context menu of a resource type
46  * and information for the new resource dialog.<p>
47  *
48  * Objects of this type are sorted by their order value which specifies the order
49  * in the new resource dialog.<p>
50  *
51  * @author Andreas Zahner
52  *
53  * @version $Revision: 1.17 $
54  *
55  * @since 6.0.0
56  */

57 public class CmsExplorerTypeSettings implements Comparable JavaDoc {
58
59     /** The log object for this class. */
60     private static final Log LOG = CmsLog.getLog(CmsExplorerTypeSettings.class);
61
62     private CmsExplorerTypeAccess m_access;
63
64     /** Flag for showing that this is an additional resource type which defined in a module. */
65     private boolean m_addititionalModuleExplorerType;
66     private boolean m_autoSetNavigation;
67     private boolean m_autoSetTitle;
68     private CmsExplorerContextMenu m_contextMenu;
69     private List JavaDoc m_contextMenuEntries;
70     private boolean m_hasEditOptions;
71     private String JavaDoc m_icon;
72     private String JavaDoc m_key;
73     private String JavaDoc m_name;
74
75     /** Optional class name for a new resource handler. */
76     private String JavaDoc m_newResourceHandlerClassName;
77     private Integer JavaDoc m_newResourceOrder;
78     private String JavaDoc m_newResourcePage;
79     private String JavaDoc m_newResourceUri;
80     private List JavaDoc m_properties;
81     private boolean m_propertiesEnabled;
82     private String JavaDoc m_reference;
83     private boolean m_showNavigation;
84
85     /**
86      * Default constructor.<p>
87      */

88     public CmsExplorerTypeSettings() {
89
90         m_access = new CmsExplorerTypeAccess();
91         m_properties = new ArrayList JavaDoc();
92         m_contextMenuEntries = new ArrayList JavaDoc();
93         m_contextMenu = new CmsExplorerContextMenu();
94         m_hasEditOptions = false;
95         m_propertiesEnabled = false;
96         m_showNavigation = false;
97         m_addititionalModuleExplorerType = false;
98         m_newResourceOrder = new Integer JavaDoc(0);
99     }
100
101     /**
102      * Adds a single context menu entry to the list of context menu items.<p>
103      *
104      * @param key the key of the current entry
105      * @param uri the dialog URI to call with the current entry
106      * @param rules the display rules
107      * @param target the frame target of the menu entry
108      * @param order the sort order of the current entry
109      */

110     public void addContextMenuEntry(String JavaDoc key, String JavaDoc uri, String JavaDoc rules, String JavaDoc target, String JavaDoc order) {
111
112         Integer JavaDoc orderValue = new Integer JavaDoc(0);
113         try {
114             orderValue = Integer.valueOf(order);
115         } catch (Exception JavaDoc e) {
116             if (LOG.isErrorEnabled()) {
117                 LOG.error(Messages.get().getBundle().key(Messages.LOG_WRONG_ORDER_CONTEXT_MENU_1, key));
118             }
119         }
120         CmsExplorerContextMenuItem item = new CmsExplorerContextMenuItem(
121             CmsExplorerContextMenuItem.TYPE_ENTRY,
122             key,
123             uri,
124             rules,
125             target,
126             orderValue);
127         
128         m_contextMenuEntries.add(item);
129         if (LOG.isDebugEnabled()) {
130             LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_MENU_ENTRY_2, key, order));
131         }
132     }
133
134     /**
135      * Adds a menu separator to the list of context menu items.<p>
136      *
137      * @param order the sort order of the separator
138      */

139     public void addContextMenuSeparator(String JavaDoc order) {
140
141         Integer JavaDoc orderValue = new Integer JavaDoc(0);
142         try {
143             orderValue = Integer.valueOf(order);
144         } catch (Exception JavaDoc e) {
145             LOG.error(Messages.get().getBundle().key(Messages.LOG_WRONG_MENU_SEP_ORDER_0, order));
146         }
147         CmsExplorerContextMenuItem item = new CmsExplorerContextMenuItem(
148             CmsExplorerContextMenuItem.TYPE_SEPARATOR,
149             null,
150             null,
151             null,
152             null,
153             orderValue);
154         m_contextMenuEntries.add(item);
155         if (LOG.isDebugEnabled()) {
156             LOG.debug(Messages.get().getBundle().key(Messages.LOG_WRONG_MENU_SEP_ORDER_0, order));
157         }
158     }
159
160     /**
161      * Adds a property definition name to the list of editable properties.<p>
162      *
163      * @param propertyName the name of the property definition to add
164      * @return true if the property definition was added properly
165      */

166     public boolean addProperty(String JavaDoc propertyName) {
167
168         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propertyName)) {
169             if (LOG.isDebugEnabled()) {
170                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_PROP_1, propertyName));
171             }
172             return m_properties.add(propertyName);
173         } else {
174             return false;
175         }
176     }
177
178     /**
179      * @see java.lang.Comparable#compareTo(java.lang.Object)
180      */

181     public int compareTo(Object JavaDoc obj) {
182
183         if (obj == this) {
184             return 0;
185         }
186         if (obj instanceof CmsExplorerTypeSettings) {
187             CmsExplorerTypeSettings other = (CmsExplorerTypeSettings)obj;
188             String JavaDoc myPage = getNewResourcePage();
189             String JavaDoc otherPage = other.getNewResourcePage();
190             if (CmsStringUtil.isEmptyOrWhitespaceOnly(myPage)) {
191                 myPage = "";
192             }
193             if (CmsStringUtil.isEmptyOrWhitespaceOnly(otherPage)) {
194                 otherPage = "";
195             }
196             int result = myPage.compareTo(otherPage);
197             if (result == 0) {
198                 result = m_newResourceOrder.compareTo(other.m_newResourceOrder);
199             }
200             return result;
201         }
202         return 0;
203     }
204
205     /**
206      * Adds all context menu entries to the context menu object.<p>
207      *
208      * This method has to be called when all context menu entries have been
209      * added to the list of entries.<p>
210      */

211     public void createContextMenu() {
212
213         m_contextMenu.addEntries(getContextMenuEntries());
214         if (LOG.isDebugEnabled()) {
215             LOG.debug(Messages.get().getBundle().key(Messages.LOG_CREATE_CONTEXT_MENU_1, getName()));
216         }
217     }
218
219     /**
220      * @see java.lang.Object#equals(java.lang.Object)
221      */

222     public boolean equals(Object JavaDoc o) {
223
224         if (!(o instanceof CmsExplorerTypeSettings)) {
225             return false;
226         }
227         CmsExplorerTypeSettings other = (CmsExplorerTypeSettings)o;
228         return getName().equals(other.getName());
229     }
230
231     /**
232      * Gets the access object of the type settings.<p>
233      *
234      * @return access object of the type settings
235      */

236     public CmsExplorerTypeAccess getAccess() {
237
238         if (m_access.isEmpty()) {
239             CmsWorkplaceManager workplaceManager = OpenCms.getWorkplaceManager();
240             if (workplaceManager != null) {
241                 m_access = workplaceManager.getDefaultAccess();
242             }
243         }
244         return m_access;
245     }
246
247     /**
248      * Returns the context menu.<p>
249      * @return the context menu
250      */

251     public CmsExplorerContextMenu getContextMenu() {
252
253         if ((m_reference != null) && (m_contextMenu.isEmpty())) {
254             m_contextMenu = (CmsExplorerContextMenu)OpenCms.getWorkplaceManager().getExplorerTypeSetting(m_reference).getContextMenu().clone();
255         }
256         return m_contextMenu;
257     }
258
259     /**
260      * Returns the list of context menu entries of the explorer type setting.<p>
261      *
262      * @return the list of context menu entries of the explorer type setting
263      */

264     public List JavaDoc getContextMenuEntries() {
265
266         return m_contextMenuEntries;
267     }
268
269     /**
270      * Returns the icon path and file name of the explorer type setting.<p>
271      *
272      * @return the icon path and file name of the explorer type setting
273      */

274     public String JavaDoc getIcon() {
275
276         return m_icon;
277     }
278
279     /**
280      * Returns the key name of the explorer type setting.<p>
281      *
282      * @return the key name of the explorer type setting
283      */

284     public String JavaDoc getKey() {
285
286         return m_key;
287     }
288
289     /**
290      * Returns the name of the explorer type setting.<p>
291      *
292      * @return the name of the explorer type setting
293      */

294     public String JavaDoc getName() {
295
296         return m_name;
297     }
298
299     /**
300      * Returns the class name of the new resource handler used to create new resources of a specified resource type.<p>
301      *
302      * @return the class name of the new resource handler
303      */

304     public String JavaDoc getNewResourceHandlerClassName() {
305
306         return m_newResourceHandlerClassName;
307     }
308
309     /**
310      * Returns the order for the new resource dialog of the explorer type setting.<p>
311      *
312      * @return the order for the new resource dialog of the explorer type setting
313      */

314     public String JavaDoc getNewResourceOrder() {
315
316         return String.valueOf(m_newResourceOrder);
317     }
318
319     /**
320      * Returns the page.<p>
321      *
322      * @return the page
323      */

324     public String JavaDoc getNewResourcePage() {
325
326         return m_newResourcePage;
327     }
328
329     /**
330      * Returns the URI for the new resource dialog of the explorer type setting.<p>
331      *
332      * @return the URI for the new resource dialog of the explorer type setting
333      */

334     public String JavaDoc getNewResourceUri() {
335
336         return m_newResourceUri;
337     }
338
339     /**
340      * Returns the list of properties of the explorer type setting.<p>
341      * @return the list of properties of the explorer type setting
342      */

343     public List JavaDoc getProperties() {
344
345         return m_properties;
346     }
347
348     /**
349      * Returns the reference of the explorer type setting.<p>
350      *
351      * @return the reference of the explorer type setting
352      */

353     public String JavaDoc getReference() {
354
355         return m_reference;
356     }
357
358     /**
359      * Returns true if this explorer type entry has explicit edit options set.<p>
360      *
361      * @return true if this explorer type entry has explicit edit options set
362      */

363     public boolean hasEditOptions() {
364
365         return m_hasEditOptions;
366     }
367
368     /**
369      * @see java.lang.Object#hashCode()
370      */

371     public int hashCode() {
372
373         return getName().hashCode();
374     }
375
376     /**
377      * Indicates that this is an additional explorer type which is defined in a module.<p>
378      *
379      * @return true or false
380      */

381     public boolean isAddititionalModuleExplorerType() {
382
383         return m_addititionalModuleExplorerType;
384     }
385
386     /**
387      * Returns true if navigation properties should automatically be added on resource creation.<p>
388      *
389      * @return true if navigation properties should automatically be added on resource creation, otherwise false
390      */

391     public boolean isAutoSetNavigation() {
392
393         return m_autoSetNavigation;
394     }
395
396     /**
397      * Returns true if the title property should automatically be added on resource creation.<p>
398      *
399      * @return true if the title property should automatically be added on resource creation, otherwise false
400      */

401     public boolean isAutoSetTitle() {
402
403         return m_autoSetTitle;
404     }
405
406     /**
407      * Returns if this explorer type setting uses a special properties dialog.<p>
408      *
409      * @return true, if this explorer type setting uses a special properties dialog
410      */

411     public boolean isPropertiesEnabled() {
412
413         return m_propertiesEnabled;
414     }
415
416     /**
417      * Returns if this explorer type setting displays the navigation properties in the special properties dialog.<p>
418      *
419      * @return true, if this explorer type setting displays the navigation properties in the special properties dialog
420      */

421     public boolean isShowNavigation() {
422
423         return m_showNavigation;
424     }
425
426     /**
427      * Sets the access object of the type settings.<p>
428      *
429      * @param access access object
430      */

431     public void setAccess(CmsExplorerTypeAccess access) {
432
433         m_access = access;
434     }
435
436     /**
437      * Sets the additional explorer type flag.<p>
438      *
439      * @param addititionalModuleExplorerType true or false
440      */

441     public void setAddititionalModuleExplorerType(boolean addititionalModuleExplorerType) {
442
443         m_addititionalModuleExplorerType = addititionalModuleExplorerType;
444     }
445
446     /**
447      * Sets if navigation properties should automatically be added on resource creation.<p>
448      *
449      * @param autoSetNavigation true if properties should be added, otherwise false
450      */

451     public void setAutoSetNavigation(String JavaDoc autoSetNavigation) {
452
453         m_autoSetNavigation = Boolean.valueOf(autoSetNavigation).booleanValue();
454         if (LOG.isDebugEnabled()) {
455             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_AUTO_NAV_1, autoSetNavigation));
456         }
457     }
458
459     /**
460      * Sets if the title property should automatically be added on resource creation.<p>
461      *
462      * @param autoSetTitle true if title should be added, otherwise false
463      */

464     public void setAutoSetTitle(String JavaDoc autoSetTitle) {
465
466         m_autoSetTitle = Boolean.valueOf(autoSetTitle).booleanValue();
467         if (LOG.isDebugEnabled()) {
468             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_AUTO_TITLE_1, autoSetTitle));
469         }
470     }
471
472     /**
473      * Sets the list of context menu entries of the explorer type setting.<p>
474      *
475      * @param entries the list of context menu entries of the explorer type setting
476      */

477     public void setContextMenuEntries(List JavaDoc entries) {
478
479         m_contextMenuEntries = entries;
480     }
481
482     /**
483      * Sets the flag if this explorer type entry has explicit edit options set.<p>
484      *
485      * This is determined by the presence of the &lt;editoptions&gt; node in the Cms workplace configuration.<p>
486      */

487     public void setEditOptions() {
488
489         m_hasEditOptions = true;
490     }
491
492     /**
493      * Sets the icon path and file name of the explorer type setting.<p>
494      *
495      * @param icon the icon path and file name of the explorer type setting
496      */

497     public void setIcon(String JavaDoc icon) {
498
499         m_icon = icon;
500         if (LOG.isDebugEnabled()) {
501             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_ICON_1, icon));
502         }
503     }
504
505     /**
506      * Sets the key name of the explorer type setting.<p>
507      *
508      * @param key the key name of the explorer type setting
509      */

510     public void setKey(String JavaDoc key) {
511
512         m_key = key;
513         if (LOG.isDebugEnabled()) {
514             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_KEY_1, key));
515         }
516     }
517
518     /**
519      * Sets the name of the explorer type setting.<p>
520      *
521      * @param name the name of the explorer type setting
522      */

523     public void setName(String JavaDoc name) {
524
525         m_name = name;
526         if (LOG.isDebugEnabled()) {
527             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NAME_1, name));
528         }
529     }
530
531     /**
532      * Sets the class name of the new resource handler used to create new resources of a specified resource type.<p>
533      *
534      * @param newResourceHandlerClassName the class name of the new resource handler
535      */

536     public void setNewResourceHandlerClassName(String JavaDoc newResourceHandlerClassName) {
537
538         m_newResourceHandlerClassName = newResourceHandlerClassName;
539     }
540
541     /**
542      * Sets the order for the new resource dialog of the explorer type setting.<p>
543      *
544      * @param newResourceOrder the order for the new resource dialog of the explorer type setting
545      */

546     public void setNewResourceOrder(String JavaDoc newResourceOrder) {
547
548         try {
549             m_newResourceOrder = Integer.valueOf(newResourceOrder);
550             if (LOG.isDebugEnabled()) {
551                 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NEW_RESOURCE_ORDER_1, newResourceOrder));
552             }
553         } catch (Exception JavaDoc e) {
554             // can usually be ignored
555
if (LOG.isInfoEnabled()) {
556                 LOG.info(e);
557             }
558             m_newResourceOrder = new Integer JavaDoc(0);
559         }
560     }
561
562     /**
563      * Sets the page.<p>
564      *
565      * @param page the page to set
566      */

567     public void setNewResourcePage(String JavaDoc page) {
568
569         m_newResourcePage = page;
570     }
571
572     /**
573      * Sets the URI for the new resource dialog of the explorer type setting.<p>
574      *
575      * @param newResourceUri the URI for the new resource dialog of the explorer type setting
576      */

577     public void setNewResourceUri(String JavaDoc newResourceUri) {
578
579         m_newResourceUri = newResourceUri;
580         if (LOG.isDebugEnabled()) {
581             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_NEW_RESOURCE_URI_1, newResourceUri));
582         }
583     }
584
585     /**
586      * Sets the list of properties of the explorer type setting.<p>
587      *
588      * @param properties the list of properties of the explorer type setting
589      */

590     public void setProperties(List JavaDoc properties) {
591
592         m_properties = properties;
593     }
594
595     /**
596      * Sets if this explorer type setting uses a special properties dialog.<p>
597      *
598      * @param enabled true, if this explorer type setting uses a special properties dialog
599      */

600     public void setPropertiesEnabled(boolean enabled) {
601
602         m_propertiesEnabled = enabled;
603     }
604
605     /**
606      * Sets the default settings for the property display dialog.<p>
607      *
608      * @param enabled true, if this explorer type setting uses a special properties dialog
609      * @param showNavigation true, if this explorer type setting displays the navigation properties in the special properties dialog
610      */

611     public void setPropertyDefaults(String JavaDoc enabled, String JavaDoc showNavigation) {
612
613         setPropertiesEnabled(Boolean.valueOf(enabled).booleanValue());
614         setShowNavigation(Boolean.valueOf(showNavigation).booleanValue());
615         if (LOG.isDebugEnabled()) {
616             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_PROP_DEFAULTS_2, enabled, showNavigation));
617         }
618     }
619
620     /**
621      * Sets the reference of the explorer type setting.<p>
622      *
623      * @param reference the reference of the explorer type setting
624      */

625     public void setReference(String JavaDoc reference) {
626
627         m_reference = reference;
628         if (LOG.isDebugEnabled()) {
629             LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_REFERENCE_1, m_reference));
630         }
631     }
632
633     /**
634      * Sets if this explorer type setting displays the navigation properties in the special properties dialog.<p>
635      *
636      * @param navigation true, if this explorer type setting displays the navigation properties in the special properties dialog
637      */

638     public void setShowNavigation(boolean navigation) {
639
640         m_showNavigation = navigation;
641     }
642
643     /**
644      * Sets the basic attributes of the type settings.<p>
645      *
646      * @param name the name of the type setting
647      * @param key the key name of the explorer type setting
648      * @param icon the icon path and file name of the explorer type setting
649      */

650     public void setTypeAttributes(String JavaDoc name, String JavaDoc key, String JavaDoc icon) {
651
652         setName(name);
653         setKey(key);
654         setIcon(icon);
655     }
656
657     /**
658      * Sets the basic attributes of the type settings.<p>
659      *
660      * @param name the name of the type setting
661      * @param key the key name of the explorer type setting
662      * @param icon the icon path and file name of the explorer type setting
663      * @param reference the reference of the explorer type setting
664      */

665     public void setTypeAttributes(String JavaDoc name, String JavaDoc key, String JavaDoc icon, String JavaDoc reference) {
666
667         setName(name);
668         setKey(key);
669         setIcon(icon);
670         setReference(reference);
671     }
672 }
Popular Tags