KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > widgets > CmsDisplayWidget


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsDisplayWidget.java,v $
3  * Date : $Date: 2006/03/27 14:52:19 $
4  * Version: $Revision: 1.12 $
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.widgets;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.i18n.CmsEncoder;
36 import org.opencms.main.OpenCms;
37 import org.opencms.util.CmsStringUtil;
38
39 import java.util.Set JavaDoc;
40
41 /**
42  * Provides a display only widget, for use on a widget dialog.<p>
43  *
44  * @author Michael Moossen
45  *
46  * @version $Revision: 1.12 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsDisplayWidget extends A_CmsWidget {
51
52     /** Key post fix, so you can display different help text if used a "normal" widget, and a display widget. */
53     private static final String JavaDoc DISABLED_POSTFIX = ".disabled";
54
55     /**
56      * Creates a new input widget.<p>
57      */

58     public CmsDisplayWidget() {
59
60         // empty constructor is required for class registration
61
this("");
62     }
63
64     /**
65      * Creates a new input widget with the given configuration.<p>
66      *
67      * @param configuration the configuration to use
68      */

69     public CmsDisplayWidget(String JavaDoc configuration) {
70
71         super(configuration);
72     }
73
74     /**
75      * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
76      */

77     public String JavaDoc getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
78
79         String JavaDoc id = param.getId();
80
81         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
82
83         result.append("<td class=\"xmlTd\">");
84         result.append("<span class=\"xmlInput textInput\" style=\"border: 0px solid black;\">");
85         if (CmsStringUtil.isNotEmpty(getConfiguration())) {
86             result.append(getConfiguration());
87         } else {
88             result.append(param.getStringValue(cms));
89         }
90         result.append("</span>");
91         result.append("<input type=\"hidden\"");
92         result.append(" name=\"");
93         result.append(id);
94         result.append("\" id=\"");
95         result.append(id);
96         result.append("\" value=\"");
97         result.append(CmsEncoder.escapeXml(param.getStringValue(cms)));
98         result.append("\">");
99         result.append("</td>");
100
101         return result.toString();
102     }
103
104     /**
105      * @see org.opencms.widgets.A_CmsWidget#getHelpBubble(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
106      */

107     public String JavaDoc getHelpBubble(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
108
109         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
110         String JavaDoc locKey = getDisabledHelpKey(param);
111         String JavaDoc locValue = widgetDialog.getMessages().key(locKey, true);
112         if (locValue == null) {
113             // there was no help message found for this key, so return a spacer cell
114
return widgetDialog.dialogHorizontalSpacer(16);
115         } else {
116             result.append("<td>");
117             result.append("<img name=\"img");
118             result.append(locKey);
119             result.append("\" id=\"img");
120             result.append(locKey);
121             result.append("\" SRC=\"");
122             result.append(OpenCms.getLinkManager().substituteLink(cms, "/system/workplace/resources/commons/help.png"));
123             result.append("\" alt=\"\" border=\"0\"");
124             if (widgetDialog.useNewStyle()) {
125                 result.append(getJsHelpMouseHandler(widgetDialog, locKey, null));
126             } else {
127                 result.append(getJsHelpMouseHandler(widgetDialog, locKey, CmsEncoder.escape(locValue, cms.getRequestContext().getEncoding())));
128             }
129             result.append("></td>");
130             return result.toString();
131         }
132     }
133
134     /**
135      * @see org.opencms.widgets.A_CmsWidget#getHelpText(org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
136      */

137     public String JavaDoc getHelpText(I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
138
139         String JavaDoc helpId = getDisabledHelpKey(param);
140         Set JavaDoc helpIdsShown = widgetDialog.getHelpMessageIds();
141         if (helpIdsShown.contains(helpId)) {
142             // help hey has already been included in output
143
return "";
144         }
145         helpIdsShown.add(helpId);
146         
147         // calculate the key
148
String JavaDoc locValue = widgetDialog.getMessages().key(helpId, true);
149         if (locValue == null) {
150             // there was no help message found for this key, so return an empty string
151
return "";
152         } else {
153             if (widgetDialog.useNewStyle()) {
154                 StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
155                 result.append("<div class=\"help\" id=\"help");
156                 result.append(helpId);
157                 result.append("\"");
158                 result.append(getJsHelpMouseHandler(widgetDialog, helpId, helpId));
159                 result.append(">");
160                 result.append(locValue);
161                 result.append("</div>\n");
162                 return result.toString();
163             } else {
164                 return "";
165             }
166         }
167     }
168
169     /**
170      * @see org.opencms.widgets.I_CmsWidget#newInstance()
171      */

172     public I_CmsWidget newInstance() {
173
174         return new CmsDisplayWidget(getConfiguration());
175     }
176
177     /**
178      * Returns the localized help key for the provided widget parameter.<p>
179      *
180      * @param param the widget parameter to return the localized help key for
181      *
182      * @return the localized help key for the provided widget parameter
183      */

184     private String JavaDoc getDisabledHelpKey(I_CmsWidgetParameter param) {
185
186         StringBuffer JavaDoc result = new StringBuffer JavaDoc(64);
187         result.append(LABEL_PREFIX);
188         result.append(param.getKey());
189         result.append(HELP_POSTFIX);
190         result.append(DISABLED_POSTFIX);
191         return result.toString();
192     }
193 }
Popular Tags