KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsNotUserGroupsList.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 CmsNotUserGroupsList extends A_CmsUserGroupsList {
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 = "lnug";
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 CmsNotUserGroupsList(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 CmsNotUserGroupsList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
99
100         this(new CmsJspActionElement(context, req, res));
101     }
102
103     /**
104      * Public constructor.<p>
105      *
106      * @param jsp an initialized JSP action element
107      * @param listId the id of the list
108      */

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

117     public void executeListMultiActions() throws CmsRuntimeException {
118
119         if (getParamListAction().equals(LIST_MACTION_ADD)) {
120             // execute the remove multiaction
121
try {
122                 Iterator JavaDoc itItems = getSelectedItems().iterator();
123                 while (itItems.hasNext()) {
124                     CmsListItem listItem = (CmsListItem)itItems.next();
125                     getCms().addUserToGroup(getParamUsername(), (String JavaDoc)listItem.get(LIST_COLUMN_NAME));
126                 }
127             } catch (CmsException e) {
128                 // refresh the list
129
Map JavaDoc objects = (Map JavaDoc)getSettings().getListObject();
130                 if (objects != null) {
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(getParamUsername(), (String JavaDoc)listItem.get(LIST_COLUMN_NAME));
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_CmsUserGroupsList#getGroups()
162      */

163     protected List JavaDoc getGroups() throws CmsException {
164
165         List JavaDoc usergroups = getCms().getGroupsOfUser(getParamUsername());
166         List JavaDoc groups = getCms().getGroups();
167         groups.removeAll(usergroups);
168         return groups;
169     }
170
171     /**
172      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
173      */

174     protected void setDefaultAction(CmsListColumnDefinition nameCol) {
175
176         // add add action
177
CmsListDefaultAction addAction = new CmsListDefaultAction(LIST_DEFACTION_ADD);
178         addAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_ADD_NAME_0));
179         addAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_ADD_HELP_0));
180         nameCol.addDefaultAction(addAction);
181         // keep the id
182
m_addActionIds.add(addAction.getId());
183     }
184
185     /**
186      * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#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_GROUPS_LIST_AVAILABLE_NAME_0));
192         iconAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_AVAILABLE_HELP_0));
193         iconAction.setIconPath(A_CmsUsersList.PATH_BUTTONS + "group.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_GROUPS_LIST_MACTION_ADD_NAME_0));
206         addMultiAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_MACTION_ADD_HELP_0));
207         addMultiAction.setConfirmationMessage(Messages.get().container(Messages.GUI_GROUPS_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_CmsUserGroupsList#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_GROUPS_LIST_COLS_STATE_0));
220         stateCol.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_COLS_STATE_HELP_0));
221         stateCol.setWidth("20");
222         stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
223         stateCol.setSorteable(false);
224         // add it to the list definition
225
metadata.addColumn(stateCol);
226
227         // add add action
228
CmsListDirectAction stateAction = new CmsListDirectAction(LIST_ACTION_ADD);
229         stateAction.setName(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_ADD_NAME_0));
230         stateAction.setHelpText(Messages.get().container(Messages.GUI_GROUPS_LIST_DEFACTION_ADD_HELP_0));
231         stateAction.setIconPath(ICON_ADD);
232         stateCol.addDirectAction(stateAction);
233         // keep the id
234
m_addActionIds.add(stateAction.getId());
235     }
236 }
237
Popular Tags