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.components;
029
030import org.opencms.ui.CmsVaadinUtils;
031import org.opencms.ui.apps.A_CmsWorkplaceApp.NavEntry;
032import org.opencms.ui.apps.CmsDefaultAppButtonProvider;
033
034import com.vaadin.ui.Button;
035import com.vaadin.ui.Component;
036import com.vaadin.ui.CssLayout;
037import com.vaadin.ui.Panel;
038
039/**
040 * The standard workplace tool layout.<p>
041 */
042public class CmsToolLayout extends CssLayout {
043
044    /** The serial version id. */
045    private static final long serialVersionUID = 2195018534066531670L;
046
047    /** The main panel. */
048    private Panel m_main;
049
050    /** The sub navigation. */
051    private CssLayout m_subNav;
052
053    /**
054     * Constructor.<p>
055     */
056    public CmsToolLayout() {
057        CmsVaadinUtils.readAndLocalizeDesign(this, null, null);
058    }
059
060    /**
061     * Adds a sub navigation entry.<p>
062     *
063     * @param navEntry the entry to add
064     *
065     * @return the entry button component
066     */
067    public Button addSubNavEntry(final NavEntry navEntry) {
068
069        Button button = CmsDefaultAppButtonProvider.createIconButton(
070            navEntry.getName(),
071            navEntry.getDescription(),
072            navEntry.getIcon());
073        m_subNav.addComponent(button);
074        return button;
075    }
076
077    /**
078     * Clears the sub navigation.<p>
079     */
080    public void clearSubNav() {
081
082        m_subNav.removeAllComponents();
083    }
084
085    /**
086     * Sets the main component.<p>
087     *
088     * @param component the main component
089     */
090    public void setMainContent(Component component) {
091
092        component.addStyleName("borderless");
093        m_main.setContent(component);
094    }
095
096    /**
097     * Sets the height of the main panel to 100% to allow for scrollable children.<p>
098     * If not set, the height of the main panel will adjust to it's content.<p>
099     *
100     * @param full <code>true</code> to set the height to 100%
101     */
102    public void setMainHeightFull(boolean full) {
103
104        if (full) {
105            m_main.setHeight("100%");
106        } else {
107            m_main.setHeightUndefined();
108        }
109    }
110
111    /**
112     * Shows or hides the sub navigation.<p>
113     *
114     * @param visible <code>true</code> to show the sub navigation
115     */
116    public void setSubNavVisible(boolean visible) {
117
118        m_subNav.setVisible(visible);
119        if (visible) {
120            removeStyleName("o-tools-subnav-hidden");
121        } else {
122            addStyleName("o-tools-subnav-hidden");
123        }
124    }
125}