001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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
068        m_parentId = parentId;
069        m_order = order;
070        m_priority = priority;
071        m_action = action;
072    }
073
074    /**
075     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#executeAction(org.opencms.ui.I_CmsDialogContext)
076     */
077    public void executeAction(I_CmsDialogContext context) {
078
079        CmsAppWorkplaceUi.get().disableGlobalShortcuts();
080        m_action.executeAction(context);
081    }
082
083    /**
084     * @see org.opencms.ui.actions.I_CmsADEAction#getCommandClassName()
085     */
086    public String getCommandClassName() {
087
088        if (isAdeSupported()) {
089            return ((I_CmsADEAction)m_action).getCommandClassName();
090        }
091        return null;
092    }
093
094    /**
095     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getId()
096     */
097    public String getId() {
098
099        return m_action.getId();
100    }
101
102    /**
103     * @see org.opencms.ui.actions.I_CmsADEAction#getJspPath()
104     */
105    public String getJspPath() {
106
107        if (isAdeSupported()) {
108            return ((I_CmsADEAction)m_action).getJspPath();
109        }
110        return null;
111    }
112
113    /**
114     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getOrder()
115     */
116    public float getOrder() {
117
118        return m_order;
119
120    }
121
122    /**
123     * @see org.opencms.ui.actions.I_CmsADEAction#getParams()
124     */
125    public Map<String, String> getParams() {
126
127        if (isAdeSupported()) {
128            return ((I_CmsADEAction)m_action).getParams();
129        }
130        return null;
131    }
132
133    /**
134     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getParentId()
135     */
136    public String getParentId() {
137
138        return m_parentId;
139    }
140
141    /**
142     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getPriority()
143     */
144    public int getPriority() {
145
146        return m_priority;
147    }
148
149    /**
150     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getTitle(java.util.Locale)
151     */
152    public String getTitle(Locale locale) {
153
154        return m_action.getTitle(locale);
155    }
156
157    /**
158     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getVisibility(org.opencms.file.CmsObject, java.util.List)
159     */
160    public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
161
162        return m_action.getVisibility(cms, resources);
163    }
164
165    /**
166     * @see org.opencms.ui.contextmenu.I_CmsHasMenuItemVisibility#getVisibility(org.opencms.ui.I_CmsDialogContext)
167     */
168    public CmsMenuItemVisibilityMode getVisibility(I_CmsDialogContext context) {
169
170        return m_action.getVisibility(context);
171    }
172
173    /**
174     * Returns the workplace action.<p>
175     *
176     * @return the workplace action
177     */
178    public I_CmsWorkplaceAction getWorkplaceAction() {
179
180        return m_action;
181    }
182
183    /**
184     * @see org.opencms.ui.actions.I_CmsADEAction#isAdeSupported()
185     */
186    public boolean isAdeSupported() {
187
188        return (m_action instanceof I_CmsADEAction) && ((I_CmsADEAction)m_action).isAdeSupported();
189    }
190
191    /**
192     * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#isLeafItem()
193     */
194    public boolean isLeafItem() {
195
196        return true;
197    }
198}