001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsGroupUsersList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.11 $
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.jsp.CmsJspActionElement;
035: import org.opencms.main.CmsException;
036: import org.opencms.main.CmsRuntimeException;
037: import org.opencms.util.CmsUUID;
038: import org.opencms.workplace.list.CmsListColumnAlignEnum;
039: import org.opencms.workplace.list.CmsListColumnDefinition;
040: import org.opencms.workplace.list.CmsListDefaultAction;
041: import org.opencms.workplace.list.CmsListDirectAction;
042: import org.opencms.workplace.list.CmsListItem;
043: import org.opencms.workplace.list.CmsListMetadata;
044: import org.opencms.workplace.list.CmsListMultiAction;
045:
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.List;
049: import java.util.Set;
050:
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053: import javax.servlet.jsp.PageContext;
054:
055: /**
056: * User groups view.<p>
057: *
058: * @author Michael Moossen
059: *
060: * @version $Revision: 1.11 $
061: *
062: * @since 6.0.0
063: */
064: public class CmsGroupUsersList extends A_CmsGroupUsersList {
065:
066: /** list action id constant. */
067: public static final String LIST_ACTION_REMOVE = "ar";
068:
069: /** list action id constant. */
070: public static final String LIST_DEFACTION_REMOVE = "dr";
071:
072: /** list item detail id constant. */
073: public static final String LIST_DETAIL_ORGUNIT = "dou";
074:
075: /** list id constant. */
076: public static final String LIST_ID = "lgu";
077:
078: /** list action id constant. */
079: public static final String LIST_MACTION_REMOVE = "mr";
080:
081: /** a set of action id's to use for removing. */
082: protected static Set m_removeActionIds = new HashSet();
083:
084: /**
085: * Public constructor.<p>
086: *
087: * @param jsp an initialized JSP action element
088: */
089: public CmsGroupUsersList(CmsJspActionElement jsp) {
090:
091: this (jsp, LIST_ID);
092: }
093:
094: /**
095: * Public constructor with JSP variables.<p>
096: *
097: * @param context the JSP page context
098: * @param req the JSP request
099: * @param res the JSP response
100: */
101: public CmsGroupUsersList(PageContext context,
102: HttpServletRequest req, HttpServletResponse res) {
103:
104: this (new CmsJspActionElement(context, req, res));
105: }
106:
107: /**
108: * Protected constructor.<p>
109: * @param jsp an initialized JSP action element
110: * @param listId the id of the specialized list
111: */
112: protected CmsGroupUsersList(CmsJspActionElement jsp, String listId) {
113:
114: super (jsp, listId, Messages.get().container(
115: Messages.GUI_GROUPUSERS_LIST_NAME_0), true);
116: }
117:
118: /**
119: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
120: */
121: public void executeListMultiActions() throws CmsRuntimeException {
122:
123: if (getParamListAction().equals(LIST_MACTION_REMOVE)) {
124: // execute the remove multiaction
125: Iterator itItems = getSelectedItems().iterator();
126: while (itItems.hasNext()) {
127: CmsListItem listItem = (CmsListItem) itItems.next();
128: String userName = (String) listItem
129: .get(LIST_COLUMN_LOGIN);
130: try {
131: getCms().removeUserFromGroup(userName,
132: getParamGroupname());
133: } catch (CmsException e) {
134: // noop
135: }
136: }
137: } else {
138: throwListUnsupportedActionException();
139: }
140: listSave();
141: }
142:
143: /**
144: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
145: */
146: public void executeListSingleActions() throws CmsRuntimeException {
147:
148: if (m_removeActionIds.contains(getParamListAction())) {
149: CmsListItem listItem = getSelectedItem();
150: try {
151: getCms().removeUserFromGroup(
152: (String) listItem.get(LIST_COLUMN_LOGIN),
153: getParamGroupname());
154: } catch (CmsException e) {
155: // should never happen
156: throw new CmsRuntimeException(Messages.get().container(
157: Messages.ERR_REMOVE_SELECTED_GROUP_0), e);
158: }
159: } else {
160: throwListUnsupportedActionException();
161: }
162: listSave();
163: }
164:
165: /**
166: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#getUsers(boolean)
167: */
168: protected List getUsers(boolean withOtherOus) throws CmsException {
169:
170: return getCms().getUsersOfGroup(getParamGroupname(),
171: withOtherOus);
172: }
173:
174: /**
175: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
176: */
177: protected void setDefaultAction(CmsListColumnDefinition loginCol) {
178:
179: // add default remove action
180: CmsListDefaultAction removeAction = new CmsListDefaultAction(
181: LIST_DEFACTION_REMOVE);
182: removeAction.setName(Messages.get().container(
183: Messages.GUI_USERS_LIST_DEFACTION_REMOVE_NAME_0));
184: removeAction.setHelpText(Messages.get().container(
185: Messages.GUI_USERS_LIST_DEFACTION_REMOVE_HELP_0));
186: loginCol.addDefaultAction(removeAction);
187: // keep the id
188: m_removeActionIds.add(removeAction.getId());
189: }
190:
191: /**
192: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
193: */
194: protected void setIconAction(CmsListColumnDefinition iconCol) {
195:
196: CmsListDirectAction iconAction = new CmsListDefaultAction(
197: LIST_ACTION_ICON) {
198:
199: /**
200: * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getIconPath()
201: */
202: public String getIconPath() {
203:
204: return ((A_CmsGroupUsersList) getWp())
205: .getIconPath(getItem());
206: }
207: };
208: iconAction.setName(Messages.get().container(
209: Messages.GUI_USERS_LIST_INGROUP_NAME_0));
210: iconAction.setHelpText(Messages.get().container(
211: Messages.GUI_USERS_LIST_INGROUP_HELP_0));
212: iconAction
213: .setIconPath(A_CmsUsersList.PATH_BUTTONS + "user.png");
214: iconAction.setEnabled(false);
215: iconCol.addDirectAction(iconAction);
216: }
217:
218: /**
219: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
220: */
221: protected void setMultiActions(CmsListMetadata metadata) {
222:
223: // add remove multi action
224: CmsListMultiAction removeMultiAction = new CmsListMultiAction(
225: LIST_MACTION_REMOVE);
226: removeMultiAction.setName(Messages.get().container(
227: Messages.GUI_USERS_LIST_MACTION_REMOVE_NAME_0));
228: removeMultiAction.setHelpText(Messages.get().container(
229: Messages.GUI_USERS_LIST_MACTION_REMOVE_HELP_0));
230: removeMultiAction.setConfirmationMessage(Messages.get()
231: .container(
232: Messages.GUI_USERS_LIST_MACTION_REMOVE_CONF_0));
233: removeMultiAction.setIconPath(ICON_MULTI_MINUS);
234: metadata.addMultiAction(removeMultiAction);
235: }
236:
237: /**
238: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
239: */
240: protected void setStateActionCol(CmsListMetadata metadata) {
241:
242: // create column for state change
243: CmsListColumnDefinition stateCol = new CmsListColumnDefinition(
244: LIST_COLUMN_STATE);
245: stateCol.setName(Messages.get().container(
246: Messages.GUI_USERS_LIST_COLS_STATE_0));
247: stateCol.setHelpText(Messages.get().container(
248: Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
249: stateCol.setWidth("20");
250: stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
251: stateCol.setSorteable(false);
252: // add remove action
253: CmsListDirectAction stateAction = new CmsListDirectAction(
254: LIST_ACTION_REMOVE);
255: stateAction.setName(Messages.get().container(
256: Messages.GUI_USERS_LIST_DEFACTION_REMOVE_NAME_0));
257: stateAction.setHelpText(Messages.get().container(
258: Messages.GUI_USERS_LIST_DEFACTION_REMOVE_HELP_0));
259: stateAction.setIconPath(ICON_MINUS);
260: stateCol.addDirectAction(stateAction);
261: // add it to the list definition
262: metadata.addColumn(stateCol);
263: // keep the id
264: m_removeActionIds.add(stateAction.getId());
265: }
266:
267: /**
268: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#validateParamaters()
269: */
270: protected void validateParamaters() throws Exception {
271:
272: super .validateParamaters();
273: if (getCms().readGroup(new CmsUUID(getParamGroupid()))
274: .isVirtual()) {
275: throw new Exception();
276: }
277: }
278: }
|