KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > accounts > CmsUserGroupsList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsUserGroupsList.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.10 $
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.tools.accounts;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsRuntimeException;
38 import org.opencms.workplace.list.A_CmsListDialog;
39 import org.opencms.workplace.list.CmsHtmlList;
40 import org.opencms.workplace.list.CmsListColumnAlignEnum;
41 import org.opencms.workplace.list.CmsListColumnDefinition;
42 import org.opencms.workplace.list.CmsListDirectAction;
43 import org.opencms.workplace.list.CmsListItem;
44 import org.opencms.workplace.list.CmsListItemActionIconComparator;
45 import org.opencms.workplace.list.CmsListMetadata;
46 import org.opencms.workplace.list.CmsListMultiAction;
47 import org.opencms.workplace.list.I_CmsListDirectAction;
48
49 import java.util.HashSet JavaDoc;
50 import java.util.Iterator JavaDoc;
51 import java.util.List JavaDoc;
52 import java.util.Set JavaDoc;
53
54 import javax.servlet.http.HttpServletRequest JavaDoc;
55 import javax.servlet.http.HttpServletResponse JavaDoc;
56 import javax.servlet.jsp.PageContext JavaDoc;
57
58 /**
59  * User groups view.<p>
60  *
61  * @author Michael Moossen
62  *
63  * @version $Revision: 1.10 $
64  *
65  * @since 6.0.0
66  */

67 public class CmsUserGroupsList extends A_CmsUserGroupsList {
68
69     /** list action id constant. */
70     public static final String JavaDoc LIST_ACTION_REMOVE = "ar";
71
72     /** list action id constant. */
73     public static final String JavaDoc LIST_DEFACTION_REMOVE = "dr";
74
75     /** list id constant. */
76     public static final String JavaDoc LIST_ID = "lug";
77
78     /** list action id constant. */
79     public static final String JavaDoc LIST_MACTION_REMOVE = "mr";
80
81     /** a set of action id's to use for removing. */
82     protected static Set JavaDoc m_removeActionIds = new HashSet JavaDoc();
83     
84     /**
85      * Public constructor.<p>
86      *
87      * @param jsp an initialized JSP action element
88      */

89     public CmsUserGroupsList(CmsJspActionElement jsp) {
90
91         this(jsp, LIST_ID);
92     }
93
94     /**
95      * Public constructor with JSP variables.<p>
96      *
97      * @param context the JSP page context
98      * @param req the JSP request
99      * @param res the JSP response
100      */

101     public CmsUserGroupsList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
102
103         this(new CmsJspActionElement(context, req, res));
104     }
105
106     /**
107      * Public constructor.<p>
108      *
109      * @param jsp an initialized JSP action element
110      * @param listId the id of the list
111      */

112     protected CmsUserGroupsList(CmsJspActionElement jsp, String JavaDoc listId) {
113
114         super(jsp, listId, Messages.get().container(Messages.GUI_USERGROUPS_LIST_NAME_0), true);
115     }
116
117     /**
118      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
119      */

120     public void executeListMultiActions() throws CmsRuntimeException {
121
122         if (getParamListAction().equals(LIST_MACTION_REMOVE)) {
123             // execute the remove multiaction
124
Iterator JavaDoc itItems = getSelectedItems().iterator();
125             while (itItems.hasNext()) {
126                 CmsListItem listItem = (CmsListItem)itItems.next();
127                 String JavaDoc groupName = (String JavaDoc)listItem.get(LIST_COLUMN_NAME);
128                 boolean directGroup = false;
129                 try {
130                     Iterator JavaDoc it = getCms().getDirectGroupsOfUser(getParamUsername()).iterator();
131                     while (it.hasNext()) {
132                         CmsGroup group = (CmsGroup)it.next();
133                         if (group.getName().equals(groupName)) {
134                             directGroup = true;
135                             break;
136                         }
137                     }
138                     if (directGroup) {
139                         getCms().removeUserFromGroup(getParamUsername(), groupName);
140                     }
141                 } catch (CmsException e) {
142                     // could be an indirectly assigned group
143
}
144             }
145         } else {
146             throwListUnsupportedActionException();
147         }
148         listSave();
149     }
150
151     /**
152      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
153      */

154     public void executeListSingleActions() throws CmsRuntimeException {
155
156         if (m_removeActionIds.contains(getParamListAction())) {
157             CmsListItem listItem = getSelectedItem();
158             try {
159                 getCms().removeUserFromGroup(getParamUsername(), (String JavaDoc)listItem.get(LIST_COLUMN_NAME));
160             } catch (CmsException e) {
161                 // should never happen
162
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_REMOVE_SELECTED_GROUP_0), e);
163             }
164         } else {
165             throwListUnsupportedActionException();
166         }
167         listSave();
168     }
169
170     /**
171      * @see org.opencms.workplace.list.A_CmsListDialog#getList()
172      */

173     public CmsHtmlList getList() {
174
175         // assure we have the right username
176
CmsHtmlList list = super.getList();
177         if (list != null) {
178             CmsListColumnDefinition col = list.getMetadata().getColumnDefinition(LIST_COLUMN_STATE);
179             if (col != null) {
180                 Iterator JavaDoc itDirectActions = col.getDirectActions().iterator();
181                 while (itDirectActions.hasNext()) {
182                     I_CmsListDirectAction action = (I_CmsListDirectAction)itDirectActions.next();
183                     if (action != null && action instanceof CmsGroupRemoveAction) {
184                         ((CmsGroupRemoveAction)action).setUserName(getParamUsername());
185                     }
186                 }
187             }
188             CmsListColumnDefinition col2 = list.getMetadata().getColumnDefinition(LIST_COLUMN_NAME);
189             if (col2 != null) {
190                 Iterator JavaDoc itDefaultActions = col2.getDefaultActions().iterator();
191                 while (itDefaultActions.hasNext()) {
192                     I_CmsListDirectAction action = (I_CmsListDirectAction)itDefaultActions.next();
193                     if (action != null && action instanceof CmsGroupRemoveAction) {
194                         ((CmsGroupRemoveAction)action).setUserName(getParamUsername());
195                     }
196                 }
197             }
198         }
199         return list;
200     }
201
202     /**
203      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#getGroups()
204      */

205     protected List getGroups() throws CmsException {
206
207         return getCms().getGroupsOfUser(getParamUsername());
208     }
209
210     /**
211      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
212      */

213     protected void setDefaultAction(CmsListColumnDefinition nameCol) {
214
215         // add default remove action for direct groups
216
CmsGroupRemoveAction removeAction = new CmsGroupRemoveAction(LIST_DEFACTION_REMOVE, getCms(), true);
217         removeAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0));
218         removeAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0));
219         nameCol.addDefaultAction(removeAction);
220
221         // add default remove action for indirect groups
222
CmsGroupRemoveAction indirRemoveAction = new CmsGroupRemoveAction(LIST_DEFACTION_REMOVE + "i", getCms(), false);
223         indirRemoveAction.setName(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0));
224         indirRemoveAction.setHelpText(Messages.get().container(
225             Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0));
226         indirRemoveAction.setEnabled(false);
227         nameCol.addDefaultAction(indirRemoveAction);
228
229         // keep the ids
230
m_removeActionIds.add(removeAction.getId());
231         m_removeActionIds.add(indirRemoveAction.getId());
232     }
233
234     /**
235      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
236      */

237     protected void setIconAction(CmsListColumnDefinition iconCol) {
238
239         // adds a direct group icon
240
CmsListDirectAction dirAction = new CmsGroupStateAction(LIST_ACTION_ICON_DIRECT, getCms(), true);
241         dirAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DIRECT_NAME_0));
242         dirAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DIRECT_HELP_0));
243         dirAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group.png");
244         dirAction.setEnabled(false);
245         iconCol.addDirectAction(dirAction);
246
247         // adds an indirect group icon
248
CmsListDirectAction indirAction = new CmsGroupStateAction(LIST_ACTION_ICON_INDIRECT, getCms(), false);
249         indirAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_INDIRECT_NAME_0));
250         indirAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_INDIRECT_HELP_0));
251         indirAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group_indirect.png");
252         indirAction.setEnabled(false);
253         iconCol.addDirectAction(indirAction);
254
255         iconCol.setListItemComparator(new CmsListItemActionIconComparator());
256     }
257
258     /**
259      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
260      */

261     protected void setMultiActions(CmsListMetadata metadata) {
262
263         // add remove multi action
264
CmsListMultiAction removeMultiAction = new CmsListMultiAction(LIST_MACTION_REMOVE);
265         removeMultiAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_MACTION_REMOVE_NAME_0));
266         removeMultiAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_MACTION_REMOVE_HELP_0));
267         removeMultiAction.setConfirmationMessage(Messages.get().container(
268             Messages.GUI_GROUPS_LIST_MACTION_REMOVE_CONF_0));
269         removeMultiAction.setIconPath(ICON_MULTI_MINUS);
270         metadata.addMultiAction(removeMultiAction);
271     }
272
273     /**
274      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
275      */

276     protected void setStateActionCol(CmsListMetadata metadata) {
277
278         // create column for state change
279
CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_STATE);
280         stateCol.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_STATE_0));
281         stateCol.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_STATE_HELP_0));
282         stateCol.setWidth("20");
283         stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
284         stateCol.setSorteable(false);
285         // add it to the list definition
286
metadata.addColumn(stateCol);
287
288         // add remove action for direct groups
289
CmsGroupRemoveAction dirStateAction = new CmsGroupRemoveAction(LIST_ACTION_REMOVE, getCms(), true);
290         dirStateAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0));
291         dirStateAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0));
292         dirStateAction.setIconPath(ICON_MINUS);
293         stateCol.addDirectAction(dirStateAction);
294
295         // add remove action for indirect groups
296
CmsGroupRemoveAction indirStateAction = new CmsGroupRemoveAction(LIST_ACTION_REMOVE + "i", getCms(), false);
297         indirStateAction.setName(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0));
298         indirStateAction.setHelpText(Messages.get().container(Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0));
299         indirStateAction.setIconPath(A_CmsListDialog.ICON_DISABLED);
300         indirStateAction.setEnabled(false);
301         stateCol.addDirectAction(indirStateAction);
302
303         stateCol.setListItemComparator(new CmsListItemActionIconComparator());
304
305         // add it to the list definition
306
metadata.addColumn(stateCol);
307         // keep the ids
308
m_removeActionIds.add(dirStateAction.getId());
309         m_removeActionIds.add(indirStateAction.getId());
310     }
311 }
312
Popular Tags