001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.gwt.shared;
029
030import org.opencms.db.CmsResourceState;
031import org.opencms.gwt.shared.sort.I_CmsHasTitle;
032import org.opencms.gwt.shared.sort.I_CmsHasType;
033
034import java.util.ArrayList;
035import java.util.List;
036
037/**
038 * A bean holding all info to be displayed in <code>CmsListItemWidget</code>s.<p>
039 *
040 * @since 8.0.0
041 */
042public class CmsListInfoBean extends CmsIconBean implements I_CmsHasTitle, I_CmsHasType {
043
044    /** Lock icons. */
045    public enum LockIcon {
046        /** Closed lock. */
047        CLOSED,
048        /** No lock. */
049        NONE,
050        /** Open lock. */
051        OPEN,
052        /** Shared closed lock. */
053        SHARED_CLOSED,
054        /** Shared open lock. */
055        SHARED_OPEN
056    }
057
058    /**
059     * Enum for the type of page icon which should be displayed.<p>
060     */
061    public enum StateIcon {
062        /** copy page icon. */
063        copy,
064        /** export page icon. */
065        export,
066        /** secure page icon. */
067        secure,
068        /** standard page icon. */
069        standard
070    }
071
072    /** CSS class for multi-line additional info's. */
073    public static final String CSS_CLASS_MULTI_LINE = "multiLineLabel";
074
075    /** The additional info. */
076    private List<CmsAdditionalInfoBean> m_additionalInfo;
077
078    /** Flag which indicates whether this was generated for a folder. */
079    private Boolean m_isFolder;
080
081    /** The lock icon. */
082    private LockIcon m_lockIcon;
083
084    /** The lock icon title. */
085    private String m_lockIconTitle;
086
087    /** Flag to control whether a resource state of 'changed' should be visualized with an overlay icon. */
088    private boolean m_markChangedState = true;
089
090    /** The resource state. */
091    private CmsResourceState m_resourceState;
092
093    /** The resource type name of the resource. */
094    private String m_resourceType;
095
096    /** The state icon information: for the type of state icon which should be displayed. The state icon indicates if a resource is exported, secure etc. */
097    private StateIcon m_stateIcon;
098
099    /** The sub-title. */
100    private String m_subTitle;
101
102    /** The title. */
103    private String m_title;
104
105    /**
106     * Default constructor.<p>
107     */
108    public CmsListInfoBean() {
109
110        // empty
111    }
112
113    /**
114     * Constructor.<p>
115     *
116     * @param title the title
117     * @param subtitle the subtitle
118     * @param additionalInfo the additional info
119     */
120    public CmsListInfoBean(String title, String subtitle, List<CmsAdditionalInfoBean> additionalInfo) {
121
122        m_title = title;
123        setSubTitle(subtitle);
124        m_additionalInfo = additionalInfo;
125    }
126
127    /**
128     * Sets a new additional info.<p>
129     *
130     * @param name the additional info name
131     * @param value the additional info value
132     */
133    public void addAdditionalInfo(String name, String value) {
134
135        getAdditionalInfo().add(new CmsAdditionalInfoBean(name, value, null));
136    }
137
138    /**
139     * Sets a new additional info.<p>
140     *
141     * @param name the additional info name
142     * @param value the additional info value
143     * @param style the CSS style to apply to the info
144     */
145    public void addAdditionalInfo(String name, String value, String style) {
146
147        getAdditionalInfo().add(new CmsAdditionalInfoBean(name, value, style));
148    }
149
150    /**
151     * Returns the additional info.<p>
152     *
153     * @return the additional info
154     */
155    public List<CmsAdditionalInfoBean> getAdditionalInfo() {
156
157        if (m_additionalInfo == null) {
158            m_additionalInfo = new ArrayList<CmsAdditionalInfoBean>();
159        }
160        return m_additionalInfo;
161    }
162
163    /**
164     * Returns a flag which indicates whether this info bean was generated for a folder.<p>
165     *
166     * This may not be set (i.e. null).
167     *
168     * @return a Boolean indicating whether this bean was generated for a folder
169     */
170    public Boolean getIsFolder() {
171
172        return m_isFolder;
173    }
174
175    /**
176     * Returns the lock icon.<p>
177     *
178     * @return the lockIcon
179     */
180    public LockIcon getLockIcon() {
181
182        return m_lockIcon;
183    }
184
185    /**
186     * Returns the lock icon title.<p>
187     *
188     * @return the lock icon title
189     */
190    public String getLockIconTitle() {
191
192        return m_lockIconTitle;
193    }
194
195    /**
196     * Returns the resourceState.<p>
197     *
198     * @return the resourceState
199     */
200    public CmsResourceState getResourceState() {
201
202        return m_resourceState;
203    }
204
205    /**
206     * Returns the resource type name.<p>
207     *
208     * @return the resource type name
209     */
210    public String getResourceType() {
211
212        return m_resourceType;
213    }
214
215    /**
216     * Returns the state icon.<p>
217     *
218     * The state icon indicates if a resource is exported, secure etc.<p>
219     *
220     * @return the state Icon
221     */
222    public StateIcon getStateIcon() {
223
224        return m_stateIcon;
225    }
226
227    /**
228     * Returns the sub-title.<p>
229     *
230     * @return the sub-title
231     */
232    public String getSubTitle() {
233
234        return m_subTitle;
235    }
236
237    /**
238     * Returns the title.<p>
239     *
240     * @return the title
241     */
242    public String getTitle() {
243
244        return m_title;
245    }
246
247    /**
248     * @see org.opencms.gwt.shared.sort.I_CmsHasType#getType()
249     */
250    public String getType() {
251
252        return getResourceType();
253    }
254
255    /**
256     * Returns if the bean has additional info elements.<p>
257     *
258     * @return <code>true</code> if the bean has additional info elements
259     */
260    public boolean hasAdditionalInfo() {
261
262        return (m_additionalInfo != null) && (m_additionalInfo.size() > 0);
263    }
264
265    /**
266     * Returns true if the 'changed' resource state should be marked by an icon.<p>
267     *
268     * @return true if the 'changed' resource state should be marked by an icon.<p>
269     */
270    public boolean isMarkChangedState() {
271
272        return m_markChangedState;
273    }
274
275    /**
276     * Sets the additional info.<p>
277     *
278     * @param additionalInfo the additional info to set
279     */
280    public void setAdditionalInfo(List<CmsAdditionalInfoBean> additionalInfo) {
281
282        m_additionalInfo = additionalInfo;
283    }
284
285    /**
286     * @see org.opencms.gwt.shared.CmsIconBean#setBigIconClasses(java.lang.String)
287     */
288    @Override
289    public CmsListInfoBean setBigIconClasses(String bigIconClasses) {
290
291        super.setBigIconClasses(bigIconClasses);
292        return this;
293    }
294
295    /**
296     * Sets thE 'isFolder' flag.<p>
297     *
298     * @param isFolder the new value
299     */
300    public void setIsFolder(Boolean isFolder) {
301
302        m_isFolder = isFolder;
303    }
304
305    /**
306     * Sets the lock icon.<p>
307     *
308     * @param lockIcon the lock icon to set
309     */
310    public void setLockIcon(LockIcon lockIcon) {
311
312        m_lockIcon = lockIcon;
313    }
314
315    /**
316     * Sets the lock icon title.<p>
317     *
318     * @param lockIconTitle the lock icon title to set
319     */
320    public void setLockIconTitle(String lockIconTitle) {
321
322        m_lockIconTitle = lockIconTitle;
323    }
324
325    /**
326     * Enables or disables the display of the 'changed' icon for the 'changed' resource state.<p>
327     *
328     * @param markChanged true if the 'changed' state should be displayed
329     */
330    public void setMarkChangedState(boolean markChanged) {
331
332        m_markChangedState = markChanged;
333    }
334
335    /**
336     * Sets the resourceState.<p>
337     *
338     * @param resourceState the resourceState to set
339     */
340    public void setResourceState(CmsResourceState resourceState) {
341
342        m_resourceState = resourceState;
343    }
344
345    /**
346     * Sets the resource type name.<p>
347     *
348     * @param resourceType the resource type name to set
349     */
350    public void setResourceType(String resourceType) {
351
352        m_resourceType = resourceType;
353    }
354
355    /**
356     * Sets the state icon.<p>
357     *
358     * The state icon indicates if a resource is exported, secure etc.<p>
359     *
360     * @param stateIcon the state icon to set
361     */
362    public void setStateIcon(StateIcon stateIcon) {
363
364        m_stateIcon = stateIcon;
365    }
366
367    /**
368     * Sets the sub-title.<p>
369     *
370     * @param subTitle the sub-title to set
371     */
372    public void setSubTitle(String subTitle) {
373
374        m_subTitle = subTitle;
375    }
376
377    /**
378     * Sets the title.<p>
379     *
380     * @param title the title to set
381     */
382    public void setTitle(String title) {
383
384        m_title = title;
385    }
386
387}