KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source$
3  * Date : $Date$
4  * Version: $Revision$
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.main.OpenCms;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.workplace.CmsWorkplace;
38
39 /**
40  * Provides a OpenCms User selection widget, for use on a widget dialog.<p>
41  *
42  * @author Michael Moossen
43  *
44  * @version $Revision$
45  *
46  * @since 6.0.0
47  */

48 public class CmsUserWidget extends A_CmsWidget {
49
50     /** Configuration parameter to set the flags of the users to display, optional. */
51     public static final String JavaDoc CONFIGURATION_FLAGS = "flags";
52
53     /** Configuration parameter to set the group of users to display, optional. */
54     public static final String JavaDoc CONFIGURATION_GROUP = "group";
55
56     /** Configuration parameter to set the user type to select in the popup user selection dialog. */
57     public static final String JavaDoc CONFIGURATION_USERTYPE = "usertype";
58
59     /** The the flags used in the popup window. */
60     private Integer JavaDoc m_flags;
61
62     /** The the group used in the popup window. */
63     private String JavaDoc m_groupName;
64
65     /** The user type used in the popup window. */
66     private Integer JavaDoc m_userType;
67
68     /**
69      * Creates a new user selection widget.<p>
70      */

71     public CmsUserWidget() {
72
73         // empty constructor is required for class registration
74
this("");
75     }
76
77     /**
78      * Creates a new user selection widget with the parameters to configure the popup window behaviour.<p>
79      *
80      * @param flags the group flags to restrict the group selection, can be <code>null</code>
81      * @param userType the type of the users to display, can be <code>null</code>
82      * @param groupName the group to restrict the user selection, can be <code>null</code>
83      */

84     public CmsUserWidget(Integer JavaDoc flags, Integer JavaDoc userType, String JavaDoc groupName) {
85
86         m_flags = flags;
87         m_userType = userType;
88         m_groupName = groupName;
89     }
90
91     /**
92      * Creates a new user selection widget with the given configuration.<p>
93      *
94      * @param configuration the configuration to use
95      */

96     public CmsUserWidget(String JavaDoc configuration) {
97
98         super(configuration);
99     }
100
101     /**
102      * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
103      */

104     public String JavaDoc getConfiguration() {
105
106         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
107
108         // append flags to configuration
109
if (m_flags != null) {
110             if (result.length() > 0) {
111                 result.append("|");
112             }
113             result.append(CONFIGURATION_FLAGS);
114             result.append("=");
115             result.append(m_flags);
116         }
117         // append user type to configuration
118
if (m_userType != null) {
119             if (result.length() > 0) {
120                 result.append("|");
121             }
122             result.append(CONFIGURATION_USERTYPE);
123             result.append("=");
124             result.append(m_userType.intValue());
125         }
126         // append group to configuration
127
if (m_groupName != null) {
128             if (result.length() > 0) {
129                 result.append("|");
130             }
131             result.append(CONFIGURATION_GROUP);
132             result.append("=");
133             result.append(m_groupName);
134         }
135
136         return result.toString();
137     }
138
139     /**
140      * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
141      */

142     public String JavaDoc getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
143
144         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
145         result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/userselector.js"));
146         return result.toString();
147     }
148
149     /**
150      * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
151      */

152     public String JavaDoc getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
153
154         String JavaDoc id = param.getId();
155         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
156
157         result.append("<td class=\"xmlTd\">");
158         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
159         result.append("<input style=\"width: 99%;\" class=\"xmlInput");
160         if (param.hasError()) {
161             result.append(" xmlInputError");
162         }
163         result.append("\" value=\"");
164         result.append(param.getStringValue(cms));
165         result.append("\" name=\"");
166         result.append(id);
167         result.append("\" id=\"");
168         result.append(id);
169         result.append("\"></td>");
170         result.append(widgetDialog.dialogHorizontalSpacer(10));
171         result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
172
173         StringBuffer JavaDoc buttonJs = new StringBuffer JavaDoc(8);
174         buttonJs.append("javascript:openUserWin('");
175         buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext());
176         buttonJs.append("/system/workplace/commons/user_selection.jsp");
177         buttonJs.append("','EDITOR', '");
178         buttonJs.append(id);
179         buttonJs.append("', document, '");
180         if (m_flags != null) {
181             buttonJs.append(m_flags);
182         } else {
183             buttonJs.append("null");
184         }
185         buttonJs.append("', '");
186         if (m_groupName != null) {
187             buttonJs.append(m_groupName);
188         } else {
189             buttonJs.append("null");
190         }
191         buttonJs.append("', '");
192         if (m_userType != null) {
193             buttonJs.append(m_userType.intValue());
194         } else {
195             buttonJs.append("null");
196         }
197         buttonJs.append("'");
198         buttonJs.append(");");
199
200         result.append(widgetDialog.button(
201             buttonJs.toString(),
202             null,
203             "user",
204             org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
205             widgetDialog.getButtonStyle()));
206         result.append("</tr></table>");
207         result.append("</td></tr></table>");
208
209         result.append("</td>");
210
211         return result.toString();
212     }
213
214     /**
215      * Returns the flags, or <code>null</code> if all.<p>
216      *
217      * @return the flags, or <code>null</code> if all
218      */

219     public Integer JavaDoc getFlags() {
220
221         return m_flags;
222     }
223
224     /**
225      * Returns the group name, or <code>null</code> if all.<p>
226      *
227      * @return the group name, or <code>null</code> if all
228      */

229     public String JavaDoc getGroupName() {
230
231         return m_groupName;
232     }
233
234     /**
235      * Returns the user Type, or <code>null</code> if all.<p>
236      *
237      * @return the user Type, or <code>null</code> if all
238      */

239     public Integer JavaDoc getUserType() {
240
241         return m_userType;
242     }
243
244     /**
245      * @see org.opencms.widgets.I_CmsWidget#newInstance()
246      */

247     public I_CmsWidget newInstance() {
248
249         return new CmsUserWidget(getConfiguration());
250     }
251
252     /**
253      * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
254      */

255     public void setConfiguration(String JavaDoc configuration) {
256
257         m_groupName = null;
258         m_userType = null;
259         m_flags = null;
260         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
261             int flagsIndex = configuration.indexOf(CONFIGURATION_FLAGS);
262             if (flagsIndex != -1) {
263                 // user is given
264
String JavaDoc flags = configuration.substring(CONFIGURATION_FLAGS.length() + 1);
265                 if (flags.indexOf('|') != -1) {
266                     // cut eventual following configuration values
267
flags = flags.substring(0, flags.indexOf('|'));
268                 }
269                 try {
270                     m_flags = Integer.valueOf(flags);
271                 } catch (Throwable JavaDoc t) {
272                     // invalid flags
273
}
274             }
275             int typeIndex = configuration.indexOf(CONFIGURATION_USERTYPE);
276             if (typeIndex != -1) {
277                 // user type is given
278
String JavaDoc type = configuration.substring(CONFIGURATION_USERTYPE.length() + 1);
279                 if (type.indexOf('|') != -1) {
280                     // cut eventual following configuration values
281
type = type.substring(0, type.indexOf('|'));
282                 }
283                 try {
284                     m_userType = Integer.valueOf(type);
285                 } catch (Throwable JavaDoc t) {
286                     // invalid flags
287
}
288             }
289             int groupIndex = configuration.indexOf(CONFIGURATION_GROUP);
290             if (groupIndex != -1) {
291                 // group is given
292
String JavaDoc group = configuration.substring(CONFIGURATION_GROUP.length() + 1);
293                 if (group.indexOf('|') != -1) {
294                     // cut eventual following configuration values
295
group = group.substring(0, group.indexOf('|'));
296                 }
297                 m_groupName = group;
298             }
299         }
300         super.setConfiguration(configuration);
301     }
302 }
Popular Tags