KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsNotGroupUsersList.java,v $
3  * Date : $Date: 2006/03/27 14:52:49 $
4  * Version: $Revision: 1.9 $
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.Map JavaDoc;
49 import java.util.Set JavaDoc;
50
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52 import javax.servlet.http.HttpServletResponse JavaDoc;
53 import javax.servlet.jsp.PageContext JavaDoc;
54
55 /**
56  * Not Usergroups view.<p>
57  *
58  * @author Michael Moossen
59  *
60  * @version $Revision: 1.9 $
61  *
62  * @since 6.0.0
63  */

64 public class CmsNotGroupUsersList extends A_CmsGroupUsersList {
65
66     /** list action id constant. */
67     public static final String JavaDoc LIST_ACTION_ADD = "aa";
68
69     /** list action id constant. */
70     public static final String JavaDoc LIST_DEFACTION_ADD = "da";
71
72     /** list id constant. */
73     public static final String JavaDoc LIST_ID = "lngu";
74
75     /** list action id constant. */
76     public static final String JavaDoc LIST_MACTION_ADD = "ma";
77
78     /** a set of action id's to use for adding. */
79     protected static Set JavaDoc m_addActionIds = new HashSet JavaDoc();
80
81     /**
82      * Public constructor.<p>
83      *
84      * @param jsp an initialized JSP action element
85      */

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

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

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

116     public void executeListMultiActions() throws CmsRuntimeException {
117
118         if (getParamListAction().equals(LIST_MACTION_ADD)) {
119             // execute the remove multiaction
120
try {
121                 Iterator JavaDoc itItems = getSelectedItems().iterator();
122                 while (itItems.hasNext()) {
123                     CmsListItem listItem = (CmsListItem)itItems.next();
124                     getCms().addUserToGroup((String JavaDoc)listItem.get(LIST_COLUMN_LOGIN), getParamGroupname());
125                 }
126             } catch (CmsException e) {
127                 // refresh the list
128
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
129                 if (objects != null) {
130                     objects.remove(CmsGroupsList.class.getName());
131                     objects.remove(A_CmsUsersList.class.getName());
132                 }
133                 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_ADD_SELECTED_GROUPS_0), e);
134             }
135         } else {
136             throwListUnsupportedActionException();
137         }
138         listSave();
139     }
140
141     /**
142      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
143      */

144     public void executeListSingleActions() throws CmsRuntimeException {
145
146         if (m_addActionIds.contains(getParamListAction())) {
147             CmsListItem listItem = getSelectedItem();
148             try {
149                 getCms().addUserToGroup((String JavaDoc)listItem.get(LIST_COLUMN_LOGIN), getParamGroupname());
150             } catch (CmsException e) {
151                 // should never happen
152
throw new CmsRuntimeException(Messages.get().container(Messages.ERR_ADD_SELECTED_GROUP_0), e);
153             }
154         } else {
155             throwListUnsupportedActionException();
156         }
157         listSave();
158     }
159
160     /**
161      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#getUsers()
162      */

163     protected List JavaDoc getUsers() throws CmsException {
164
165         List JavaDoc groupusers = getCms().getUsersOfGroup(getParamGroupname());
166         List JavaDoc users = getCms().getUsers();
167         users.removeAll(groupusers);
168         return users;
169     }
170
171     /**
172      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
173      */

174     protected void setDefaultAction(CmsListColumnDefinition loginCol) {
175
176         // add add action
177
CmsListDefaultAction addAction = new CmsListDefaultAction(LIST_DEFACTION_ADD);
178         addAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
179         addAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
180         loginCol.addDefaultAction(addAction);
181         // keep the id
182
m_addActionIds.add(addAction.getId());
183     }
184
185     /**
186      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
187      */

188     protected void setIconAction(CmsListColumnDefinition iconCol) {
189
190         CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON);
191         iconAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_AVAILABLE_NAME_0));
192         iconAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_AVAILABLE_HELP_0));
193         iconAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "user.png");
194         iconAction.setEnabled(false);
195         iconCol.addDirectAction(iconAction);
196     }
197
198     /**
199      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
200      */

201     protected void setMultiActions(CmsListMetadata metadata) {
202
203         // add add multi action
204
CmsListMultiAction addMultiAction = new CmsListMultiAction(LIST_MACTION_ADD);
205         addMultiAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_ADD_NAME_0));
206         addMultiAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_ADD_HELP_0));
207         addMultiAction.setConfirmationMessage(Messages.get().container(Messages.GUI_USERS_LIST_MACTION_ADD_CONF_0));
208         addMultiAction.setIconPath(ICON_MULTI_ADD);
209         metadata.addMultiAction(addMultiAction);
210     }
211
212     /**
213      * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
214      */

215     protected void setStateActionCol(CmsListMetadata metadata) {
216
217         // create column for state change
218
CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_STATE);
219         stateCol.setName(Messages.get().container(Messages.GUI_USERS_LIST_COLS_STATE_0));
220         stateCol.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
221         stateCol.setWidth("20");
222         stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
223         stateCol.setSorteable(false);
224         // add add action
225
CmsListDirectAction stateAction = new CmsListDirectAction(LIST_ACTION_ADD);
226         stateAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
227         stateAction.setHelpText(Messages.get().container(Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
228         stateAction.setIconPath(ICON_ADD);
229         stateCol.addDirectAction(stateAction);
230         // add it to the list definition
231
metadata.addColumn(stateCol);
232         // keep the id
233
m_addActionIds.add(stateAction.getId());
234     }
235 }
236
Popular Tags