KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListResourceIconAction.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.4 $
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.file.CmsObject;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.OpenCms;
38 import org.opencms.util.CmsStringUtil;
39 import org.opencms.workplace.CmsWorkplace;
40
41 import java.io.File JavaDoc;
42
43 /**
44  * Displays an icon action for dependency lists.<p>
45  *
46  * @author Michael Moossen
47  *
48  * @version $Revision: 1.4 $
49  *
50  * @since 6.0.0
51  */

52 public class CmsListResourceIconAction extends CmsListDirectAction {
53
54     /** the cms object. */
55     private final CmsObject m_cms;
56
57     /** the id of the column with the resource type. */
58     private final String JavaDoc m_resColumnTypeId;
59
60     /**
61      * Default Constructor.<p>
62      *
63      * @param id the unique id
64      * @param resColumnTypeId the id of the column with the resource type
65      * @param cms the cms context
66      */

67     public CmsListResourceIconAction(String JavaDoc id, String JavaDoc resColumnTypeId, CmsObject cms) {
68
69         super(id);
70         m_cms = cms;
71         m_resColumnTypeId = resColumnTypeId;
72     }
73
74     /**
75      * @see org.opencms.workplace.list.CmsListDirectAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
76      */

77     public String JavaDoc buttonHtml(CmsWorkplace wp) {
78
79         if (!isVisible()) {
80             return "";
81         }
82         return defButtonHtml(
83             wp.getJsp(),
84             getId() + getItem().getId(),
85             getId(),
86             resolveName(wp.getLocale()),
87             resolveHelpText(wp.getLocale()),
88             isEnabled(),
89             getIconPath(),
90             null,
91             resolveOnClic(wp.getLocale()),
92             getColumnForTexts() == null);
93     }
94
95     /**
96      * Returns the cms context.<p>
97      *
98      * @return the cms context
99      */

100     public CmsObject getCms() {
101
102         return m_cms;
103     }
104
105     /**
106      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
107      */

108     public String JavaDoc getIconPath() {
109
110         try {
111             int resourceType = Integer.parseInt(getItem().get(m_resColumnTypeId).toString());
112             String JavaDoc typeName = OpenCms.getResourceManager().getResourceType(resourceType).getTypeName();
113             return "filetypes/" + OpenCms.getWorkplaceManager().getExplorerTypeSetting(typeName).getIcon();
114         } catch (CmsException e) {
115             return super.getIconPath();
116         }
117     }
118
119     /**
120      * Generates a default html code where several buttons can have the same help text.<p>
121      *
122      * the only diff to <code>{@link org.opencms.workplace.tools.A_CmsHtmlIconButton#defaultButtonHtml(CmsJspActionElement, org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum, String, String, String, boolean, String, String, String)}</code>
123      * is that the icons are 16x16.<p>
124      *
125      * @param jsp the cms context, can be null
126      * @param id the id
127      * @param helpId the id of the helptext div tag
128      * @param name the name, if empty only the icon is displayed
129      * @param helpText the help text, if empty no mouse events are generated
130      * @param enabled if enabled or not, if not set be sure to take an according helptext
131      * @param iconPath the path to the icon, if empty only the name is displayed
132      * @param onClick the js code to execute, if empty no link is generated
133      * @param confirmationMessage the confirmation message
134      * @param singleHelp if set, no helptext is written, you have to use the defaultHelpHtml() method later
135      *
136      * @return html code
137      *
138      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#defaultButtonHtml(CmsJspActionElement, org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum, String, String, String, boolean, String, String, String)
139      */

140     protected String JavaDoc defButtonHtml(
141         CmsJspActionElement jsp,
142         String JavaDoc id,
143         String JavaDoc helpId,
144         String JavaDoc name,
145         String JavaDoc helpText,
146         boolean enabled,
147         String JavaDoc iconPath,
148         String JavaDoc confirmationMessage,
149         String JavaDoc onClick,
150         boolean singleHelp) {
151
152         StringBuffer JavaDoc html = new StringBuffer JavaDoc(1024);
153         html.append("\t<span class=\"link");
154         if (enabled) {
155             html.append("\"");
156         } else {
157             html.append(" linkdisabled\"");
158         }
159         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText)) {
160             if (!singleHelp) {
161                 html.append(" onMouseOver=\"sMH('");
162                 html.append(id);
163                 html.append("');\" onMouseOut=\"hMH('");
164                 html.append(id);
165                 html.append("');\"");
166             } else {
167                 html.append(" onMouseOver=\"sMHS('");
168                 html.append(id);
169                 html.append("', '");
170                 html.append(helpId);
171                 html.append("');\" onMouseOut=\"hMH('");
172                 html.append(id);
173                 html.append("', '");
174                 html.append(helpId);
175                 html.append("');\"");
176             }
177         }
178         if (enabled && CmsStringUtil.isNotEmptyOrWhitespaceOnly(onClick)) {
179             html.append(" onClick=\"");
180             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
181                 html.append("if (confirm('" + CmsStringUtil.escapeJavaScript(confirmationMessage) + "')) {");
182             }
183             html.append(onClick);
184             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(confirmationMessage)) {
185                 html.append(" }");
186             }
187             html.append("\"");
188         }
189         html.append(" title='");
190         html.append(name);
191         html.append("'");
192         html.append(" style='display: block; width: 20px; height: 20px;'>");
193         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(iconPath)) {
194             html.append("<img SRC='");
195             html.append(CmsWorkplace.getSkinUri());
196             if (!enabled) {
197                 StringBuffer JavaDoc icon = new StringBuffer JavaDoc(128);
198                 icon.append(iconPath.substring(0, iconPath.lastIndexOf('.')));
199                 icon.append("_disabled");
200                 icon.append(iconPath.substring(iconPath.lastIndexOf('.')));
201                 if (jsp != null) {
202                     String JavaDoc resorcesRoot = jsp.getJspContext().getServletConfig().getServletContext().getRealPath(
203                         "/resources/");
204                     File JavaDoc test = new File JavaDoc(resorcesRoot + "/" + icon.toString());
205                     if (test.exists()) {
206                         html.append(icon);
207                     } else {
208                         html.append(iconPath);
209                     }
210                 } else {
211                     html.append(iconPath);
212                 }
213             } else {
214                 html.append(iconPath);
215             }
216             html.append("'");
217             if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) {
218                 html.append(" alt='");
219                 html.append(name);
220                 html.append("'");
221                 html.append(" title='");
222                 html.append(name);
223                 html.append("'");
224             }
225             html.append("style='width: 16px; height: 16px;' >");
226         }
227         html.append("</span>\n");
228         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(helpText) && !singleHelp) {
229             html.append("<div class='help' id='help");
230             html.append(helpId);
231             html.append("' onMouseOver=\"sMH('");
232             html.append(id);
233             html.append("');\" onMouseOut=\"hMH('");
234             html.append(id);
235             html.append("');\">");
236             html.append(helpText);
237             html.append("</div>\n");
238         }
239         return html.toString();
240     }
241 }
Popular Tags