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.ui.actions;
029
030import org.opencms.file.CmsObject;
031import org.opencms.file.CmsResource;
032import org.opencms.ui.I_CmsDialogContext;
033import org.opencms.ui.apps.CmsAppWorkplaceUi;
034import org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode;
035import org.opencms.ui.contextmenu.I_CmsContextMenuItem;
036
037import java.util.List;
038import java.util.Locale;
039import java.util.Map;
040
041/**
042 * A workplace action context menu item.<p>
043 */
044public class CmsContextMenuActionItem implements I_CmsContextMenuItem, I_CmsADEAction {
045
046    /** The workplace action. */
047    private I_CmsWorkplaceAction m_action;
048
049    /** The order. */
050    private float m_order;
051
052    /** The parent item id. */
053    private String m_parentId;
054
055    /** The priority. */
056    private int m_priority;
057
058    /**
059     * Creates a new instance.<p>
060     *
061     * @param action the action to execute
062     * @param parentId the parent item id
063     * @param order the order
064     * @param priority the priority
065     */
066    public CmsContextMenuActionItem(I_CmsWorkplaceAction action, String parentId, float order, int priority) {
067        m_parentId = parentId;
068        m_order = order;
069        m_priority = priority;
070        m_action = action;
071    }
072
073    /**
074     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#executeAction(org.opencms.ui.I_CmsDialogContext)
075     */
076    public void executeAction(I_CmsDialogContext context) {
077
078        CmsAppWorkplaceUi.get().disableGlobalShortcuts();
079        m_action.executeAction(context);
080    }
081
082    /**
083     * @see org.opencms.ui.actions.I_CmsADEAction#getCommandClassName()
084     */
085    public String getCommandClassName() {
086
087        if (isAdeSupported()) {
088            return ((I_CmsADEAction)m_action).getCommandClassName();
089        }
090        return null;
091    }
092
093    /**
094     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getId()
095     */
096    public String getId() {
097
098        return m_action.getId();
099    }
100
101    /**
102     * @see org.opencms.ui.actions.I_CmsADEAction#getJspPath()
103     */
104    public String getJspPath() {
105
106        if (isAdeSupported()) {
107            return ((I_CmsADEAction)m_action).getJspPath();
108        }
109        return null;
110    }
111
112    /**
113     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getOrder()
114     */
115    public float getOrder() {
116
117        return m_order;
118
119    }
120
121    /**
122     * @see org.opencms.ui.actions.I_CmsADEAction#getParams()
123     */
124    public Map<String, String> getParams() {
125
126        if (isAdeSupported()) {
127            return ((I_CmsADEAction)m_action).getParams();
128        }
129        return null;
130    }
131
132    /**
133     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getParentId()
134     */
135    public String getParentId() {
136
137        return m_parentId;
138    }
139
140    /**
141     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getPriority()
142     */
143    public int getPriority() {
144
145        return m_priority;
146    }
147
148    /**
149     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getTitle(java.util.Locale)
150     */
151    public String getTitle(Locale locale) {
152
153        return m_action.getTitle(locale);
154    }
155
156    /**
157     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getVisibility(org.opencms.file.CmsObject, java.util.List)
158     */
159    public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
160
161        return m_action.getVisibility(cms, resources);
162    }
163
164    /**
165     * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.ui.I_CmsDialogContext)
166     */
167    public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) {
168
169        return m_action.getVisibility(context);
170    }
171
172    /**
173     * Returns the workplace action.<p>
174     *
175     * @return the workplace action
176     */
177    public I_CmsWorkplaceAction getWorkplaceAction() {
178
179        return m_action;
180    }
181
182    /**
183     * @see org.opencms.ui.actions.I_CmsADEAction#isAdeSupported()
184     */
185    public boolean isAdeSupported() {
186
187        return (m_action instanceof I_CmsADEAction) && ((I_CmsADEAction)m_action).isAdeSupported();
188    }
189
190    /**
191     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#isLeafItem()
192     */
193    public boolean isLeafItem() {
194
195        return true;
196    }
197}