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 java.util.Arrays;
031import java.util.HashMap;
032import java.util.List;
033import java.util.Map;
034import java.util.Set;
035
036import com.google.common.collect.Sets;
037import com.google.gwt.user.client.rpc.IsSerializable;
038
039/**
040 * Container bean.<p>
041 *
042 * @since 8.0.0
043 */
044public class CmsContainer implements IsSerializable {
045
046    /** Flag indicating the container is displayed in detail view only. */
047    private boolean m_detailOnly;
048
049    /** Flag indicating this container is used for detail views. */
050    private boolean m_detailView;
051
052    /** Flag indicating the container is editable by the current user. */
053    private boolean m_editable;
054
055    /** List of the contained elements. */
056    private List<CmsContainerElement> m_elements;
057
058    /** The content to display in case the container is empty. */
059    private String m_emptyContainerContent;
060
061    /** True if this is a detail view container. */
062    private boolean m_isDetailViewContainer;
063
064    /**
065     * Indicates whether this container not nested,
066     * or in case of a detail only container page the starting point of a detail only container hierarchy.
067     **/
068    private boolean m_isRootContainer;
069
070    /** The maximum number of elements. */
071    private int m_maxElements;
072
073    /** The container name. */
074    private String m_name;
075
076    /** The parent container name. */
077    private String m_parentContainerName;
078
079    /** The parent instance id. */
080    private String m_parentInstanceId;
081
082    /** Presets for settings. */
083    private Map<String, String> m_settingPresets = new HashMap<String, String>();
084
085    /** The container type. */
086    private String m_type;
087
088    /** The width of the container. */
089    private int m_width;
090
091    /**
092     * Constructor.<p>
093     *
094     * @param name the container name, also used as id within a container-page
095     * @param type the container type
096     * @param emptyContainerContent content to display in case the container is empty
097     * @param width the width of the container
098     * @param maxElements the maximum number of elements displayed by this container
099     * @param isDetailViewContainer flag indicating this is a detail view container
100     * @param detailView flag indicating this container is currently used for a detail view
101     * @param editable flag indicating the container is editable by the current user
102     * @param elements the container elements id's
103     * @param parentContainerName the parent container name
104     * @param parentInstanceId the parent instance id
105     * @param settingPresets the presets for container element settings
106     */
107    public CmsContainer(
108        String name,
109        String type,
110        String emptyContainerContent,
111        int width,
112        int maxElements,
113        boolean isDetailViewContainer,
114        boolean detailView,
115        boolean editable,
116        List<CmsContainerElement> elements,
117        String parentContainerName,
118        String parentInstanceId,
119        Map<String, String> settingPresets) {
120
121        m_elements = elements;
122        m_name = name;
123        m_type = type;
124        m_emptyContainerContent = emptyContainerContent;
125        m_maxElements = maxElements;
126        m_width = width;
127        m_isDetailViewContainer = isDetailViewContainer;
128        m_detailView = detailView;
129        m_editable = editable;
130        m_parentContainerName = parentContainerName;
131        m_parentInstanceId = parentInstanceId;
132        m_settingPresets = settingPresets != null ? settingPresets : new HashMap<String, String>();
133    }
134
135    /**
136     * Hidden default constructor (for GWT serialization).<p>
137     */
138    protected CmsContainer() {
139
140        // do nothing
141    }
142
143    /**
144     * Splits the type attribute of a container into individual types.<p>
145     *
146     * @param containerTypeSpec the container type attribute
147     *
148     * @return the entries of the type attribute
149     */
150    public static Set<String> splitType(String containerTypeSpec) {
151
152        return Sets.newHashSet(Arrays.asList(containerTypeSpec.trim().split(" *, *")));
153
154    }
155
156    /**
157     * Returns the list of the contained elements id's.<p>
158     *
159     * @return the list of the contained elements id's
160     */
161    public List<CmsContainerElement> getElements() {
162
163        return m_elements;
164    }
165
166    /**
167     * Returns the content to display in case the container is empty.<p>
168     *
169     * @return the content to display in case the container is empty
170     */
171    public String getEmptyContainerContent() {
172
173        return m_emptyContainerContent;
174    }
175
176    /**
177     * Returns the maximum number of elements allowed in this container.<p>
178     *
179     * @return the maximum number of elements allowed in this container
180     */
181    public int getMaxElements() {
182
183        return m_maxElements;
184    }
185
186    /**
187     * Returns the container name, also used as HTML-id for the container DOM-element. Has to be unique within the template.<p>
188     *
189     * @return the container name
190     */
191    public String getName() {
192
193        return m_name;
194    }
195
196    /**
197     * Returns the parent container name.<p>
198     *
199     * @return the parent container name
200     */
201    public String getParentContainerName() {
202
203        return m_parentContainerName;
204    }
205
206    /**
207     * Returns the parent instance id.<p>
208     *
209     * @return the parent instance id
210     */
211    public String getParentInstanceId() {
212
213        return m_parentInstanceId;
214    }
215
216    /**
217     * Gets the setting presets.
218     *
219     * @return the setting presets
220     */
221    public Map<String, String> getSettingPresets() {
222
223        return m_settingPresets;
224    }
225
226    /**
227     * Returns the container type. Used to determine the formatter used to render the contained elements.<p>
228     *
229     * @return the container type
230     */
231    public String getType() {
232
233        return m_type;
234    }
235
236    /**
237     * Returns the container width.<p>
238     *
239     * @return the container width
240     */
241    public int getWidth() {
242
243        return m_width;
244    }
245
246    /**
247     * Returns <code>true</code> if the container is displayed in detail view only.<p>
248     *
249     * @return <code>true</code> if the container is displayed in detail view only
250     */
251    public boolean isDetailOnly() {
252
253        return m_detailOnly;
254    }
255
256    /**
257     * Returns if this container is used for detail views.<p>
258     *
259     * @return <code>true</code> if this container is used for detail views
260     */
261    public boolean isDetailView() {
262
263        return m_detailView;
264    }
265
266    /**
267     * Checks if this is a detail view container.
268     *
269     * @return true if this is a detail view container
270     */
271    public boolean isDetailViewContainer() {
272
273        return m_isDetailViewContainer;
274    }
275
276    /**
277     * Returns if the container is editable by the current user.<p>
278     *
279     * @return <code>true</code> if the container is editable by the current user
280     */
281    public boolean isEditable() {
282
283        return m_editable;
284    }
285
286    /**
287     * Returns if this container not nested,
288     * or in case of a detail only container page the starting point of a detail only container hierarchy.<p>
289     *
290     * @return <code>true</code> if this container not nested
291     */
292    public boolean isRootContainer() {
293
294        return m_isRootContainer;
295    }
296
297    /**
298     * Returns if this is a sub container.<p>
299     *
300     * @return <code>true</code> this is a sub container
301     */
302    public boolean isSubContainer() {
303
304        return m_parentContainerName != null;
305    }
306
307    /**
308     * Sets the detail only flag.<p>
309     *
310     * @param detailOnly <code>true</code> if the container is displayed in detail view only
311     */
312    public void setDetailOnly(boolean detailOnly) {
313
314        m_detailOnly = detailOnly;
315    }
316
317    /**
318     * Sets the elements contained in this container.<p>
319     *
320     * @param elements the elements
321     */
322    public void setElements(List<CmsContainerElement> elements) {
323
324        m_elements = elements;
325
326    }
327
328    /**
329     * Sets the maxElements.<p>
330     *
331     * @param maxElements the maxElements to set
332     */
333    public void setMaxElements(int maxElements) {
334
335        m_maxElements = maxElements;
336    }
337
338    /**
339     * Sets the name.<p>
340     *
341     * @param name the name to set
342     */
343    public void setName(String name) {
344
345        m_name = name;
346    }
347
348    /**
349     * Sets the if this container not nested,
350     * or in case of a detail only container page the starting point of a detail only container hierarchy.<p>
351     *
352     * @param isRootContainer <code>true</code> if this container not nested
353     */
354    public void setRootContainer(boolean isRootContainer) {
355
356        m_isRootContainer = isRootContainer;
357    }
358
359    /**
360     * Sets the type.<p>
361     *
362     * @param type the type to set
363     */
364    public void setType(String type) {
365
366        m_type = type;
367    }
368
369    /**
370     * @see java.lang.Object#toString()
371     */
372    @Override
373    public String toString() {
374
375        return "[Container name='"
376            + m_name
377            + "' type='"
378            + m_type
379            + "' numElements='"
380            + (m_elements == null ? 0 : m_elements.size())
381            + "']";
382    }
383
384}