001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsUserGroupsList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.13 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.accounts;
033:
034: import org.opencms.file.CmsGroup;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.workplace.list.A_CmsListDialog;
039: import org.opencms.workplace.list.CmsListColumnAlignEnum;
040: import org.opencms.workplace.list.CmsListColumnDefinition;
041: import org.opencms.workplace.list.CmsListDirectAction;
042: import org.opencms.workplace.list.CmsListItem;
043: import org.opencms.workplace.list.CmsListItemActionIconComparator;
044: import org.opencms.workplace.list.CmsListMetadata;
045: import org.opencms.workplace.list.CmsListMultiAction;
046:
047: import java.util.HashSet;
048: import java.util.Iterator;
049: import java.util.List;
050: import java.util.Set;
051:
052: import javax.servlet.http.HttpServletRequest;
053: import javax.servlet.http.HttpServletResponse;
054: import javax.servlet.jsp.PageContext;
055:
056: /**
057: * User groups view.<p>
058: *
059: * @author Michael Moossen
060: *
061: * @version $Revision: 1.13 $
062: *
063: * @since 6.0.0
064: */
065: public class CmsUserGroupsList extends A_CmsUserGroupsList {
066:
067: /** list action id constant. */
068: public static final String LIST_ACTION_REMOVE = "ar";
069:
070: /** list action id constant. */
071: public static final String LIST_DEFACTION_REMOVE = "dr";
072:
073: /** list id constant. */
074: public static final String LIST_ID = "lug";
075:
076: /** list action id constant. */
077: public static final String LIST_MACTION_REMOVE = "mr";
078:
079: /** a set of action id's to use for removing. */
080: protected static Set m_removeActionIds = new HashSet();
081:
082: /**
083: * Public constructor.<p>
084: *
085: * @param jsp an initialized JSP action element
086: */
087: public CmsUserGroupsList(CmsJspActionElement jsp) {
088:
089: this (jsp, LIST_ID);
090: }
091:
092: /**
093: * Public constructor with JSP variables.<p>
094: *
095: * @param context the JSP page context
096: * @param req the JSP request
097: * @param res the JSP response
098: */
099: public CmsUserGroupsList(PageContext context,
100: HttpServletRequest req, HttpServletResponse res) {
101:
102: this (new CmsJspActionElement(context, req, res));
103: }
104:
105: /**
106: * Public constructor.<p>
107: *
108: * @param jsp an initialized JSP action element
109: * @param listId the id of the list
110: */
111: protected CmsUserGroupsList(CmsJspActionElement jsp, String listId) {
112:
113: super (jsp, listId, Messages.get().container(
114: 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 itItems = getSelectedItems().iterator();
125: while (itItems.hasNext()) {
126: CmsListItem listItem = (CmsListItem) itItems.next();
127: String groupName = (String) listItem
128: .get(LIST_COLUMN_NAME);
129: boolean directGroup = false;
130: try {
131: Iterator it = getCms().getGroupsOfUser(
132: getParamUsername(), true).iterator();
133: while (it.hasNext()) {
134: CmsGroup group = (CmsGroup) it.next();
135: if (group.getName().equals(groupName)) {
136: directGroup = true;
137: break;
138: }
139: }
140: if (directGroup) {
141: getCms().removeUserFromGroup(
142: getParamUsername(), groupName);
143: }
144: } catch (CmsException e) {
145: // could be an indirectly assigned group
146: }
147: }
148: } else {
149: throwListUnsupportedActionException();
150: }
151: listSave();
152: }
153:
154: /**
155: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
156: */
157: public void executeListSingleActions() throws CmsRuntimeException {
158:
159: if (m_removeActionIds.contains(getParamListAction())) {
160: CmsListItem listItem = getSelectedItem();
161: try {
162: getCms().removeUserFromGroup(getParamUsername(),
163: (String) listItem.get(LIST_COLUMN_NAME));
164: } catch (CmsException e) {
165: // should never happen
166: throw new CmsRuntimeException(Messages.get().container(
167: Messages.ERR_REMOVE_SELECTED_GROUP_0), e);
168: }
169: } else {
170: throwListUnsupportedActionException();
171: }
172: listSave();
173: }
174:
175: /**
176: * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#getGroups(boolean)
177: */
178: protected List getGroups(boolean withOtherOus) throws CmsException {
179:
180: return getCms().getGroupsOfUser(getParamUsername(), false,
181: withOtherOus);
182: }
183:
184: /**
185: * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
186: */
187: protected void setDefaultAction(CmsListColumnDefinition nameCol) {
188:
189: // add default remove action for direct groups
190: CmsGroupRemoveAction removeAction = new CmsGroupRemoveAction(
191: LIST_DEFACTION_REMOVE, true);
192: removeAction.setName(Messages.get().container(
193: Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0));
194: removeAction.setHelpText(Messages.get().container(
195: Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0));
196: nameCol.addDefaultAction(removeAction);
197:
198: // add default remove action for indirect groups
199: CmsGroupRemoveAction indirRemoveAction = new CmsGroupRemoveAction(
200: LIST_DEFACTION_REMOVE + "i", false);
201: indirRemoveAction
202: .setName(Messages
203: .get()
204: .container(
205: Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0));
206: indirRemoveAction
207: .setHelpText(Messages
208: .get()
209: .container(
210: Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0));
211: indirRemoveAction.setEnabled(false);
212: nameCol.addDefaultAction(indirRemoveAction);
213:
214: // keep the ids
215: m_removeActionIds.add(removeAction.getId());
216: m_removeActionIds.add(indirRemoveAction.getId());
217: }
218:
219: /**
220: * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
221: */
222: protected void setIconAction(CmsListColumnDefinition iconCol) {
223:
224: // adds a direct group icon
225: CmsListDirectAction dirAction = new CmsGroupStateAction(
226: LIST_ACTION_ICON_DIRECT, true);
227: dirAction.setName(Messages.get().container(
228: Messages.GUI_GROUPS_LIST_DIRECT_NAME_0));
229: dirAction.setHelpText(Messages.get().container(
230: Messages.GUI_GROUPS_LIST_DIRECT_HELP_0));
231: dirAction
232: .setIconPath(A_CmsUsersList.PATH_BUTTONS + "group.png");
233: dirAction.setEnabled(false);
234: iconCol.addDirectAction(dirAction);
235:
236: // adds an indirect group icon
237: CmsListDirectAction indirAction = new CmsGroupStateAction(
238: LIST_ACTION_ICON_INDIRECT, false);
239: indirAction.setName(Messages.get().container(
240: Messages.GUI_GROUPS_LIST_INDIRECT_NAME_0));
241: indirAction.setHelpText(Messages.get().container(
242: Messages.GUI_GROUPS_LIST_INDIRECT_HELP_0));
243: indirAction.setIconPath(A_CmsUsersList.PATH_BUTTONS
244: + "group_indirect.png");
245: indirAction.setEnabled(false);
246: iconCol.addDirectAction(indirAction);
247:
248: iconCol
249: .setListItemComparator(new CmsListItemActionIconComparator());
250: }
251:
252: /**
253: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
254: */
255: protected void setMultiActions(CmsListMetadata metadata) {
256:
257: // add remove multi action
258: CmsListMultiAction removeMultiAction = new CmsListMultiAction(
259: LIST_MACTION_REMOVE);
260: removeMultiAction.setName(Messages.get().container(
261: Messages.GUI_GROUPS_LIST_MACTION_REMOVE_NAME_0));
262: removeMultiAction.setHelpText(Messages.get().container(
263: Messages.GUI_GROUPS_LIST_MACTION_REMOVE_HELP_0));
264: removeMultiAction
265: .setConfirmationMessage(Messages.get().container(
266: Messages.GUI_GROUPS_LIST_MACTION_REMOVE_CONF_0));
267: removeMultiAction.setIconPath(ICON_MULTI_MINUS);
268: metadata.addMultiAction(removeMultiAction);
269: }
270:
271: /**
272: * @see org.opencms.workplace.tools.accounts.A_CmsUserGroupsList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
273: */
274: protected void setStateActionCol(CmsListMetadata metadata) {
275:
276: // create column for state change
277: CmsListColumnDefinition stateCol = new CmsListColumnDefinition(
278: LIST_COLUMN_STATE);
279: stateCol.setName(Messages.get().container(
280: Messages.GUI_GROUPS_LIST_COLS_STATE_0));
281: stateCol.setHelpText(Messages.get().container(
282: Messages.GUI_GROUPS_LIST_COLS_STATE_HELP_0));
283: stateCol.setWidth("20");
284: stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
285: stateCol.setSorteable(false);
286:
287: // add remove action for direct groups
288: CmsGroupRemoveAction dirStateAction = new CmsGroupRemoveAction(
289: LIST_ACTION_REMOVE, true);
290: dirStateAction.setName(Messages.get().container(
291: Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_NAME_0));
292: dirStateAction.setHelpText(Messages.get().container(
293: Messages.GUI_GROUPS_LIST_DEFACTION_REMOVE_HELP_0));
294: dirStateAction.setIconPath(ICON_MINUS);
295: stateCol.addDirectAction(dirStateAction);
296:
297: // add remove action for indirect groups
298: CmsGroupRemoveAction indirStateAction = new CmsGroupRemoveAction(
299: LIST_ACTION_REMOVE + "i", false);
300: indirStateAction
301: .setName(Messages
302: .get()
303: .container(
304: Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_NAME_0));
305: indirStateAction
306: .setHelpText(Messages
307: .get()
308: .container(
309: Messages.GUI_USERGROUPS_LIST_ACTION_STATE_DISABLED_HELP_0));
310: indirStateAction.setIconPath(A_CmsListDialog.ICON_DISABLED);
311: indirStateAction.setEnabled(false);
312: stateCol.addDirectAction(indirStateAction);
313:
314: stateCol
315: .setListItemComparator(new CmsListItemActionIconComparator());
316:
317: // add it to the list definition
318: metadata.addColumn(stateCol);
319: // keep the ids
320: m_removeActionIds.add(dirStateAction.getId());
321: m_removeActionIds.add(indirStateAction.getId());
322: }
323: }
|