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 java.util.ArrayList;
031import java.util.List;
032
033/**
034 * Gallery tree entry class. To organize gallery folders as a tree.<p>
035 *
036 * @since 8.0.1
037 */
038public class CmsGalleryTreeEntry extends CmsGalleryFolderBean {
039
040    /** List of child entries. */
041    private List<CmsGalleryTreeEntry> m_children;
042
043    /** The parent entry. */
044    private CmsGalleryTreeEntry m_parent;
045
046    /**
047     * Constructor.<p>
048     * Copy the fields of the given master.<p>
049     *
050     * @param master master to copy
051     */
052    public CmsGalleryTreeEntry(CmsGalleryFolderBean master) {
053
054        setContentTypes(master.getContentTypes());
055        setEditable(master.isEditable());
056        setOptimizable(master.isOptimizable());
057        setPath(master.getPath());
058        setId(master.getId());
059        setGroup(master.getGroup());
060        setTitle(master.getTitle());
061        setResourceType(master.getType());
062        setBigIconClasses(master.getBigIconClasses());
063    }
064
065    /**
066     * Adds a new child entry.<p>
067     *
068     * @param child the child entry to add
069     */
070    public void addChild(CmsGalleryTreeEntry child) {
071
072        if (m_children == null) {
073            m_children = new ArrayList<CmsGalleryTreeEntry>();
074        }
075        m_children.add(child);
076        child.setParent(this);
077    }
078
079    /**
080     * Returns the list of child entries.<p>
081     *
082     * @return the list of child entries
083     */
084    public List<CmsGalleryTreeEntry> getChildren() {
085
086        return m_children;
087    }
088
089    /**
090     * Returns the parent entry or <code>null</code> if there is none.<p>
091     *
092     * @return the parent entry
093     */
094    public CmsGalleryTreeEntry getParent() {
095
096        return m_parent;
097    }
098
099    /**
100     * Sets the child entry list.<p>
101     *
102     * @param children the list of child entries
103     */
104    public void setChildren(List<CmsGalleryTreeEntry> children) {
105
106        m_children = children;
107        for (CmsGalleryTreeEntry child : m_children) {
108            child.setParent(this);
109        }
110    }
111
112    /**
113     * Sets the parent entry.<p>
114     *
115     * @param parent the parent entry
116     */
117    protected void setParent(CmsGalleryTreeEntry parent) {
118
119        m_parent = parent;
120    }
121}