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.galleries.shared;
029
030import org.opencms.gwt.shared.I_CmsHasIconClasses;
031import org.opencms.util.CmsStringUtil;
032import org.opencms.util.CmsUUID;
033
034import java.util.ArrayList;
035import java.util.List;
036
037import com.google.gwt.user.client.rpc.IsSerializable;
038
039/**
040 * Represents a single VFS resource entry for use by the VFS tab of the galleries.<p>
041 */
042public class CmsVfsEntryBean implements IsSerializable, I_CmsGalleryTreeEntry<CmsVfsEntryBean>, I_CmsHasIconClasses {
043
044    /** Flag to indicate if the user has write permissions to the folder. */
045    private boolean m_editable;
046
047    /** The small folder icon classes. */
048    private String m_iconClasses;
049
050    /** Flag indicating whether this is entry should be displayed at the top level of the tree. */
051    private boolean m_isRoot;
052
053    /** True if this is a filter search match. */
054    private boolean m_isSearchMatch;
055
056    /** The list of children. */
057    private List<CmsVfsEntryBean> m_preloadedChildren;
058
059    /** The root path of the VFS entry. */
060    private String m_rootPath;
061
062    /** The site root of the entry. */
063    private String m_siteRoot;
064
065    /** The structure id. */
066    private CmsUUID m_structureId;
067
068    /** The folder title. */
069    private String m_title;
070
071    /**
072     * Creates a new VFS entry bean.<p>
073     *
074     * @param rootPath the root path
075     * @param structureId the structure id
076     * @param title the folder title
077     * @param iconClasses the resource icon classes
078     * @param isRoot flag indicating whether this is entry should be displayed at the top level of the tree
079     * @param editable <code>true</code> if the user has write permissions to the folder
080     * @param preloadedChildren the preloaded child nodes
081     * @param isMatch true if this entry bean is a search match for the filter string the user entered
082     */
083    public CmsVfsEntryBean(
084        String rootPath,
085        CmsUUID structureId,
086        String title,
087        String iconClasses,
088        boolean isRoot,
089        boolean editable,
090        List<CmsVfsEntryBean> preloadedChildren,
091        boolean isMatch) {
092
093        m_rootPath = rootPath;
094
095        m_structureId = structureId;
096        m_isRoot = isRoot;
097        m_editable = editable;
098        m_title = title;
099        m_iconClasses = iconClasses;
100        m_isSearchMatch = isMatch;
101        m_preloadedChildren = preloadedChildren;
102    }
103
104    /**
105     * Hidden default constructor.<p>
106     */
107    protected CmsVfsEntryBean() {
108
109        // do nothing
110    }
111
112    /**
113     * @see org.opencms.ade.galleries.shared.I_CmsGalleryTreeEntry#addChild(java.lang.Object)
114     */
115    public void addChild(CmsVfsEntryBean child) {
116
117        if (m_preloadedChildren == null) {
118            m_preloadedChildren = new ArrayList<CmsVfsEntryBean>();
119        }
120        m_preloadedChildren.add(child);
121    }
122
123    /**
124     * @see org.opencms.gwt.shared.I_CmsHasIconClasses#getBigIconClasses()
125     */
126    public String getBigIconClasses() {
127
128        // not needed
129        return null;
130    }
131
132    /**
133     * @see org.opencms.ade.galleries.shared.I_CmsGalleryTreeEntry#getChildren()
134     */
135    public List<CmsVfsEntryBean> getChildren() {
136
137        return m_preloadedChildren;
138    }
139
140    /**
141     * Gets the name which should be displayed in the widget representing this VFS entry.<p>
142     *
143     * @return the name to display
144     */
145    public String getDisplayName() {
146
147        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_title)) {
148            return m_title;
149        }
150        if (m_isRoot) {
151            return getRootPath();
152        } else {
153            String fixedPath = getRootPath().replaceFirst("/$", "");
154            int lastSlash = fixedPath.lastIndexOf('/');
155            if (lastSlash == -1) {
156                return fixedPath;
157            }
158            return fixedPath.substring(lastSlash + 1);
159        }
160    }
161
162    /**
163     * Gets the root path of the VFS entry.<p>
164     *
165     * @return the root path of the VFS entry
166     */
167    public String getRootPath() {
168
169        return m_rootPath;
170    }
171
172    /**
173     * Gets the site root of this tree entry.<p>
174     *
175     * @return the site root of this entry
176     */
177    public String getSiteRoot() {
178
179        return m_siteRoot;
180    }
181
182    /**
183     * @see org.opencms.gwt.shared.I_CmsHasIconClasses#getSmallIconClasses()
184     */
185    public String getSmallIconClasses() {
186
187        return m_iconClasses;
188    }
189
190    /**
191     * Returns the structure id.<p>
192     *
193     * @return the structure id
194     */
195    public CmsUUID getStructureId() {
196
197        return m_structureId;
198    }
199
200    /**
201     * Returns the editable flag. Indicate if the user has write permissions to the folder.<p>
202     *
203     * @return the editable flag
204     */
205    public boolean isEditable() {
206
207        return m_editable;
208    }
209
210    /**
211     * Returns true if this entry is a top-level entry.<p>
212     *
213     * @return true if this is a top-level entry
214     */
215    public boolean isRoot() {
216
217        return m_isRoot;
218    }
219
220    /**
221     * Returns true if this entry bean is a search match.<p>
222     *
223     * @return true if this is a search match
224     */
225    public boolean isSearchMatch() {
226
227        return m_isSearchMatch;
228    }
229
230    /**
231     * Sets the list of children.<p>
232     *
233     * @param children the list of children
234     */
235    public void setChildren(List<CmsVfsEntryBean> children) {
236
237        m_preloadedChildren = children;
238    }
239
240    /**
241     * Sets if the user has write permissions to the folder.<p>
242     *
243     * @param editable <code>true</code> if the user has write permissions to the folder
244     */
245    public void setEditable(boolean editable) {
246
247        m_editable = editable;
248    }
249
250    /**
251     * Sets the site root of this tree entry.<p>
252     *
253     * @param siteRoot the site root of this tree entry
254     */
255    public void setSiteRoot(String siteRoot) {
256
257        m_siteRoot = siteRoot;
258    }
259
260}