KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

85     public CmsGroupUsersList(CmsJspActionElement jsp) {
86
87         this(jsp, LIST_ID);
88     }
89
90     /**
91      * Public constructor with JSP variables.<p>
92      *
93      * @param context the JSP page context
94      * @param req the JSP request
95      * @param res the JSP response
96      */

97     public CmsGroupUsersList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
98
99         this(new CmsJspActionElement(context, req, res));
100     }
101
102     /**
103      * Protected constructor.<p>
104      * @param jsp an initialized JSP action element
105      * @param listId the id of the specialized list
106      */

107     protected CmsGroupUsersList(CmsJspActionElement jsp, String JavaDoc listId) {
108
109         super(jsp, listId, Messages.get().container(Messages.GUI_GROUPUSERS_LIST_NAME_0), true);
110     }
111
112     /**
113      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
114      */

115     public void executeListMultiActions() throws CmsRuntimeException {
116
117         if (getParamListAction().equals(LIST_MACTION_REMOVE)) {
118             // execute the remove multiaction
119
Iterator JavaDoc itItems = getSelectedItems().iterator();
120             while (itItems.hasNext()) {
121                 CmsListItem listItem = (CmsListItem)itItems.next();
122                 String JavaDoc userName = (String JavaDoc)listItem.get(LIST_COLUMN_LOGIN);
123                 try {
124                     getCms().removeUserFromGroup(userName, getParamGroupname());
125                 } catch (CmsException e) {
126                     // noop
127
}
128             }
129         } else {
130             throwListUnsupportedActionException();
131         }
132         listSave();
133     }
134
135     /**
136      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
137      */

138     public void executeListSingleActions() throws CmsRuntimeException {
139
140         if (m_removeActionIds.contains(getParamListAction())) {
141             CmsListItem listItem = getSelectedItem();
142             try {
143                 getCms().removeUserFromGroup((String JavaDoc)listItem.get(LIST_COLUMN_LOGIN), getParamGroupname());
144             } catch (CmsException e) {
145                 // should never happen
146
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_REMOVE_SELECTED_GROUP_0), e);
147             }
148         } else {
149             throwListUnsupportedActionException();
150         }
151         listSave();
152     }
153
154     /**
155      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#getUsers()
156      */

157     protected List JavaDoc getUsers() throws CmsException {
158
159         return getCms().getUsersOfGroup(getParamGroupname());
160     }
161
162     /**
163      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
164      */

165     protected void setDefaultAction(CmsListColumnDefinition loginCol) {
166
167         // add default remove action
168
CmsListDefaultAction removeAction = new CmsListDefaultAction(LIST_DEFACTION_REMOVE);
169         removeAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_REMOVE_NAME_0));
170         removeAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_REMOVE_HELP_0));
171         loginCol.addDefaultAction(removeAction);
172         // keep the id
173
m_removeActionIds.add(removeAction.getId());
174     }
175
176     /**
177      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
178      */

179     protected void setIconAction(CmsListColumnDefinition iconCol) {
180
181         CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON);
182         iconAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_INGROUP_NAME_0));
183         iconAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_INGROUP_HELP_0));
184         iconAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "user.png");
185         iconAction.setEnabled(false);
186         iconCol.addDirectAction(iconAction);
187     }
188
189     /**
190      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
191      */

192     protected void setMultiActions(CmsListMetadata metadata) {
193
194         // add remove multi action
195
CmsListMultiAction removeMultiAction = new CmsListMultiAction(LIST_MACTION_REMOVE);
196         removeMultiAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_REMOVE_NAME_0));
197         removeMultiAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_REMOVE_HELP_0));
198         removeMultiAction.setConfirmationMessage(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_REMOVE_CONF_0));
199         removeMultiAction.setIconPath(ICON_MULTI_MINUS);
200         metadata.addMultiAction(removeMultiAction);
201     }
202
203     /**
204      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
205      */

206     protected void setStateActionCol(CmsListMetadata metadata) {
207
208         // create column for state change
209
CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_STATE);
210         stateCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_STATE_0));
211         stateCol.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
212         stateCol.setWidth("20");
213         stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
214         stateCol.setSorteable(false);
215         // add remove action
216
CmsListDirectAction stateAction = new CmsListDirectAction(LIST_ACTION_REMOVE);
217         stateAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_REMOVE_NAME_0));
218         stateAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_REMOVE_HELP_0));
219         stateAction.setIconPath(ICON_MINUS);
220         stateCol.addDirectAction(stateAction);
221         // add it to the list definition
222
metadata.addColumn(stateCol);
223         // keep the id
224
m_removeActionIds.add(stateAction.getId());
225     }
226 }
227
Popular Tags