KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsUserSelectionList


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.workplace.commons;
33
34 import org.opencms.file.CmsUser;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsRuntimeException;
38 import org.opencms.security.CmsPrincipal;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.workplace.list.A_CmsListDefaultJsAction;
41 import org.opencms.workplace.list.A_CmsListDialog;
42 import org.opencms.workplace.list.CmsListColumnAlignEnum;
43 import org.opencms.workplace.list.CmsListColumnDefinition;
44 import org.opencms.workplace.list.CmsListDefaultAction;
45 import org.opencms.workplace.list.CmsListDirectAction;
46 import org.opencms.workplace.list.CmsListItem;
47 import org.opencms.workplace.list.CmsListMetadata;
48 import org.opencms.workplace.list.CmsListOrderEnum;
49 import org.opencms.workplace.tools.CmsToolMacroResolver;
50
51 import java.util.ArrayList JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.List JavaDoc;
54
55 import javax.servlet.http.HttpServletRequest JavaDoc;
56 import javax.servlet.http.HttpServletResponse JavaDoc;
57 import javax.servlet.jsp.PageContext JavaDoc;
58
59 /**
60  * User selection dialog.<p>
61  *
62  * @author Michael Moossen
63  *
64  * @version $Revision$
65  *
66  * @since 6.0.0
67  */

68 public class CmsUserSelectionList extends A_CmsListDialog {
69
70     /** list action id constant. */
71     public static final String JavaDoc LIST_ACTION_ICON = "ai";
72
73     /** list action id constant. */
74     public static final String JavaDoc LIST_ACTION_SELECT = "js";
75
76     /** list column id constant. */
77     public static final String JavaDoc LIST_COLUMN_FULLNAME = "cf";
78
79     /** list column id constant. */
80     public static final String JavaDoc LIST_COLUMN_ICON = "ci";
81
82     /** list column id constant. */
83     public static final String JavaDoc LIST_COLUMN_LOGIN = "cn";
84
85     /** list id constant. */
86     public static final String JavaDoc LIST_ID = "lus";
87
88     /** Stores the value of the request parameter for the group name. */
89     private String JavaDoc m_paramGroup;
90
91     /** Stores the value of the request parameter for the user type. */
92     private String JavaDoc m_paramUsertype;
93
94     /** Stores the value of the request parameter for the flags. */
95     private String JavaDoc m_paramFlags;
96
97     /**
98      * Public constructor.<p>
99      *
100      * @param jsp an initialized JSP action element
101      */

102     public CmsUserSelectionList(CmsJspActionElement jsp) {
103
104         super(
105             jsp,
106             LIST_ID,
107             Messages.get().container(Messages.GUI_USERSELECTION_LIST_NAME_0),
108             LIST_COLUMN_LOGIN,
109             CmsListOrderEnum.ORDER_ASCENDING,
110             LIST_COLUMN_LOGIN);
111     }
112
113     /**
114      * Public constructor with JSP variables.<p>
115      *
116      * @param context the JSP page context
117      * @param req the JSP request
118      * @param res the JSP response
119      */

120     public CmsUserSelectionList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
121
122         this(new CmsJspActionElement(context, req, res));
123     }
124
125     /**
126      * @see org.opencms.workplace.tools.CmsToolDialog#dialogTitle()
127      */

128     public String JavaDoc dialogTitle() {
129
130         // build title
131
StringBuffer JavaDoc html = new StringBuffer JavaDoc(512);
132         html.append("<div class='screenTitle'>\n");
133         html.append("\t<table width='100%' cellspacing='0'>\n");
134         html.append("\t\t<tr>\n");
135         html.append("\t\t\t<td>\n");
136         String JavaDoc param = "";
137         if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamGroup())) {
138             param = Messages.get().getBundle(getLocale()).key(Messages.GUI_USERSELECTION_GROUP_BLOCK_1, getParamGroup());
139         } else if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamUsertype())) {
140             if (Integer.parseInt(getParamUsertype()) == CmsUser.USER_TYPE_WEBUSER) {
141                 param = Messages.get().getBundle(getLocale()).key(Messages.GUI_USERSELECTION_TYPE_WEB_0);
142             } else {
143                 param = Messages.get().getBundle(getLocale()).key(Messages.GUI_USERSELECTION_TYPE_SYSTEM_0);
144             }
145         }
146         html.append(key(Messages.GUI_USERSELECTION_INTRO_TITLE_1, new Object JavaDoc[] {param}));
147         html.append("\n\t\t\t</td>");
148         html.append("\t\t</tr>\n");
149         html.append("\t</table>\n");
150         html.append("</div>\n");
151         return CmsToolMacroResolver.resolveMacros(html.toString(), this);
152     }
153
154     /**
155      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
156      */

157     public void executeListMultiActions() throws CmsRuntimeException {
158
159         throwListUnsupportedActionException();
160     }
161
162     /**
163      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
164      */

165     public void executeListSingleActions() throws CmsRuntimeException {
166
167         throwListUnsupportedActionException();
168     }
169
170     /**
171      * Returns the Group name parameter value.<p>
172      *
173      * @return the Group name parameter value
174      */

175     public String JavaDoc getParamGroup() {
176
177         return m_paramGroup;
178     }
179
180     /**
181      * Returns the user type parameter value.<p>
182      *
183      * @return the user type parameter value
184      */

185     public String JavaDoc getParamUsertype() {
186
187         return m_paramUsertype;
188     }
189
190     /**
191      * Returns the flags parameter value.<p>
192      *
193      * @return the flags parameter value
194      */

195     public String JavaDoc getParamFlags() {
196
197         return m_paramFlags;
198     }
199
200     /**
201      * Sets the group name parameter value.<p>
202      *
203      * @param groupName the group name parameter value to set
204      */

205     public void setParamGroup(String JavaDoc groupName) {
206
207         m_paramGroup = groupName;
208     }
209
210     /**
211      * Sets the user type parameter value.<p>
212      *
213      * @param userType the user type parameter value to set
214      */

215     public void setParamUsertype(String JavaDoc userType) {
216
217         m_paramUsertype = userType;
218     }
219
220     /**
221      * Sets the flags parameter value.<p>
222      *
223      * @param flags the flags parameter value to set
224      */

225     public void setParamFlags(String JavaDoc flags) {
226
227         m_paramFlags = flags;
228     }
229
230     /**
231      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
232      */

233     protected void fillDetails(String JavaDoc detailId) {
234
235         // noop
236
}
237
238     /**
239      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
240      */

241     protected List JavaDoc getListItems() throws CmsException {
242
243         List JavaDoc ret = new ArrayList JavaDoc();
244
245         // get content
246
List JavaDoc users = getUsers();
247         Iterator JavaDoc itUsers = users.iterator();
248         while (itUsers.hasNext()) {
249             CmsUser user = (CmsUser)itUsers.next();
250             CmsListItem item = getList().newItem(user.getId().toString());
251             item.set(LIST_COLUMN_LOGIN, user.getName());
252             item.set(LIST_COLUMN_FULLNAME, user.getFullName());
253             ret.add(item);
254         }
255
256         return ret;
257     }
258
259     /**
260      * Returns the list of users for selection.<p>
261      *
262      * @return a list of users
263      *
264      * @throws CmsException if womething goes wrong
265      */

266     protected List JavaDoc getUsers() throws CmsException {
267
268         List JavaDoc ret = new ArrayList JavaDoc();
269         if (getParamGroup() != null) {
270             ret.addAll(getCms().getUsersOfGroup(getParamGroup()));
271         } else if (getParamUsertype() == null) {
272             ret.addAll(getCms().getUsers());
273         } else {
274             ret.addAll(getCms().getUsers(Integer.parseInt(getParamUsertype())));
275         }
276         if (getParamFlags() != null) {
277             int flags = Integer.parseInt(getParamFlags());
278             return CmsPrincipal.filterFlag(ret, flags);
279         }
280         return ret;
281     }
282     
283     /**
284      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
285      */

286     protected void setColumns(CmsListMetadata metadata) {
287
288         // create column for icon display
289
CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
290         iconCol.setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_COLS_ICON_0));
291         iconCol.setHelpText(Messages.get().container(Messages.GUI_USERSELECTION_LIST_COLS_ICON_HELP_0));
292         iconCol.setWidth("20");
293         iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
294         iconCol.setSorteable(false);
295         // set icon action
296
CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON);
297         iconAction.setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_ICON_NAME_0));
298         iconAction.setHelpText(Messages.get().container(Messages.GUI_USERSELECTION_LIST_ICON_HELP_0));
299         iconAction.setIconPath("buttons/user.png");
300         iconAction.setEnabled(false);
301         iconCol.addDirectAction(iconAction);
302         // add it to the list definition
303
metadata.addColumn(iconCol);
304
305         // create column for login
306
CmsListColumnDefinition loginCol = new CmsListColumnDefinition(LIST_COLUMN_LOGIN);
307         loginCol.setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_COLS_LOGIN_0));
308         loginCol.setWidth("35%");
309         CmsListDefaultAction selectAction = new A_CmsListDefaultJsAction(LIST_ACTION_SELECT) {
310
311             /**
312              * @see org.opencms.workplace.list.A_CmsListDirectJsAction#jsCode()
313              */

314             public String JavaDoc jsCode() {
315
316                 return "window.opener.setUserFormValue('"
317                     + getItem().get(LIST_COLUMN_LOGIN)
318                     + "'); window.opener.focus(); window.close();";
319             }
320         };
321         selectAction.setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_ACTION_SELECT_NAME_0));
322         selectAction.setHelpText(Messages.get().container(Messages.GUI_USERSELECTION_LIST_ACTION_SELECT_HELP_0));
323         loginCol.addDefaultAction(selectAction);
324         // add it to the list definition
325
metadata.addColumn(loginCol);
326
327         // create column for fullname
328
CmsListColumnDefinition fullnameCol = new CmsListColumnDefinition(LIST_COLUMN_FULLNAME);
329         fullnameCol.setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_COLS_FULLNAME_0));
330         fullnameCol.setWidth("65%");
331         fullnameCol.setTextWrapping(true);
332         // add it to the list definition
333
metadata.addColumn(fullnameCol);
334     }
335
336     /**
337      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
338      */

339     protected void setIndependentActions(CmsListMetadata metadata) {
340
341         // no-op
342
}
343
344     /**
345      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
346      */

347     protected void setMultiActions(CmsListMetadata metadata) {
348
349         // no-op
350
}
351
352     /**
353      * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
354      */

355     protected void validateParamaters() throws Exception JavaDoc {
356
357         try {
358             getCms().readGroup(getParamGroup()).getName();
359         } catch (Exception JavaDoc e) {
360             setParamGroup(null);
361         }
362         try {
363             Integer.valueOf(getParamUsertype());
364         } catch (Throwable JavaDoc e) {
365             setParamUsertype(null);
366         }
367         try {
368             Integer.valueOf(getParamFlags());
369         } catch (Throwable JavaDoc e) {
370             setParamFlags(null);
371         }
372     }
373 }
Popular Tags