KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListExplorerDirectAction.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.jsp.CmsJspActionElement;
35 import org.opencms.util.CmsResourceUtil;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 import java.io.File JavaDoc;
40
41 /**
42  * Displays a 16x16 icon from the explorer view in a list action.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.2 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsListExplorerDirectAction extends CmsListDirectAction {
51
52     /** The current resource util object. */
53     private CmsResourceUtil m_resourceUtil;
54
55     /** The current workplace context. */
56     private A_CmsListExplorerDialog m_wp;
57
58     /**
59      * Default Constructor.<p>
60      *
61      * @param id the unique id
62      * @param wp the current workplace context
63      */

64     public CmsListExplorerDirectAction(String JavaDoc id, A_CmsListExplorerDialog wp) {
65
66         super(id);
67         m_wp = wp;
68     }
69
70     /**
71      * @see org.opencms.workplace.list.CmsListDirectAction#buttonHtml(org.opencms.workplace.CmsWorkplace)
72      */

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

96     public A_CmsListExplorerDialog getWp() {
97
98         return m_wp;
99     }
100
101     /**
102      * @see org.opencms.workplace.list.I_CmsListDirectAction#setItem(org.opencms.workplace.list.CmsListItem)
103      */

104     public void setItem(CmsListItem item) {
105
106         m_resourceUtil = m_wp.getResourceUtil(item);
107         super.setItem(item);
108     }
109
110     /**
111      * Sets the workplace dialog.<p>
112      *
113      * @param wp the workplace dialog
114      */

115     public void setWp(A_CmsListExplorerDialog wp) {
116
117         m_wp = wp;
118     }
119
120     /**
121      * Generates a default html code where several buttons can have the same help text.<p>
122      *
123      * 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>
124      * is that the icons are 16x16.<p>
125      *
126      * @param jsp the cms context, can be null
127      * @param id the id
128      * @param helpId the id of the helptext div tag
129      * @param name the name, if empty only the icon is displayed
130      * @param helpText the help text, if empty no mouse events are generated
131      * @param enabled if enabled or not, if not set be sure to take an according helptext
132      * @param iconPath the path to the icon, if empty only the name is displayed
133      * @param onClick the js code to execute, if empty no link is generated
134      * @param confirmationMessage the confirmation message
135      * @param singleHelp if set, no helptext is written, you have to use the defaultHelpHtml() method later
136      *
137      * @return html code
138      *
139      * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#defaultButtonHtml(CmsJspActionElement, org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum, String, String, String, boolean, String, String, String)
140      */

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

248     protected CmsResourceUtil getResourceUtil() {
249
250         return m_resourceUtil;
251     }
252 }
Popular Tags