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.ui.sitemap;
029
030import org.opencms.ui.CmsVaadinUtils;
031import org.opencms.ui.components.OpenCmsTheme;
032
033import com.vaadin.ui.Component;
034import com.vaadin.ui.ComponentContainer;
035import com.vaadin.ui.CssLayout;
036import com.vaadin.v7.ui.Label;
037
038/**
039 * Widget displaying a sitemap tree node, with an openable area for its children.<p>
040 */
041public class CmsSitemapTreeNode extends CssLayout {
042
043    /** The serial version id. */
044    private static final long serialVersionUID = 1L;
045
046    /** The container for the children. */
047    protected ComponentContainer m_children;
048
049    /** The container for the content widget (usually a resource box). */
050    protected CssLayout m_contentContainer;
051
052    /** True if the child area is opened. */
053    private boolean m_isOpen;
054
055    /** The button to open/close the llst of children. */
056    private CmsSitemapTreeNodeOpener m_opener;
057
058    /** Creates a new instance. */
059    public CmsSitemapTreeNode() {
060
061        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
062        setOpen(false);
063        setContent(new Label("[content not set]"));
064    }
065
066    /**
067     * Gets the container for the children.<p>
068     *
069     * @return the container for the children
070     */
071    public ComponentContainer getChildren() {
072
073        return m_children;
074    }
075
076    /**
077     * Gets the opener button.<p>
078     *
079     * @return the opener button
080     */
081    public CmsSitemapTreeNodeOpener getOpener() {
082
083        return m_opener;
084    }
085
086    /**
087     * Returns true if the child list is opened.<p>
088     *
089     * @return true if the child list is opened
090     */
091    public boolean isOpen() {
092
093        return m_isOpen;
094    }
095
096    /**
097     * Sets additional styles.<p>
098     *
099     * Useful for declarative layouts.
100     *
101     * TODO: check if this is actually used anywhere
102     *
103     * @param additionalStyles the additional styles to set
104     */
105    public void setAdditionalStyles(String additionalStyles) {
106
107        addStyleName(additionalStyles);
108    }
109
110    /**
111     * Sets the content widget.<p>
112     *
113     * @param content the content widget
114     */
115    public void setContent(Component content) {
116
117        m_contentContainer.removeAllComponents();
118        m_contentContainer.addComponent(content);
119    }
120
121    /**
122     * Opens / closes the list of children.<p>
123     *
124     * @param isOpen true if the children should be opened, false if they should be closed
125     */
126    public void setOpen(boolean isOpen) {
127
128        m_opener.setStyleOpen(isOpen);
129        m_children.setVisible(isOpen);
130        m_isOpen = isOpen;
131    }
132
133    /**
134     * Shows or hides the opener button.<p>
135     *
136     * @param visible true if the opener should be shown, else false
137     */
138    public void setOpenerVisible(boolean visible) {
139
140        if (visible) {
141            m_opener.removeStyleName(OpenCmsTheme.BUTTON_INVISIBLE);
142        } else {
143            m_opener.addStyleName(OpenCmsTheme.BUTTON_INVISIBLE);
144        }
145    }
146
147}