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.ade.editprovider.client;
029
030import org.opencms.gwt.client.ui.A_CmsToolbarButton;
031import org.opencms.gwt.client.ui.I_CmsButton;
032import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
033import org.opencms.gwt.client.util.CmsStyleVariable;
034
035import com.google.gwt.user.client.ui.RootPanel;
036
037/**
038 * The selection button for the direct edit provider.<p>
039 *
040 * @since 8.0.0
041 */
042public class CmsToolbarSelectionButton extends A_CmsToolbarButton<CmsDirectEditToolbarHandler> {
043
044    /** The style variable which controls the direct edit button visibility. */
045    CmsStyleVariable m_editButtonsVisibility;
046
047    /**
048     * Constructor.<p>
049     *
050     * @param handler the container-page handler
051     */
052    public CmsToolbarSelectionButton(CmsDirectEditToolbarHandler handler) {
053
054        super(I_CmsButton.ButtonData.SELECTION, handler);
055        addStyleName(I_CmsLayoutBundle.INSTANCE.toolbarCss().toolbarShow());
056        m_editButtonsVisibility = new CmsStyleVariable(RootPanel.get());
057    }
058
059    /**
060     * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarActivate()
061     */
062    public void onToolbarActivate() {
063
064        // this is never called
065    }
066
067    /**
068     * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarClick()
069     */
070    @Override
071    public void onToolbarClick() {
072
073        if (areEditButtonsVisible()) {
074            setDirectEditButtonsVisible(false);
075        } else {
076            setDirectEditButtonsVisible(true);
077        }
078    }
079
080    /**
081     * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarDeactivate()
082     */
083    public void onToolbarDeactivate() {
084
085        // this is never called
086    }
087
088    /**
089     * @see org.opencms.gwt.client.ui.A_CmsToolbarButton#setActive(boolean)
090     */
091    @Override
092    public void setActive(boolean active) {
093
094        setDown(active);
095        setDirectEditButtonsVisible(active);
096    }
097
098    /**
099     * Sets the visibility of the direct edit buttons.<p>
100     *
101     * @param visible true if the buttons should be shown
102     */
103    protected void setDirectEditButtonsVisible(boolean visible) {
104
105        m_editButtonsVisibility.setValue(
106            visible
107            ? I_CmsLayoutBundle.INSTANCE.directEditCss().showButtons()
108            : I_CmsLayoutBundle.INSTANCE.directEditCss().hideButtons());
109        getHandler().showToolbar(visible);
110    }
111
112    /**
113     * Checks whether the direct edit buttons are visible.<p>
114     *
115     * @return true if the direct edit buttons are visible
116     */
117    private boolean areEditButtonsVisible() {
118
119        return m_editButtonsVisibility.getValue().equals(
120            org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.directEditCss().showButtons());
121    }
122}