KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > list > CmsListResourceTypeIconAction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListResourceTypeIconAction.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.list;
33
34 import org.opencms.i18n.CmsMessageContainer;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 import java.io.File JavaDoc;
40
41 /**
42  * Displays an icon action for the resource type.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.2 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsListResourceTypeIconAction extends CmsListExplorerDirectAction {
51
52     /**
53      * Default Constructor.<p>
54      *
55      * @param id the unique id
56      * @param wp the current workplace context
57      */

58     public CmsListResourceTypeIconAction(String JavaDoc id, A_CmsListExplorerDialog wp) {
59
60         super(id, wp);
61     }
62
63     /**
64      * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getHelpText()
65      */

66     public CmsMessageContainer getHelpText() {
67
68         if (super.getHelpText() == null || super.getHelpText().equals(EMPTY_MESSAGE)) {
69             return Messages.get().container(Messages.GUI_EXPLORER_LIST_ACTION_RES_HELP_0);
70         }
71         return super.getHelpText();
72     }
73
74     /**
75      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
76      */

77     public String JavaDoc getIconPath() {
78
79         return getResourceUtil().getIconPathExplorer();
80     }
81
82     /**
83      * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getName()
84      */

85     public CmsMessageContainer getName() {
86
87         if (super.getName() == null) {
88             return new CmsMessageContainer(null, getResourceUtil().getResourceTypeName());
89         }
90         return super.getName();
91     }
92     
93     /**
94      * @see org.opencms.workplace.list.CmsListExplorerDirectAction#defButtonHtml(org.opencms.jsp.CmsJspActionElement, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String, boolean)
95      */

96     protected String JavaDoc defButtonHtml(
97         CmsJspActionElement jsp,
98         String JavaDoc id,
99         String JavaDoc helpId,
100         String JavaDoc name,
101         String JavaDoc helpText,
102         boolean enabled,
103         String JavaDoc iconPath,
104         String JavaDoc confirmationMessage,
105         String JavaDoc onClick,
106         boolean singleHelp) {
107
108         StringBuffer JavaDoc html = new StringBuffer JavaDoc(1024);
109         html.append("\t<span class=\"link");
110         if (enabled) {
111             html.append("\"");
112         } else {
113             html.append(" linkdisabled\"");
114         }
115         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) {
116             if (!singleHelp) {
117                 html.append(" onMouseOver=\"sMH('");
118                 html.append(id);
119                 html.append("');\" onMouseOut=\"hMH('");
120                 html.append(id);
121                 html.append("');\"");
122             } else {
123                 html.append(" onMouseOver=\"sMHS('");
124                 html.append(id);
125                 html.append("', '");
126                 html.append(helpId);
127                 html.append("');\" onMouseOut=\"hMH('");
128                 html.append(id);
129                 html.append("', '");
130                 html.append(helpId);
131                 html.append("');\"");
132             }
133         }
134         if (enabled && CmsStringUtil.isNotEmptyOrWhitespaceOnly(onClick)) {
135             html.append(" onClick=\"");
136             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
137                 html.append("if (confirm('" + CmsStringUtil.escapeJavaScript(confirmationMessage) + "')) {");
138             }
139             html.append(onClick);
140             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
141                 html.append(" }");
142             }
143             html.append("\"");
144         }
145         html.append(" title='");
146         html.append(name);
147         html.append("'");
148         html.append(" style='display: block; width: 20px; height: 20px;'>");
149         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath)) {
150             html.append("<img SRC='");
151             html.append(CmsWorkplace.getSkinUri());
152             if (!enabled) {
153                 StringBuffer JavaDoc icon = new StringBuffer JavaDoc(128);
154                 icon.append(iconPath.substring(0, iconPath.lastIndexOf('.')));
155                 icon.append("_disabled");
156                 icon.append(iconPath.substring(iconPath.lastIndexOf('.')));
157                 if (jsp != null) {
158                     String JavaDoc resorcesRoot = jsp.getJspContext().getServletConfig().getServletContext().getRealPath(
159                         "/resources/");
160                     File JavaDoc test = new File JavaDoc(resorcesRoot + "/" + icon.toString());
161                     if (test.exists()) {
162                         html.append(icon);
163                     } else {
164                         html.append(iconPath);
165                     }
166                 } else {
167                     html.append(iconPath);
168                 }
169             } else {
170                 html.append(iconPath);
171             }
172             html.append("'");
173             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) {
174                 html.append(" alt='");
175                 html.append(name);
176                 html.append("'");
177                 html.append(" title='");
178                 html.append(name);
179                 html.append("'");
180             }
181             html.append(" style='width: 16px; height: 16px;");
182             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getResourceUtil().getStyleSiblings())) {
183                 html.append(getResourceUtil().getStyleSiblings());
184             }
185             html.append("' >");
186         }
187         html.append("</span>\n");
188         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText) && !singleHelp) {
189             html.append("<div class='help' id='help");
190             html.append(helpId);
191             html.append("' onMouseOver=\"sMH('");
192             html.append(id);
193             html.append("');\" onMouseOut=\"hMH('");
194             html.append(id);
195             html.append("');\">");
196             html.append(helpText);
197             html.append("</div>\n");
198         }
199         return html.toString();
200     }
201 }
202
Popular Tags