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.relations.CmsCategory;
031import org.opencms.util.CmsStringUtil;
032
033import java.util.List;
034
035import com.google.common.collect.Lists;
036
037/**
038 * Recursive category tree entry.<p>
039 *
040 * @since 8.0.0
041 */
042public class CmsCategoryTreeEntry extends CmsCategoryBean {
043
044    /** The children. */
045    private List<CmsCategoryTreeEntry> m_children = Lists.newArrayList();
046
047    /** 'Forced visible' state. */
048    private Boolean m_forcedVisible;
049
050    /** Category is among the 'recently used' ones for the current user.  */
051    private boolean m_used;
052
053    /**
054     * Clone constructor.<p>
055     *
056     * @param category the category to clone
057     */
058    public CmsCategoryTreeEntry(CmsCategory category) {
059
060        super(category);
061    }
062
063    /**
064     * Constructor for serialization.<p>
065     */
066    protected CmsCategoryTreeEntry() {
067
068        // do nothing
069    }
070
071    /**
072     * Adds a child entry.<p>
073     *
074     * @param child the child to add
075     */
076    public void addChild(CmsCategoryTreeEntry child) {
077
078        m_children.add(child);
079    }
080
081    /**
082     * Returns the children.<p>
083     *
084     * @return the children
085     */
086    public List<CmsCategoryTreeEntry> getChildren() {
087
088        return m_children;
089    }
090
091    /**
092     * Gets the 'forced visible' status.
093     *
094     * <p>A category tree entry with this status set to 'true' should be shown even if it is marked as hidden.
095     *
096     * @return the 'forced visible' status
097     */
098    public Boolean getForcedVisible() {
099
100        return m_forcedVisible;
101    }
102
103    /**
104     * Gets the title of the category, or the name if the title is not set.<p>
105     *
106     * @return the title or name
107     */
108    public Object getTitleOrName() {
109
110        String result = getTitle();
111        if (CmsStringUtil.isEmptyOrWhitespaceOnly(result)) {
112            result = getPath();
113        }
114        return result;
115    }
116
117    /**
118     * Checks if the category is among the 'recently used' ones for the current user.
119     *
120     * @return true if the category was recently used
121     */
122    public boolean isUsed() {
123
124        return m_used;
125    }
126
127    /**
128     * Sets the children.<p>
129     *
130     * @param children the children to set
131     */
132    public void setChildren(List<CmsCategoryTreeEntry> children) {
133
134        m_children = children;
135    }
136
137    /**
138     * Sets the 'forced visible' status.
139     *
140     * @param visibility the new value
141     */
142    public void setForcedVisible(Boolean visibility) {
143
144        m_forcedVisible = visibility;
145    }
146
147    /**
148     * Sets the 'recently used' state.
149     *
150     * @param used the new 'recently used' state
151     */
152    public void setUsed(boolean used) {
153
154        m_used = used;
155    }
156}