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.sitemap.client.toolbar;
029
030import org.opencms.ade.sitemap.client.CmsSitemapView;
031import org.opencms.ade.sitemap.client.control.CmsSitemapController;
032import org.opencms.ade.sitemap.shared.CmsGalleryType;
033import org.opencms.ade.sitemap.shared.CmsSitemapData.EditorMode;
034import org.opencms.gwt.client.CmsCoreProvider;
035import org.opencms.gwt.client.ui.CmsPushButton;
036import org.opencms.gwt.client.ui.CmsQuickLauncher.A_QuickLaunchHandler;
037import org.opencms.gwt.client.ui.CmsToggleButton;
038import org.opencms.gwt.client.ui.CmsToolbar;
039import org.opencms.gwt.client.ui.CmsToolbarContextButton;
040import org.opencms.gwt.client.ui.I_CmsToolbarButton;
041import org.opencms.gwt.shared.CmsGwtConstants.QuickLaunch;
042import org.opencms.gwt.shared.CmsQuickLaunchParams;
043
044import java.util.Collection;
045
046import com.google.gwt.dom.client.Style.Display;
047import com.google.gwt.event.dom.client.ClickEvent;
048import com.google.gwt.event.dom.client.ClickHandler;
049import com.google.gwt.user.client.ui.Widget;
050
051/**
052 * Sitemap toolbar.<p>
053 *
054 * @since 8.0.0
055 */
056public class CmsSitemapToolbar extends CmsToolbar {
057
058    /**
059     * Quick launch handler for the sitemap.<p>
060     */
061    public static class SitemapQuickLaunchHandler extends A_QuickLaunchHandler {
062
063        /**
064         * @see org.opencms.gwt.client.ui.CmsQuickLauncher.I_QuickLaunchHandler#getParameters()
065         */
066        public CmsQuickLaunchParams getParameters() {
067
068            return new CmsQuickLaunchParams(
069                QuickLaunch.CONTEXT_SITEMAP,
070                null,
071                null,
072                CmsSitemapView.getInstance().getController().getData().getReturnCode(),
073                CmsCoreProvider.get().getUri(),
074                CmsCoreProvider.get().getLastPageId());
075        }
076
077    }
078
079    /** The sitemap clipboard button. */
080    private CmsToolbarClipboardButton m_clipboardButton;
081
082    /** The context menu button. */
083    private CmsToolbarContextButton m_contextMenuButton;
084
085    /** The new galleries menu button. */
086    private CmsToolbarNewGalleryButton m_newGalleryMenuButton;
087
088    /** The new menu button. */
089    private CmsToolbarNewButton m_newMenuButton;
090
091    /** The sitemap toolbar handler. */
092    private CmsSitemapToolbarHandler m_toolbarHandler;
093
094    /**
095     * Constructor.<p>
096     *
097     * @param controller the sitemap controller
098     */
099    public CmsSitemapToolbar(CmsSitemapController controller) {
100
101        m_toolbarHandler = new CmsSitemapToolbarHandler(controller.getData().getContextMenuEntries());
102        addLeft(new CmsToolbarPublishButton(this, controller));
103        m_newMenuButton = new CmsToolbarNewButton(this, controller);
104        if (controller.isEditable() && (controller.getData().getDefaultNewElementInfo() != null)) {
105            m_clipboardButton = new CmsToolbarClipboardButton(this, controller);
106            addLeft(m_clipboardButton);
107            addLeft(m_newMenuButton);
108        }
109
110        m_newGalleryMenuButton = new CmsToolbarNewGalleryButton(this, controller);
111        if (controller.isEditable()) {
112            addLeft(m_newGalleryMenuButton);
113        }
114
115        addLeft(new CmsToolbarChooseEditorModeButton(CmsCoreProvider.get().getUserInfo().isDeveloper()));
116        ClickHandler clickHandler = new ClickHandler() {
117
118            /**
119             * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
120             */
121            public void onClick(ClickEvent event) {
122
123                I_CmsToolbarButton source = (I_CmsToolbarButton)event.getSource();
124                source.onToolbarClick();
125                if (source instanceof CmsPushButton) {
126                    ((CmsPushButton)source).clearHoverState();
127                }
128            }
129        };
130
131        m_contextMenuButton = new CmsToolbarContextButton(m_toolbarHandler);
132        m_contextMenuButton.addClickHandler(clickHandler);
133        insertRight(m_contextMenuButton, 0);
134        setMode(EditorMode.navigation);
135        setQuickLaunchHandler(new SitemapQuickLaunchHandler());
136    }
137
138    /**
139     * Deactivates all toolbar buttons.<p>
140     */
141    public void deactivateAll() {
142
143        for (Widget button : getAll()) {
144            if (button instanceof I_CmsToolbarActivatable) {
145                ((I_CmsToolbarActivatable)button).setEnabled(false);
146            } else if (button instanceof CmsToggleButton) {
147                ((CmsToggleButton)button).setEnabled(false);
148            }
149        }
150    }
151
152    /**
153     * Gets the context menu button.<p>
154     *
155     * @return the context menu button
156     */
157    public CmsToolbarContextButton getContextMenuButton() {
158
159        return m_contextMenuButton;
160    }
161
162    /**
163     * Returns the toolbar handler.<p>
164     *
165     * @return the toolbar handler
166     */
167    public CmsSitemapToolbarHandler getToolbarHandler() {
168
169        return m_toolbarHandler;
170    }
171
172    /**
173     * Should be executed by every widget when starting an action.<p>
174     *
175     * @param widget the widget that got activated
176     */
177    public void onButtonActivation(Widget widget) {
178
179        for (Widget w : getAll()) {
180            if (!(w instanceof I_CmsToolbarActivatable)) {
181                continue;
182            }
183            ((I_CmsToolbarActivatable)w).onActivation(widget);
184        }
185    }
186
187    /**
188     * Enables/disables the new clipboard button.<p>
189     *
190     * @param enabled <code>true</code> to enable the button
191     * @param disabledReason the reason, why the button is disabled
192     */
193    public void setClipboardEnabled(boolean enabled, String disabledReason) {
194
195        if (m_clipboardButton != null) {
196            if (enabled) {
197                m_clipboardButton.enable();
198            } else {
199                m_clipboardButton.disable(disabledReason);
200            }
201        }
202    }
203
204    /**
205     * Sets the available gallery types.<p>
206     *
207     * @param galleryTypes the gallery types
208     */
209    public void setGalleryTypes(Collection<CmsGalleryType> galleryTypes) {
210
211        m_newGalleryMenuButton.setGalleryTypes(galleryTypes);
212    }
213
214    /**
215     * Sets the galleries mode.<p>
216     *
217     * @param mode the editor mode
218     */
219    public void setMode(EditorMode mode) {
220
221        switch (mode) {
222            case galleries:
223                m_newGalleryMenuButton.getElement().getStyle().clearDisplay();
224                m_newMenuButton.getElement().getStyle().setDisplay(Display.NONE);
225                break;
226            case modelpages:
227            case categories:
228                m_newGalleryMenuButton.getElement().getStyle().setDisplay(Display.NONE);
229                m_newMenuButton.getElement().getStyle().clearDisplay();
230                break;
231            default:
232                m_newMenuButton.getElement().getStyle().clearDisplay();
233                m_newGalleryMenuButton.getElement().getStyle().setDisplay(Display.NONE);
234                break;
235        }
236    }
237
238    /**
239     * Enables/disables the new menu button.<p>
240     *
241     * @param enabled <code>true</code> to enable the button
242     * @param disabledReason the reason, why the button is disabled
243     */
244    public void setNewEnabled(boolean enabled, String disabledReason) {
245
246        if (enabled) {
247            m_newMenuButton.enable();
248        } else {
249            m_newMenuButton.disable(disabledReason);
250        }
251    }
252
253    /**
254     * Enables/disables the new menu button.<p>
255     *
256     * @param enabled <code>true</code> to enable the button
257     * @param disabledReason the reason, why the button is disabled
258     */
259    public void setNewGalleryEnabled(boolean enabled, String disabledReason) {
260
261        if (enabled) {
262            m_newGalleryMenuButton.enable();
263        } else {
264            m_newGalleryMenuButton.disable(disabledReason);
265        }
266    }
267}