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.hoverbar;
029
030import org.opencms.ade.sitemap.client.CmsSitemapView;
031import org.opencms.ade.sitemap.client.Messages;
032import org.opencms.ade.sitemap.client.ui.CmsCreateModelPageDialog;
033import org.opencms.gwt.client.ui.CmsPushButton;
034import org.opencms.gwt.client.ui.I_CmsButton;
035import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
036
037import com.google.gwt.event.dom.client.ClickEvent;
038import com.google.gwt.event.dom.client.ClickHandler;
039
040/**
041 * Button used to create new model pages.<p>
042 */
043public class CmsHoverbarCreateModelPageButton extends CmsPushButton {
044
045    /** The hover bar. */
046    CmsSitemapHoverbar m_hoverbar;
047
048    /** The model group flag. */
049    private boolean m_isModelGroup;
050
051    /**
052     * Constructor.<p>
053     *
054     * @param isModelGroup in case of a model group page
055     */
056    public CmsHoverbarCreateModelPageButton(boolean isModelGroup) {
057
058        m_isModelGroup = isModelGroup;
059        setImageClass(I_CmsButton.ADD_SMALL);
060        setButtonStyle(ButtonStyle.FONT_ICON, null);
061        setTitle(
062            isModelGroup
063            ? Messages.get().key(Messages.GUI_CREATE_MODEL_GROUP_PAGE_BUTTON_TITLE_0)
064            : Messages.get().key(Messages.GUI_CREATE_MODEL_PAGE_BUTTON_TITLE_0));
065        addClickHandler(new ClickHandler() {
066
067            /**
068             * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
069             */
070            public void onClick(ClickEvent event) {
071
072                if (m_hoverbar != null) {
073                    m_hoverbar.hide();
074                    openDialog();
075                }
076            }
077        });
078    }
079
080    /**
081     * Sets the hover bar instance.<p>
082     *
083     * @param hoverbar the hover bar
084     */
085    public void setHoverbar(CmsSitemapHoverbar hoverbar) {
086
087        m_hoverbar = hoverbar;
088    }
089
090    /**
091     * Opens the new gallery dialog.<p>
092     */
093    protected void openDialog() {
094
095        CmsCreateModelPageDialog dialog = new CmsCreateModelPageDialog(
096            CmsSitemapView.getInstance().getController(),
097            m_isModelGroup);
098        dialog.center();
099    }
100
101}