001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.containerpage.shared;
029
030import org.opencms.gwt.shared.CmsPermissionInfo;
031import org.opencms.gwt.shared.I_CmsHasIconClasses;
032import org.opencms.util.CmsUUID;
033
034import com.google.gwt.user.client.rpc.IsSerializable;
035
036/**
037 * Bean holding basic container element information.<p>
038 *
039 * @since 8.0.0
040 */
041public class CmsContainerElement implements IsSerializable, I_CmsHasIconClasses {
042
043    /** The model group states. */
044    public static enum ModelGroupState {
045        /** Is model group state. */
046        isModelGroup,
047
048        /** No model group what so ever. */
049        noGroup,
050
051        /** Former copy model group. */
052        wasModelGroup;
053
054        /**
055         * Evaluates the given state string.<p>
056         *
057         * @param state the state
058         *
059         * @return the model group state
060         */
061        public static ModelGroupState evaluate(String state) {
062
063            ModelGroupState result = null;
064            if (state != null) {
065                try {
066                    result = ModelGroupState.valueOf(state);
067                } catch (IllegalArgumentException e) {
068                    // ignore
069                }
070            }
071            if (result == null) {
072                result = noGroup;
073            }
074            return result;
075        }
076    }
077
078    /** HTML class used to identify containers. */
079    public static final String CLASS_CONTAINER = "oc-container";
080
081    /** HTML class used to identify container elements. */
082    public static final String CLASS_CONTAINER_ELEMENT_END_MARKER = "oc-element-end";
083
084    /** HTML class used to identify container elements. */
085    public static final String CLASS_CONTAINER_ELEMENT_START_MARKER = "oc-element-start";
086
087    /** HTML class used to identify error message for elements where rendering failed to render. */
088    public static final String CLASS_ELEMENT_ERROR = "oc-element-error";
089
090    /** HTML class used to identify group container elements. */
091    public static final String CLASS_GROUP_CONTAINER_ELEMENT_MARKER = "oc-groupcontainer";
092
093    /** The create as new setting key. */
094    public static final String CREATE_AS_NEW = "create_as_new";
095
096    /** The element instance id settings key. */
097    public static final String ELEMENT_INSTANCE_ID = "element_instance_id";
098
099    /** The group container resource type name. */
100    public static final String GROUP_CONTAINER_TYPE_NAME = "groupcontainer";
101
102    /** The resource type name for inherited container references.  */
103    public static final String INHERIT_CONTAINER_TYPE_NAME = "inheritance_group";
104
105    /** The is model group always replace element setting key. */
106    public static final String IS_MODEL_GROUP_ALWAYS_REPLACE = "is_model_group_always_replace";
107
108    /** The container id marking the edit menus. */
109    public static final String MENU_CONTAINER_ID = "cms_edit_menu_container";
110
111    /** The model group id setting key. */
112    public static final String MODEL_GROUP_ID = "model_group_id";
113
114    /** The is model group element setting key. */
115    public static final String MODEL_GROUP_STATE = "model_group_state";
116
117    /** The use as copy model setting key. */
118    public static final String USE_AS_COPY_MODEL = "use_as_copy_model";
119
120    /** The element client id. */
121    private String m_clientId;
122
123    /** The copy in models flag. */
124    private boolean m_copyInModels;
125
126    /** The 'create new' status of the element. */
127    private boolean m_createNew;
128
129    /** The element view this element belongs to by it's type. */
130    private CmsUUID m_elementView;
131
132    /** Indicates an edit handler is configured for the given resource type. */
133    private boolean m_hasEditHandler;
134
135    /** Flag to indicate that this element may have settings. */
136    private boolean m_hasSettings;
137
138    /** The resource type icon CSS classes. */
139    private String m_iconClasses;
140
141    /** The inheritance info for this element. */
142    private CmsInheritanceInfo m_inheritanceInfo;
143
144    /** The model group always replace flag. */
145    private boolean m_isModelGroupAlwaysReplace;
146
147    /** The model group id or null. */
148    private CmsUUID m_modelGroupId;
149
150    /** Flag indicating a new element. */
151    private boolean m_new;
152
153    /** Flag which controls whether the new editor is disabled for this element. */
154    private boolean m_newEditorDisabled;
155
156    /** The permission info for the element resource. */
157    private CmsPermissionInfo m_permissionInfo;
158
159    /** Flag indicating if the given resource is released and not expired. */
160    private boolean m_releasedAndNotExpired = true;
161
162    /** The resource type for new elements. If this field is not empty, the element is regarded as new and not created yet. */
163    private String m_resourceType;
164
165    /** The full site path. */
166    private String m_sitePath;
167
168    /** The sub title. */
169    private String m_subTitle;
170
171    /** The title. */
172    private String m_title;
173
174    /** The former copy model status. */
175    private boolean m_wasModelGroup;
176
177    /**
178     * Default constructor.<p>
179     */
180    public CmsContainerElement() {
181
182        // empty
183    }
184
185    /**
186     * Copies the container element.<p>
187     *
188     * @return the new copy of the container element
189     */
190    public CmsContainerElement copy() {
191
192        CmsContainerElement result = new CmsContainerElement();
193        result.m_clientId = m_clientId;
194        result.m_hasSettings = m_hasSettings;
195        result.m_inheritanceInfo = m_inheritanceInfo;
196        result.m_new = m_new;
197        result.m_newEditorDisabled = m_newEditorDisabled;
198        result.m_permissionInfo = new CmsPermissionInfo(
199            m_permissionInfo.hasViewPermission(),
200            m_permissionInfo.hasWritePermission(),
201            m_permissionInfo.getNoEditReason());
202        result.m_releasedAndNotExpired = m_releasedAndNotExpired;
203        result.m_resourceType = m_resourceType;
204        result.m_iconClasses = m_iconClasses;
205        result.m_sitePath = m_sitePath;
206        result.m_subTitle = m_subTitle;
207        result.m_title = m_title;
208        result.m_elementView = m_elementView;
209        result.m_modelGroupId = m_modelGroupId;
210        result.m_wasModelGroup = m_wasModelGroup;
211        result.m_isModelGroupAlwaysReplace = m_isModelGroupAlwaysReplace;
212        return result;
213
214    }
215
216    /**
217     * Returns the resource type icon CSS rules.<p>
218     *
219     * @return the resource type icon CSS rules
220     */
221    public String getBigIconClasses() {
222
223        return m_iconClasses;
224    }
225
226    /**
227     * Returns the client id.<p>
228     *
229     * @return the client id
230     */
231    public String getClientId() {
232
233        return m_clientId;
234    }
235
236    /**
237     * Returns the element view this element belongs to by it's type.<p>
238     *
239     * @return the element view
240     */
241    public CmsUUID getElementView() {
242
243        return m_elementView;
244    }
245
246    /**
247     * Returns the inheritance info for this element.<p>
248     *
249     * @return the inheritance info for this element
250     */
251    public CmsInheritanceInfo getInheritanceInfo() {
252
253        return m_inheritanceInfo;
254    }
255
256    /**
257     * Returns the model group id.<p>
258     *
259     * @return the model group id
260     */
261    public CmsUUID getModelGroupId() {
262
263        return m_modelGroupId;
264    }
265
266    /**
267     * Returns the no edit reason. If empty editing is allowed.<p>
268     *
269     * @return the no edit reason
270     */
271    public String getNoEditReason() {
272
273        return m_permissionInfo.getNoEditReason();
274    }
275
276    /**
277     * Returns the resource type name for elements.<p>
278     *
279     * @return the resource type name
280     */
281    public String getResourceType() {
282
283        return m_resourceType;
284    }
285
286    /**
287     * Returns the site path.<p>
288     *
289     * @return the site path
290     */
291    public String getSitePath() {
292
293        return m_sitePath;
294    }
295
296    /**
297     * @see org.opencms.gwt.shared.I_CmsHasIconClasses#getSmallIconClasses()
298     */
299    public String getSmallIconClasses() {
300
301        // not needed
302        return null;
303    }
304
305    /**
306     * Returns the sub title.<p>
307     *
308     * @return the sub title
309     */
310    public String getSubTitle() {
311
312        return m_subTitle;
313    }
314
315    /**
316     * Returns the title.<p>
317     *
318     * @return the title
319     */
320    public String getTitle() {
321
322        return m_title;
323    }
324
325    /**
326     * Returns if an edit handler is configured for the given resource type.<p>
327     *
328     * @return <code>true</code> if an edit handler is configured for the given resource type
329     */
330    public boolean hasEditHandler() {
331
332        return m_hasEditHandler;
333    }
334
335    /**
336     * Returns if the element may have settings.<p>
337     *
338     * @param containerId the container id
339     *
340     * @return <code>true</code> if the element may have settings
341     */
342    public boolean hasSettings(String containerId) {
343
344        return m_hasSettings;
345    }
346
347    /**
348     * Returns if the current user has view permissions for the element resource.<p>
349     *
350     * @return <code>true</code> if the current user has view permissions for the element resource
351     */
352    public boolean hasViewPermission() {
353
354        return m_permissionInfo.hasViewPermission();
355    }
356
357    /**
358     * Returns if the user has write permission.<p>
359     *
360     * @return <code>true</code> if the user has write permission
361     */
362    public boolean hasWritePermission() {
363
364        return m_permissionInfo.hasWritePermission();
365    }
366
367    /**
368     * Returns the copy in models flag.<p>
369     *
370     * @return the copy in models flag
371     */
372    public boolean isCopyInModels() {
373
374        return m_copyInModels;
375    }
376
377    /**
378     * Reads the 'create new' status of the element.<p>
379     *
380     * When the page containing the element is used a model page, this flag determines whether a copy of the element
381     * is created when creating a new page from that model page.<p>
382     *
383     * @return the 'create new' status of the element
384     */
385    public boolean isCreateNew() {
386
387        return m_createNew;
388    }
389
390    /**
391     * Returns if the given element is of the type group container.<p>
392     *
393     * @return <code>true</code> if the given element is of the type group container
394     */
395    public boolean isGroupContainer() {
396
397        return GROUP_CONTAINER_TYPE_NAME.equals(m_resourceType);
398    }
399
400    /**
401     * Returns if the given element is of the type inherit container.<p>
402     *
403     * @return <code>true</code> if the given element is of the type inherit container
404     */
405    public boolean isInheritContainer() {
406
407        return INHERIT_CONTAINER_TYPE_NAME.equals(m_resourceType);
408    }
409
410    /**
411     * Returns if the element is a model group.<p>
412     *
413     * @return <code>true</code> if the element is a model group
414     */
415    public boolean isModelGroup() {
416
417        return m_modelGroupId != null;
418    }
419
420    /**
421     * Returns if all instances of this element should be replaced within a model group.<p>
422     *
423     * @return <code>true</code> if all instances of this element should be replaced within a model group
424     */
425    public boolean isModelGroupAlwaysReplace() {
426
427        return m_isModelGroupAlwaysReplace;
428    }
429
430    /**
431     * Returns if the element is new and has not been created in the VFS yet.<p>
432     *
433     * @return <code>true</code> if the element is not created in the VFS yet
434     */
435    public boolean isNew() {
436
437        return m_new;
438    }
439
440    /**
441     * Returns true if the new editor is disabled for this element.<p>
442     *
443     * @return true if the new editor is disabled for this element
444     */
445    public boolean isNewEditorDisabled() {
446
447        return m_newEditorDisabled;
448    }
449
450    /**
451     * Returns if the given resource is released and not expired.<p>
452     *
453     * @return <code>true</code> if the given resource is released and not expired
454     */
455    public boolean isReleasedAndNotExpired() {
456
457        return m_releasedAndNotExpired;
458    }
459
460    /**
461     * Returns the former copy model status.<p>
462     *
463     * @return the former copy model status
464     */
465    public boolean isWasModelGroup() {
466
467        return m_wasModelGroup;
468    }
469
470    /**
471     * Sets the client id.<p>
472     *
473     * @param clientId the client id to set
474     */
475    public void setClientId(String clientId) {
476
477        m_clientId = clientId;
478    }
479
480    /**
481     * Sets the copy in models flag.<p>
482     *
483     * @param copyInModels the copy in models flag to set
484     */
485    public void setCopyInModels(boolean copyInModels) {
486
487        m_copyInModels = copyInModels;
488    }
489
490    /**
491     * Sets the 'create new' status of the element.<p>
492     *
493     * @param createNew the new 'create new' status
494     */
495    public void setCreateNew(boolean createNew) {
496
497        m_createNew = createNew;
498    }
499
500    /**
501     * Sets the element view.<p>
502     *
503     * @param elementView the element view to set
504     */
505    public void setElementView(CmsUUID elementView) {
506
507        m_elementView = elementView;
508    }
509
510    /**
511     * Sets the if an edit handler is configured for the given resource type.<p>
512     *
513     * @param hasEditHandler if an edit handler is configured for the given resource type
514     */
515    public void setHasEditHandler(boolean hasEditHandler) {
516
517        m_hasEditHandler = hasEditHandler;
518    }
519
520    /**
521     * Sets if the element may have settings.<p>
522     *
523     * @param hasSettings <code>true</code> if the element may have settings
524     */
525    public void setHasSettings(boolean hasSettings) {
526
527        m_hasSettings = hasSettings;
528    }
529
530    /**
531     * Sets the resource type icon CSS rules.<p>
532     *
533     * @param iconRules resource type icon CSS rules to set
534     */
535    public void setIconClasses(String iconRules) {
536
537        m_iconClasses = iconRules;
538    }
539
540    /**
541     * Sets the inheritance info for this element.<p>
542     *
543     * @param inheritanceInfo the inheritance info for this element to set
544     */
545    public void setInheritanceInfo(CmsInheritanceInfo inheritanceInfo) {
546
547        m_inheritanceInfo = inheritanceInfo;
548    }
549
550    /**
551     * Sets if all instances of this element should be replaced within a model group.<p>
552     *
553     * @param alwaysReplace if all instances of this element should be replaced within a model group
554     */
555    public void setModelGroupAlwaysReplace(boolean alwaysReplace) {
556
557        m_isModelGroupAlwaysReplace = alwaysReplace;
558    }
559
560    /**
561     * Sets the model group id.<p>
562     *
563     * @param modelGroupId <code>true</code> if the element is a model group
564     */
565    public void setModelGroupId(CmsUUID modelGroupId) {
566
567        m_modelGroupId = modelGroupId;
568    }
569
570    /**
571     * Sets the 'new' flag.<p>
572     *
573     * @param isNew <code>true</code> on a new element
574     */
575    public void setNew(boolean isNew) {
576
577        m_new = isNew;
578    }
579
580    /**
581     * Disables the new editor for this element.<p>
582     *
583     * @param disabled if true, the new editor will be disabled for this element
584     */
585    public void setNewEditorDisabled(boolean disabled) {
586
587        m_newEditorDisabled = disabled;
588    }
589
590    /**
591     * Sets the permission info.<p>
592     *
593     * @param permissionInfo the permission info to set
594     */
595    public void setPermissionInfo(CmsPermissionInfo permissionInfo) {
596
597        m_permissionInfo = permissionInfo;
598    }
599
600    /**
601     * Sets if the given resource is released and not expired.<p>
602     *
603     * @param releasedAndNotExpired <code>true</code> if the given resource is released and not expired
604     */
605    public void setReleasedAndNotExpired(boolean releasedAndNotExpired) {
606
607        m_releasedAndNotExpired = releasedAndNotExpired;
608    }
609
610    /**
611     * Sets the element resource type.<p>
612     *
613     * @param resourceType the element resource type
614     */
615    public void setResourceType(String resourceType) {
616
617        m_resourceType = resourceType;
618    }
619
620    /**
621     * Sets the site path.<p>
622     *
623     * @param sitePath the site path to set
624     */
625    public void setSitePath(String sitePath) {
626
627        m_sitePath = sitePath;
628    }
629
630    /**
631     * Sets the sub title.<p>
632     *
633     * @param subTitle the sub title
634     */
635    public void setSubTitle(String subTitle) {
636
637        m_subTitle = subTitle;
638    }
639
640    /**
641     * Sets the title.<p>
642     *
643     * @param title the title
644     */
645    public void setTitle(String title) {
646
647        m_title = title;
648    }
649
650    /**
651     * Sets the was model group flag.<p>
652     *
653     * @param wasModelGroup the was model group flag to set
654     */
655    public void setWasModelGroup(boolean wasModelGroup) {
656
657        m_wasModelGroup = wasModelGroup;
658    }
659}