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.list;
029
030import org.opencms.i18n.CmsMessageContainer;
031import org.opencms.main.OpenCms;
032import org.opencms.util.CmsStringUtil;
033import org.opencms.workplace.CmsWorkplace;
034
035import java.io.File;
036
037/**
038 * Displays an icon action for the resource type.<p>
039 *
040 * @since 6.0.0
041 */
042public class CmsListResourceTypeIconAction extends CmsListExplorerDirectAction {
043
044    /**
045     * Default Constructor.<p>
046     *
047     * @param id the unique id
048     */
049    public CmsListResourceTypeIconAction(String id) {
050
051        super(id);
052    }
053
054    /**
055     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getHelpText()
056     */
057    @Override
058    public CmsMessageContainer getHelpText() {
059
060        if ((super.getHelpText() == null) || super.getHelpText().equals(EMPTY_MESSAGE)) {
061            return Messages.get().container(Messages.GUI_EXPLORER_LIST_ACTION_RES_HELP_0);
062        }
063        return super.getHelpText();
064    }
065
066    /**
067     * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
068     */
069    @Override
070    public String getIconPath() {
071
072        return getResourceUtil().getIconPathExplorer();
073    }
074
075    /**
076     * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getName()
077     */
078    @Override
079    public CmsMessageContainer getName() {
080
081        if (super.getName() == null) {
082            return new CmsMessageContainer(null, getResourceUtil().getResourceTypeName());
083        }
084        return super.getName();
085    }
086
087    /**
088     * @see org.opencms.workplace.list.CmsListExplorerDirectAction#defButtonHtml(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String, boolean)
089     */
090    @Override
091    protected String defButtonHtml(
092        String id,
093        String helpId,
094        String name,
095        String helpText,
096        boolean enabled,
097        String iconPath,
098        String confirmationMessage,
099        String onClick,
100        boolean singleHelp) {
101
102        StringBuffer html = new StringBuffer(1024);
103        html.append("\t<span class=\"link");
104        if (enabled) {
105            html.append("\"");
106        } else {
107            html.append(" linkdisabled\"");
108        }
109        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) {
110            if (!singleHelp) {
111                html.append(" onMouseOver=\"sMH('");
112                html.append(id);
113                html.append("');\" onMouseOut=\"hMH('");
114                html.append(id);
115                html.append("');\"");
116            } else {
117                html.append(" onMouseOver=\"sMHS('");
118                html.append(id);
119                html.append("', '");
120                html.append(helpId);
121                html.append("');\" onMouseOut=\"hMH('");
122                html.append(id);
123                html.append("', '");
124                html.append(helpId);
125                html.append("');\"");
126            }
127        }
128        if (enabled && CmsStringUtil.isNotEmptyOrWhitespaceOnly(onClick)) {
129            html.append(" onClick=\"");
130            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
131                html.append("if (confirm('" + CmsStringUtil.escapeJavaScript(confirmationMessage) + "')) {");
132            }
133            html.append(onClick);
134            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
135                html.append(" }");
136            }
137            html.append("\"");
138        }
139        html.append(" title='");
140        html.append(name);
141        html.append("'");
142        html.append(" style='display: block; width: 20px; height: 20px;'>");
143        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath)) {
144            html.append("<img src='");
145            html.append(CmsWorkplace.getSkinUri());
146            if (!enabled) {
147                StringBuffer icon = new StringBuffer(128);
148                int pos = iconPath.lastIndexOf('.');
149                if (pos < 0) {
150                    pos = iconPath.length();
151                }
152                icon.append(iconPath.substring(0, pos));
153                icon.append("_disabled");
154                icon.append(iconPath.substring(pos));
155                String resourcesRoot = OpenCms.getSystemInfo().getWebApplicationRfsPath() + "resources/";
156                File test = new File(resourcesRoot + icon.toString());
157                if (test.exists()) {
158                    html.append(icon);
159                } else {
160                    html.append(iconPath);
161                }
162            } else {
163                html.append(iconPath);
164            }
165            html.append("'");
166            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) {
167                html.append(" alt='");
168                html.append(name);
169                html.append("'");
170                html.append(" title='");
171                html.append(name);
172                html.append("'");
173            }
174            html.append(" style='width: 16px; height: 16px;");
175            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getResourceUtil().getStyleSiblings())) {
176                html.append(getResourceUtil().getStyleSiblings());
177            }
178            html.append("' >");
179        }
180        html.append("</span>\n");
181        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText) && !singleHelp) {
182            html.append("<div class='help' id='help");
183            html.append(helpId);
184            html.append("' onMouseOver=\"sMH('");
185            html.append(id);
186            html.append("');\" onMouseOut=\"hMH('");
187            html.append(id);
188            html.append("');\">");
189            html.append(helpText);
190            html.append("</div>\n");
191        }
192        return html.toString();
193    }
194}