001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.acacia.client.ui;
029
030import org.opencms.acacia.client.CmsButtonBarHandler;
031import org.opencms.acacia.client.CmsChoiceMenuEntryBean;
032import org.opencms.acacia.client.css.I_CmsLayoutBundle;
033import org.opencms.gwt.client.util.CmsDomUtil;
034
035import com.google.gwt.event.dom.client.ClickEvent;
036import com.google.gwt.event.dom.client.ClickHandler;
037import com.google.gwt.event.dom.client.MouseOutEvent;
038import com.google.gwt.event.dom.client.MouseOverEvent;
039import com.google.gwt.user.client.rpc.AsyncCallback;
040import com.google.gwt.user.client.ui.Composite;
041import com.google.gwt.user.client.ui.HTML;
042
043/**
044 * A menu entry widget for selecting choices for complex choice values.<p>
045 */
046public class CmsChoiceMenuEntryWidget extends Composite {
047
048    /** The root attribute choice menu to which this entry belongs. */
049    private CmsAttributeChoiceWidget m_attributeChoiceWidget;
050
051    /** The bean to which this entry belongs. */
052    private CmsChoiceMenuEntryBean m_entryBean;
053
054    /** The callback to invoke when a widget is selected. */
055    private AsyncCallback<CmsChoiceMenuEntryBean> m_selectCallback;
056
057    /** The submenu to which this entry widget belongs. */
058    private CmsChoiceSubmenu m_submenu;
059
060    /**
061      * Creates a new menu entry instance.<p>
062      *
063      * @param label the entry label
064      * @param help the entry help text
065      * @param menuEntry the menu entry bean
066      * @param selectHandler the select handler
067      * @param choiceWidget the root choice menu
068      * @param submenu the submenu for which this entry is being created
069      */
070    public CmsChoiceMenuEntryWidget(
071        String label,
072        String help,
073        final CmsChoiceMenuEntryBean menuEntry,
074        final AsyncCallback<CmsChoiceMenuEntryBean> selectHandler,
075        CmsAttributeChoiceWidget choiceWidget,
076        CmsChoiceSubmenu submenu) {
077
078        HTML baseWidget = new HTML(label);
079        initWidget(baseWidget);
080        setStyleName(I_CmsLayoutBundle.INSTANCE.attributeChoice().choice());
081        addStyleName(CmsButtonBarHandler.HOVERABLE_MARKER);
082        m_entryBean = menuEntry;
083        m_selectCallback = selectHandler;
084        m_submenu = submenu;
085        m_attributeChoiceWidget = choiceWidget;
086        setTitle(CmsDomUtil.stripHtml(help));
087        if (menuEntry.isLeaf()) {
088            baseWidget.addClickHandler(new ClickHandler() {
089
090                public void onClick(ClickEvent event) {
091
092                    selectHandler.onSuccess(menuEntry);
093                    CmsButtonBarHandler.INSTANCE.closeAll();
094
095                }
096            });
097        }
098        addDomHandler(CmsButtonBarHandler.INSTANCE, MouseOverEvent.getType());
099        addDomHandler(CmsButtonBarHandler.INSTANCE, MouseOutEvent.getType());
100    }
101
102    /**
103     * Gets the root choice menu.<p>
104     *
105     * @return the root choice menu
106     */
107    public CmsAttributeChoiceWidget getAttributeChoiceWidget() {
108
109        return m_attributeChoiceWidget;
110    }
111
112    /**
113     * Gets the menu entry bean.<p>
114     *
115     * @return the menu entry bean
116     */
117    public CmsChoiceMenuEntryBean getEntryBean() {
118
119        return m_entryBean;
120    }
121
122    /**
123     * Gets the select handler.<p>
124     *
125     * @return the select handler
126     */
127    public AsyncCallback<CmsChoiceMenuEntryBean> getSelectHandler() {
128
129        return m_selectCallback;
130    }
131
132    /**
133     * Gets the submenu to which this entry belongs (or null if it belongs to a root menu).<p>
134     *
135     * @return the submenu of this entry
136     */
137    public CmsChoiceSubmenu getSubmenu() {
138
139        return m_submenu;
140    }
141}