KickJava   Java API By Example, From Geeks To Geeks.

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


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 Group 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 CmsGroupWidget extends A_CmsWidget {
49
50     /** Configuration parameter to set the flags of the groups to display, optional. */
51     public static final String JavaDoc CONFIGURATION_FLAGS = "flags";
52
53     /** Configuration parameter to set the user of the groups to display, optional. */
54     public static final String JavaDoc CONFIGURATION_USER = "user";
55
56     /** The the flags used in the popup window. */
57     private Integer JavaDoc m_flags;
58
59     /** The the user used in the popup window. */
60     private String JavaDoc m_userName;
61
62     /**
63      * Creates a new group selection widget.<p>
64      */

65     public CmsGroupWidget() {
66
67         // empty constructor is required for class registration
68
this("");
69     }
70
71     /**
72      * Creates a new group selection widget with the parameters to configure the popup window behaviour.<p>
73      *
74      * @param flags the group flags to restrict the group selection, can be <code>null</code>
75      * @param userName the user to restrict the group selection, can be <code>null</code>
76      */

77     public CmsGroupWidget(Integer JavaDoc flags, String JavaDoc userName) {
78
79         m_flags = flags;
80         m_userName = userName;
81     }
82
83     /**
84      * Creates a new group selection widget with the given configuration.<p>
85      *
86      * @param configuration the configuration to use
87      */

88     public CmsGroupWidget(String JavaDoc configuration) {
89
90         super(configuration);
91     }
92
93     /**
94      * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
95      */

96     public String JavaDoc getConfiguration() {
97
98         StringBuffer JavaDoc result = new StringBuffer JavaDoc(8);
99
100         // append flags to configuration
101
if (m_flags != null) {
102             if (result.length() > 0) {
103                 result.append("|");
104             }
105             result.append(CONFIGURATION_FLAGS);
106             result.append("=");
107             result.append(m_flags);
108         }
109         // append user to configuration
110
if (m_userName != null) {
111             if (result.length() > 0) {
112                 result.append("|");
113             }
114             result.append(CONFIGURATION_USER);
115             result.append("=");
116             result.append(m_userName);
117         }
118         return result.toString();
119     }
120
121     /**
122      * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
123      */

124     public String JavaDoc getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) {
125
126         StringBuffer JavaDoc result = new StringBuffer JavaDoc(16);
127         result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/groupselector.js"));
128         return result.toString();
129     }
130
131     /**
132      * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
133      */

134     public String JavaDoc getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
135
136         String JavaDoc id = param.getId();
137         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
138
139         result.append("<td class=\"xmlTd\">");
140         result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
141         result.append("<input style=\"width: 99%;\" class=\"xmlInput");
142         if (param.hasError()) {
143             result.append(" xmlInputError");
144         }
145         result.append("\" value=\"");
146         result.append(param.getStringValue(cms));
147         result.append("\" name=\"");
148         result.append(id);
149         result.append("\" id=\"");
150         result.append(id);
151         result.append("\"></td>");
152         result.append(widgetDialog.dialogHorizontalSpacer(10));
153         result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
154
155         StringBuffer JavaDoc buttonJs = new StringBuffer JavaDoc(8);
156         buttonJs.append("javascript:openGroupWin('");
157         buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext());
158         buttonJs.append("/system/workplace/commons/group_selection.jsp");
159         buttonJs.append("','EDITOR', '");
160         buttonJs.append(id);
161         buttonJs.append("', document, '");
162         if (m_flags != null) {
163             buttonJs.append(m_flags);
164         } else {
165             buttonJs.append("null");
166         }
167         buttonJs.append("', '");
168         if (m_userName != null) {
169             buttonJs.append(m_userName);
170         } else {
171             buttonJs.append("null");
172         }
173         buttonJs.append("'");
174         buttonJs.append(");");
175
176         result.append(widgetDialog.button(
177             buttonJs.toString(),
178             null,
179             "group",
180             org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
181             widgetDialog.getButtonStyle()));
182         result.append("</tr></table>");
183         result.append("</td></tr></table>");
184
185         result.append("</td>");
186
187         return result.toString();
188     }
189
190     /**
191      * Returns the flags, or <code>null</code> if all.<p>
192      *
193      * @return the flags, or <code>null</code> if all
194      */

195     public Integer JavaDoc getFlags() {
196
197         return m_flags;
198     }
199
200     /**
201      * Returns the user name, or <code>null</code> if all.<p>
202      *
203      * @return the user name
204      */

205     public String JavaDoc getUserName() {
206
207         return m_userName;
208     }
209
210     /**
211      * @see org.opencms.widgets.I_CmsWidget#newInstance()
212      */

213     public I_CmsWidget newInstance() {
214
215         return new CmsGroupWidget(getConfiguration());
216     }
217
218     /**
219      * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
220      */

221     public void setConfiguration(String JavaDoc configuration) {
222
223         m_userName = null;
224         m_flags = null;
225         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
226             int flagsIndex = configuration.indexOf(CONFIGURATION_FLAGS);
227             if (flagsIndex != -1) {
228                 // user is given
229
String JavaDoc flags = configuration.substring(CONFIGURATION_FLAGS.length() + 1);
230                 if (flags.indexOf('|') != -1) {
231                     // cut eventual following configuration values
232
flags = flags.substring(0, flags.indexOf('|'));
233                 }
234                 try {
235                     m_flags = Integer.valueOf(flags);
236                 } catch (Throwable JavaDoc t) {
237                     // invalid flags
238
}
239             }
240             int groupIndex = configuration.indexOf(CONFIGURATION_USER);
241             if (groupIndex != -1) {
242                 // user is given
243
String JavaDoc user = configuration.substring(CONFIGURATION_USER.length() + 1);
244                 if (user.indexOf('|') != -1) {
245                     // cut eventual following configuration values
246
user = user.substring(0, user.indexOf('|'));
247                 }
248                 m_userName = user;
249             }
250         }
251         super.setConfiguration(configuration);
252     }
253 }
Popular Tags