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.containerpage.client.ui;
029
030import org.opencms.gwt.client.dnd.I_CmsDragHandle;
031import org.opencms.gwt.client.dnd.I_CmsDraggable;
032import org.opencms.gwt.client.ui.CmsPushButton;
033import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
034
035import com.google.gwt.user.client.Event;
036
037/**
038 * An optional container element button.<p>
039 *
040 * @since 8.0.0
041 */
042public class CmsElementOptionButton extends CmsPushButton implements I_CmsDragHandle {
043
044    /** The associated container element. */
045    private CmsContainerPageElementPanel m_dragElement;
046
047    /** The associated tool-bar button. */
048    private A_CmsToolbarOptionButton m_toolbarButton;
049
050    /**
051     * Constructor.<p>
052     *
053     * @param toolbarButton the tool-bar button associated with this button, providing all necessary information
054     * @param element the element to create this button for
055     */
056    public CmsElementOptionButton(A_CmsToolbarOptionButton toolbarButton, CmsContainerPageElementPanel element) {
057
058        super();
059        setImageClass(toolbarButton.getButtonData().getSmallIconClass());
060        setButtonStyle(ButtonStyle.FONT_ICON, null);
061        setTitle(toolbarButton.getTitle());
062        m_toolbarButton = toolbarButton;
063        m_dragElement = element;
064    }
065
066    /**
067     * Returns the dragElement.<p>
068     *
069     * @return the dragElement
070     */
071    public CmsContainerPageElementPanel getContainerElement() {
072
073        return m_dragElement;
074    }
075
076    /**
077     * @see org.opencms.gwt.client.dnd.I_CmsDragHandle#getDraggable()
078     */
079    public I_CmsDraggable getDraggable() {
080
081        return m_dragElement;
082    }
083
084    /**
085     * Returns the associated tool-bar button.<p>
086     *
087     * @return the associated tool-bar button
088     */
089    public A_CmsToolbarOptionButton getToolbarButton() {
090
091        return m_toolbarButton;
092    }
093
094    /**
095     * @see org.opencms.gwt.client.ui.CmsPushButton#onBrowserEvent(com.google.gwt.user.client.Event)
096     */
097    @Override
098    public void onBrowserEvent(Event event) {
099
100        /* This is to prevent click events from leaking out to the surrounding container element.
101         * We can't just use preventDefault in the click handler itself, since the GWT button widget class does
102         * some magic related to event handling (it ignores the initial click event, then fires *another* click
103         * event when receiving a mouseup event - the click handler doesn't get to see the first event).
104         */
105        if (event.getTypeInt() == Event.ONCLICK) {
106            event.preventDefault();
107            event.stopPropagation();
108        }
109        super.onBrowserEvent(event);
110    }
111}