KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/CmsComboWidget.java,v $
3  * Date : $Date: 2006/05/19 08:34:36 $
4  * Version: $Revision: 1.11 $
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.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 import java.util.Iterator JavaDoc;
40 import java.util.List JavaDoc;
41
42 /**
43  * Provides a HTML text input field with optional values to select in a combo box, for use on a widget dialog.<p>
44  *
45  * Please see the documentation of <code>{@link org.opencms.widgets.CmsSelectWidgetOption}</code> for a description
46  * about the configuration String syntax for the select options.<p>
47  *
48  * The combo widget does use the following select options:<ul>
49  * <li><code>{@link org.opencms.widgets.CmsSelectWidgetOption#getValue()}</code> for the texts to be displayed in the combo selector
50  * <li><code>{@link org.opencms.widgets.CmsSelectWidgetOption#isDefault()}</code> to fill the input with a preselected text
51  * <li><code>{@link org.opencms.widgets.CmsSelectWidgetOption#getHelp()}</code> to display an (optional) help text for the combo option
52  * </ul>
53  *
54  * @author Andreas Zahner
55  * @author Alexander Kandzior
56  *
57  * @version $Revision: 1.11 $
58  *
59  * @since 6.0.0
60  */

61 public class CmsComboWidget extends A_CmsSelectWidget {
62
63     /**
64      * Creates a new combo widget.<p>
65      */

66     public CmsComboWidget() {
67
68         // empty constructor is required for class registration
69
super();
70     }
71
72     /**
73      * Creates a combo widget with the select options specified in the given configuration List.<p>
74      *
75      * The list elements must be of type <code>{@link CmsSelectWidgetOption}</code>.<p>
76      *
77      * @param configuration the configuration (possible options) for the select widget
78      *
79      * @see CmsSelectWidgetOption
80      */

81     public CmsComboWidget(List JavaDoc configuration) {
82
83         super(configuration);
84     }
85
86     /**
87      * Creates a combo widget with the specified combo options.<p>
88      *
89      * @param configuration the configuration (possible options) for the combo box
90      */

91     public CmsComboWidget(String JavaDoc configuration) {
92
93         super(configuration);
94     }
95
96     /**
97      * @see org.opencms.widgets.A_CmsWidget#getDialogHtmlEnd(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
98      */

99     public String JavaDoc getDialogHtmlEnd(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
100
101         String JavaDoc id = param.getId();
102         StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
103
104         // get the select box options
105
List JavaDoc options = parseSelectOptions(cms, widgetDialog, param);
106
107         if (options.size() > 0) {
108             // create combo div
109
result.append("<div class=\"widgetcombo\" id=\"combo");
110             result.append(id);
111             result.append("\">\n");
112
113             int count = 0;
114             Iterator JavaDoc i = options.iterator();
115             while (i.hasNext()) {
116                 CmsSelectWidgetOption option = (CmsSelectWidgetOption)i.next();
117                 String JavaDoc itemId = new StringBuffer JavaDoc(64).append("ci").append(id).append('.').append(count).toString();
118                 // create the link around value
119
result.append("\t<a HREF=\"javascript:setComboValue(\'");
120                 result.append(id);
121                 result.append("\', \'");
122                 result.append(itemId);
123                 result.append("\')\" name=\"");
124                 result.append(itemId);
125                 result.append("\" id=\"");
126                 result.append(itemId);
127                 result.append("\"");
128                 if (option.getHelp() != null) {
129                     // create help text mousevent attributes
130
// can't use method in CmsEncoder because we need to keep < > for HTML in help text
131
String JavaDoc locValue = CmsStringUtil.substitute(option.getHelp(), "\"", "&quot;");
132                     result.append(getJsHelpMouseHandler(widgetDialog, itemId, CmsStringUtil.escapeJavaScript(locValue)));
133                 }
134                 result.append(">");
135                 result.append(option.getValue());
136                 result.append("</a>\n");
137                 count++;
138             }
139
140             // close combo div
141
result.append("</div>\n");
142
143             if (widgetDialog.useNewStyle()) {
144                 // create help texts for the values in admin view
145
count = 0;
146                 i = options.iterator();
147                 while (i.hasNext()) {
148                     CmsSelectWidgetOption option = (CmsSelectWidgetOption)i.next();
149                     if (option.getHelp() != null) {
150                         // help text is optional
151
String JavaDoc itemId = new StringBuffer JavaDoc(64).append("ci").append(id).append('.').append(count).toString();
152                         result.append("<div class=\"help\" id=\"help");
153                         result.append(itemId);
154                         result.append("\"");
155                         result.append(getJsHelpMouseHandler(widgetDialog, itemId, itemId));
156                         result.append(">");
157                         result.append(option.getHelp());
158                         result.append("</div>\n");
159                         count++;
160                     }
161                 }
162             }
163         }
164
165         // return the icon help text from super class
166
result.append(super.getDialogHtmlEnd(cms, widgetDialog, param));
167         return result.toString();
168     }
169
170     /**
171      * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
172      */

173     public String JavaDoc getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
174
175         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
176         result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/combobox.js"));
177         return result.toString();
178     }
179
180     /**
181      * @see org.opencms.widgets.I_CmsWidget#getDialogInitCall(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
182      */

183     public String JavaDoc getDialogInitCall(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
184
185         return "\tinitComboBox();\n";
186     }
187
188     /**
189      * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
190      */

191     public String JavaDoc getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
192
193         String JavaDoc id = param.getId();
194         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
195         result.append("<td class=\"xmlTd\">");
196
197         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>");
198         // medium text input field
199
result.append("<input type=\"text\" class=\"xmlInputMedium");
200         if (param.hasError()) {
201             result.append(" xmlInputError");
202         }
203         result.append("\" name=\"");
204         result.append(id);
205         result.append("\" id=\"");
206         result.append(id);
207         result.append("\"");
208         String JavaDoc selected = getSelectedValue(cms, param);
209         if (selected != null) {
210             // append the selection
211
result.append(" value=\"");
212             result.append(CmsEncoder.escapeXml(selected));
213             result.append("\"");
214         }
215         result.append(">");
216         result.append("</td><td>");
217         // button to open combo box
218
result.append("<button name=\"test\" onclick=\"showCombo(\'").append(id).append("\', \'combo").append(id);
219         result.append("\');return false;\" class=\"widgetcombobutton\">");
220         result.append("<img SRC=\"");
221         result.append(CmsWorkplace.getSkinUri()).append("components/widgets/combo.png");
222         result.append("\" width=\"7\" height=\"12\" alt=\"\" border=\"0\">");
223         result.append("</button></td></tr></table>");
224
225         result.append("</td>");
226         return result.toString();
227     }
228
229     /**
230      * @see org.opencms.widgets.I_CmsWidget#newInstance()
231      */

232     public I_CmsWidget newInstance() {
233
234         return new CmsComboWidget(getConfiguration());
235     }
236 }
Popular Tags