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.gwt.client.ui.contextmenu;
029
030import org.opencms.gwt.client.util.CmsClientCollectionUtil;
031import org.opencms.gwt.shared.CmsContextMenuEntryBean;
032import org.opencms.util.CmsUUID;
033
034import java.util.List;
035
036/**
037 * Implementation for a context menu entry.<p>
038 *
039 * @since version 8.0.0
040 */
041public class CmsContextMenuEntry implements I_CmsContextMenuEntry {
042
043    /** The server bean for this menu entry. */
044    private CmsContextMenuEntryBean m_bean;
045
046    /** The context menu handler. */
047    private I_CmsContextMenuHandler m_handler;
048
049    /** The command for this entry. */
050    private I_CmsContextMenuCommand m_menuCommand;
051
052    /** The structure id of the resource to execute the command on. */
053    private CmsUUID m_structureId;
054
055    /** The sub menu entries as list. */
056    private List<I_CmsContextMenuEntry> m_subMenu;
057
058    /**
059     * Constructor.<p>
060     *
061     * @param handler the context menu handler
062     * @param structureId the structure id
063     * @param menuCommand the menu command
064     */
065    public CmsContextMenuEntry(
066        I_CmsContextMenuHandler handler,
067        CmsUUID structureId,
068        I_CmsContextMenuCommand menuCommand) {
069
070        m_menuCommand = menuCommand;
071        m_handler = handler;
072        m_structureId = structureId;
073    }
074
075    /**
076     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#execute()
077     */
078    public void execute() {
079
080        if (m_menuCommand != null) {
081            m_menuCommand.execute(m_structureId, m_handler, m_bean);
082        }
083    }
084
085    /**
086     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#generateMenuItem()
087     */
088    public A_CmsContextMenuItem generateMenuItem() {
089
090        if ((m_menuCommand != null) && m_menuCommand.hasItemWidget() && m_bean.isActive()) {
091            return m_menuCommand.getItemWidget(m_structureId, m_handler, m_bean);
092        } else {
093            return new CmsContextMenuItem(this);
094        }
095    }
096
097    /**
098     * Returns the bean.<p>
099     *
100     * @return the bean
101     */
102    public CmsContextMenuEntryBean getBean() {
103
104        return m_bean;
105    }
106
107    /**
108     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getIconClass()
109     */
110    public String getIconClass() {
111
112        return m_bean.getIconClass();
113
114    }
115
116    /**
117     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getJspPath()
118     */
119    public String getJspPath() {
120
121        return m_bean.getJspPath();
122    }
123
124    /**
125     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getLabel()
126     */
127    public String getLabel() {
128
129        return m_bean.getLabel();
130    }
131
132    /**
133     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getName()
134     */
135    public String getName() {
136
137        return m_bean.getName();
138    }
139
140    /**
141     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getReason()
142     */
143    public String getReason() {
144
145        return m_bean.getReason();
146    }
147
148    /**
149     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#getSubMenu()
150     */
151    public List<I_CmsContextMenuEntry> getSubMenu() {
152
153        return m_subMenu;
154    }
155
156    /**
157     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#hasSubMenu()
158     */
159    public boolean hasSubMenu() {
160
161        if (!CmsClientCollectionUtil.isEmptyOrNull(getSubMenu())) {
162            return true;
163        }
164        return false;
165    }
166
167    /**
168     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#isActive()
169     */
170    public boolean isActive() {
171
172        return m_bean.isActive();
173    }
174
175    /**
176     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#isSeparator()
177     */
178    public boolean isSeparator() {
179
180        return m_bean.isSeparator();
181    }
182
183    /**
184     * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry#isVisible()
185     */
186    public boolean isVisible() {
187
188        return m_bean.isVisible();
189    }
190
191    /**
192     * Sets the bean.<p>
193     *
194     * @param bean the bean to set
195     */
196    public void setBean(CmsContextMenuEntryBean bean) {
197
198        m_bean = bean;
199    }
200
201    /**
202     * Sets the command.<p>
203     *
204     * @param command the command to set
205     */
206    public void setMenuCommand(I_CmsContextMenuCommand command) {
207
208        m_menuCommand = command;
209    }
210
211    /**
212     * Sets the sub menu.<p>
213     *
214     * @param subMenu the sub menu to set
215     */
216    public void setSubMenu(List<I_CmsContextMenuEntry> subMenu) {
217
218        m_subMenu = subMenu;
219    }
220}