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.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        CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null);
061        setOpen(false);
062        setContent(new Label("[content not set]"));
063    }
064
065    /**
066     * Gets the container for the children.<p>
067     *
068     * @return the container for the children
069     */
070    public ComponentContainer getChildren() {
071
072        return m_children;
073    }
074
075    /**
076     * Gets the opener button.<p>
077     *
078     * @return the opener button
079     */
080    public CmsSitemapTreeNodeOpener getOpener() {
081
082        return m_opener;
083    }
084
085    /**
086     * Returns true if the child list is opened.<p>
087     *
088     * @return true if the child list is opened
089     */
090    public boolean isOpen() {
091
092        return m_isOpen;
093    }
094
095    /**
096     * Sets additional styles.<p>
097     *
098     * Useful for declarative layouts.
099     *
100     * TODO: check if this is actually used anywhere
101     *
102     * @param additionalStyles the additional styles to set
103     */
104    public void setAdditionalStyles(String additionalStyles) {
105
106        addStyleName(additionalStyles);
107    }
108
109    /**
110     * Sets the content widget.<p>
111     *
112     * @param content the content widget
113     */
114    public void setContent(Component content) {
115
116        m_contentContainer.removeAllComponents();
117        m_contentContainer.addComponent(content);
118    }
119
120    /**
121     * Opens / closes the list of children.<p<
122     *
123     * @param isOpen true if the children should be opened, false if they should be closed
124     */
125    public void setOpen(boolean isOpen) {
126
127        m_opener.setStyleOpen(isOpen);
128        m_children.setVisible(isOpen);
129        m_isOpen = isOpen;
130    }
131
132    /**
133     * Shows or hides the opener button.<p>
134     *
135     * @param visible true if the opener should be shown, else false
136     */
137    public void setOpenerVisible(boolean visible) {
138
139        if (visible) {
140            m_opener.removeStyleName(OpenCmsTheme.BUTTON_INVISIBLE);
141        } else {
142            m_opener.addStyleName(OpenCmsTheme.BUTTON_INVISIBLE);
143        }
144    }
145
146}