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 GmbH & Co. KG, 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.workplace.administration;
029
030import org.opencms.workplace.CmsWorkplace;
031import org.opencms.workplace.tools.A_CmsHtmlIconButton;
032import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
033import org.opencms.workplace.tools.CmsToolMacroResolver;
034
035/**
036 * Html icon button implementation that generates the
037 * required html code for a menu item.<p>
038 *
039 * @since 6.0.0
040 */
041public class CmsAdminMenuItem {
042
043    /** Enabled flag. */
044    private boolean m_enabled;
045
046    /** Help text. */
047    private final String m_helpText;
048
049    /** Path to the icon. */
050    private final String m_iconPath;
051
052    /** Dhtml id, from name. */
053    private final String m_id;
054
055    /** Link to follow when selected. */
056    private final String m_link;
057
058    /** Display name of the item. */
059    private final String m_name;
060
061    /** Target frame. */
062    private final String m_target;
063
064    /**
065     * Default Constructor.<p>
066     *
067     * @param id a unique id
068     * @param name the name of the item
069     * @param iconPath the icon to display
070     * @param link the link to open when selected
071     * @param helpText the help text to display
072     * @param enabled if enabled or not
073     * @param target the target frame to open the link into
074     */
075    public CmsAdminMenuItem(
076        String id,
077        String name,
078        String iconPath,
079        String link,
080        String helpText,
081        boolean enabled,
082        String target) {
083
084        m_id = id;
085        m_name = name;
086        m_iconPath = iconPath;
087        m_link = link;
088        m_helpText = helpText;
089        m_enabled = enabled;
090        m_target = target;
091    }
092
093    /**
094     * Returns the help text.<p>
095     *
096     * @return the help text
097     */
098    public String getHelpText() {
099
100        return m_helpText;
101    }
102
103    /**
104     * Returns the path to the icon.<p>
105     *
106     * @return the path to the icon
107     */
108    public String getIconPath() {
109
110        return m_iconPath;
111    }
112
113    /**
114     * Returns the dhtml unique id.<p>
115     *
116     * @return the dhtml unique id
117     */
118    public String getId() {
119
120        return m_id;
121    }
122
123    /**
124     * Returns the link.<p>
125     *
126     * @return the link
127     */
128    public String getLink() {
129
130        return m_link;
131    }
132
133    /**
134     * Returns the display name.<p>
135     *
136     * @return the name
137     */
138    public String getName() {
139
140        return m_name;
141    }
142
143    /**
144     * Returns the target.<p>
145     *
146     * @return the target
147     */
148    public String getTarget() {
149
150        return m_target;
151    }
152
153    /**
154     * Returns if enabled or disabled.<p>
155     *
156     * @return if enabled or disabled
157     */
158    public boolean isEnabled() {
159
160        return m_enabled;
161    }
162
163    /**
164     * Returns the necessary html code.<p>
165     *
166     * @param wp the workplace
167     *
168     * @return html code
169     */
170    public String itemHtml(CmsWorkplace wp) {
171
172        StringBuffer html = new StringBuffer(1024);
173        html.append("<table border='0' cellspacing='0' cellpadding='0' width='100%' class='node' id='");
174        html.append(getId());
175        html.append("'>\n");
176        html.append("\t<tr>\n");
177        html.append("\t\t<td>\n");
178        String onClic = "return openView('" + getId() + "', '" + m_link + "', '" + m_target + "');";
179        html.append(A_CmsHtmlIconButton.defaultButtonHtml(
180            CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT,
181            getId(),
182            getName(),
183            getHelpText(),
184            isEnabled(),
185            getIconPath(),
186            null,
187            onClic));
188
189        html.append("\t\t</td>\n");
190        html.append("\t</tr>\n");
191        html.append("</table>\n");
192        return CmsToolMacroResolver.resolveMacros(html.toString(), wp);
193    }
194
195}