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