KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/list/CmsListDirectAction.java,v $
3  * Date : $Date: 2006/03/27 14:52:28 $
4  * Version: $Revision: 1.19 $
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.util.CmsStringUtil;
35 import org.opencms.workplace.CmsWorkplace;
36 import org.opencms.workplace.tools.A_CmsHtmlIconButton;
37 import org.opencms.workplace.tools.CmsHtmlIconButtonStyleEnum;
38
39 import java.text.MessageFormat JavaDoc;
40 import java.util.Locale JavaDoc;
41
42 /**
43  * Default implementation of a direct action for a html list column.<p>
44  *
45  * @author Michael Moossen
46  *
47  * @version $Revision: 1.19 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsListDirectAction extends A_CmsListAction implements I_CmsListDirectAction {
52
53     /** Id of the Column to use when setting param in help and conf texts. */
54     private String JavaDoc m_columnForTexts;
55
56     /** List item. */
57     private CmsListItem m_listItem;
58
59     /**
60      * Default Constructor.<p>
61      *
62      * @param id unique id
63      */

64     public CmsListDirectAction(String JavaDoc id) {
65
66         super(id);
67     }
68
69     /**
70      * Help method to resolve the help text to use.<p>
71      *
72      * @param locale the used locale
73      *
74      * @return the help text
75      */

76     protected String JavaDoc resolveHelpText(Locale JavaDoc locale) {
77
78         String JavaDoc helpText = getHelpText().key(locale);
79         if (getColumnForTexts() != null && getItem().get(getColumnForTexts()) != null) {
80             helpText = new MessageFormat JavaDoc(helpText, locale).format(new Object JavaDoc[] {getItem().get(getColumnForTexts())});
81         }
82         return helpText;
83     }
84
85     /**
86      * Help method to resolve the on clic text to use.<p>
87      *
88      * @param locale the used locale
89      *
90      * @return the on clic text
91      */

92     protected String JavaDoc resolveOnClic(Locale JavaDoc locale) {
93
94         String JavaDoc confirmationMessage = getConfirmationMessage().key(locale);
95         if (getColumnForTexts() != null && getItem().get(getColumnForTexts()) != null) {
96             confirmationMessage = new MessageFormat JavaDoc(confirmationMessage, locale).format(new Object JavaDoc[] {getItem().get(
97                 getColumnForTexts())});
98         }
99         StringBuffer JavaDoc onClic = new StringBuffer JavaDoc(128);
100         onClic.append("listAction('");
101         onClic.append(getListId());
102         onClic.append("', '");
103         onClic.append(getId());
104         onClic.append("', '");
105         if (getColumnForTexts() == null
106             || getItem().get(getColumnForTexts()) == null
107             || confirmationMessage.equals(new MessageFormat JavaDoc(confirmationMessage, locale).format(new Object JavaDoc[] {""}))) {
108             onClic.append("conf" + getId());
109         } else {
110             onClic.append(CmsStringUtil.escapeJavaScript(confirmationMessage));
111         }
112         onClic.append("', '");
113         onClic.append(CmsStringUtil.escapeJavaScript(getItem().getId()));
114         onClic.append("');");
115         return onClic.toString();
116     }
117
118     /**
119      * Help method to resolve the name to use.<p>
120      *
121      * @param locale the used locale
122      *
123      * @return the name
124      */

125     protected String JavaDoc resolveName(Locale JavaDoc locale) {
126
127         return getName().key(locale);
128     }
129
130     /**
131      * Help method to resolve the style of the button.<p>
132      *
133      * @return the style of the button
134      */

135     protected CmsHtmlIconButtonStyleEnum resolveButtonStyle() {
136         
137         return CmsHtmlIconButtonStyleEnum.SMALL_ICON_ONLY;
138     }
139     
140     /**
141      * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(CmsWorkplace)
142      */

143     public String JavaDoc buttonHtml(CmsWorkplace wp) {
144
145         if (!isVisible()) {
146             return "";
147         }
148         return A_CmsHtmlIconButton.defaultButtonHtml(
149             wp.getJsp(),
150             resolveButtonStyle(),
151             getId() + getItem().getId(),
152             getId(),
153             resolveName(wp.getLocale()),
154             resolveHelpText(wp.getLocale()),
155             isEnabled(),
156             getIconPath(),
157             null,
158             resolveOnClic(wp.getLocale()),
159             getColumnForTexts() == null);
160     }
161
162     /**
163      * @see org.opencms.workplace.list.I_CmsListDirectAction#confirmationTextHtml(org.opencms.workplace.CmsWorkplace)
164      */

165     public String JavaDoc confirmationTextHtml(CmsWorkplace wp) {
166
167         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
168         String JavaDoc cm = getConfirmationMessage().key(wp.getLocale());
169         String JavaDoc confMessage = new MessageFormat JavaDoc(cm, wp.getLocale()).format(new Object JavaDoc[] {""});
170         if (getColumnForTexts() == null
171             || confMessage.equals(new MessageFormat JavaDoc(cm, wp.getLocale()).format(new Object JavaDoc[] {getItem().get(getColumnForTexts())}))) {
172             html.append(A_CmsListAction.defaultConfirmationHtml(getId(), confMessage));
173         }
174         return html.toString();
175     }
176
177     /**
178      * @see org.opencms.workplace.list.I_CmsListDirectAction#getColumnForTexts()
179      */

180     public String JavaDoc getColumnForTexts() {
181
182         return m_columnForTexts;
183     }
184
185     /**
186      * @see org.opencms.workplace.list.I_CmsListDirectAction#getItem()
187      */

188     public CmsListItem getItem() {
189
190         return m_listItem;
191     }
192
193     /**
194      * @see org.opencms.workplace.list.I_CmsListDirectAction#helpTextHtml(org.opencms.workplace.CmsWorkplace)
195      */

196     public String JavaDoc helpTextHtml(CmsWorkplace wp) {
197
198         StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
199         String JavaDoc ht = getHelpText().key(wp.getLocale());
200         String JavaDoc helptext = new MessageFormat JavaDoc(ht, wp.getLocale()).format(new Object JavaDoc[] {""});
201         if (getColumnForTexts() == null
202             || helptext.equals(new MessageFormat JavaDoc(ht, wp.getLocale()).format(new Object JavaDoc[] {getItem().get(getColumnForTexts())}))) {
203             html.append(A_CmsHtmlIconButton.defaultHelpHtml(getId(), helptext));
204         }
205         return html.toString();
206     }
207
208     /**
209      * @see org.opencms.workplace.list.I_CmsListDirectAction#setColumnForTexts(java.lang.String)
210      */

211     public void setColumnForTexts(String JavaDoc columnId) {
212
213         m_columnForTexts = columnId;
214     }
215
216     /**
217      * @see org.opencms.workplace.list.I_CmsListDirectAction#setItem(org.opencms.workplace.list.CmsListItem)
218      */

219     public void setItem(CmsListItem item) {
220
221         m_listItem = item;
222     }
223
224 }
Popular Tags