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.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
058        CmsVaadinUtils.readAndLocalizeDesign(this, null, null);
059    }
060
061    /**
062     * Adds a sub navigation entry.<p>
063     *
064     * @param navEntry the entry to add
065     *
066     * @return the entry button component
067     */
068    public Button addSubNavEntry(final NavEntry navEntry) {
069
070        Button button = CmsDefaultAppButtonProvider.createIconButton(
071            navEntry.getName(),
072            navEntry.getDescription(),
073            navEntry.getIcon());
074        m_subNav.addComponent(button);
075        return button;
076    }
077
078    /**
079     * Clears the sub navigation.<p>
080     */
081    public void clearSubNav() {
082
083        m_subNav.removeAllComponents();
084    }
085
086    /**
087     * Sets the main component.<p>
088     *
089     * @param component the main component
090     */
091    public void setMainContent(Component component) {
092
093        component.addStyleName("borderless");
094        m_main.setContent(component);
095    }
096
097    /**
098     * Sets the height of the main panel to 100% to allow for scrollable children.<p>
099     * If not set, the height of the main panel will adjust to it's content.<p>
100     *
101     * @param full <code>true</code> to set the height to 100%
102     */
103    public void setMainHeightFull(boolean full) {
104
105        if (full) {
106            m_main.setHeight("100%");
107        } else {
108            m_main.setHeightUndefined();
109        }
110    }
111
112    /**
113     * Shows or hides the sub navigation.<p>
114     *
115     * @param visible <code>true</code> to show the sub navigation
116     */
117    public void setSubNavVisible(boolean visible) {
118
119        m_subNav.setVisible(visible);
120        if (visible) {
121            removeStyleName("o-tools-subnav-hidden");
122        } else {
123            addStyleName("o-tools-subnav-hidden");
124        }
125    }
126}