001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsNotGroupUsersList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.12 $
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.main.OpenCms;
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.Map;
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: * Not Usergroups view.<p>
058: *
059: * @author Michael Moossen
060: *
061: * @version $Revision: 1.12 $
062: *
063: * @since 6.0.0
064: */
065: public class CmsNotGroupUsersList extends A_CmsGroupUsersList {
066:
067: /** list action id constant. */
068: public static final String LIST_ACTION_ADD = "aa";
069:
070: /** list action id constant. */
071: public static final String LIST_DEFACTION_ADD = "da";
072:
073: /** list id constant. */
074: public static final String LIST_ID = "lngu";
075:
076: /** list action id constant. */
077: public static final String LIST_MACTION_ADD = "ma";
078:
079: /** a set of action id's to use for adding. */
080: protected static Set m_addActionIds = new HashSet();
081:
082: /**
083: * Public constructor.<p>
084: *
085: * @param jsp an initialized JSP action element
086: */
087: public CmsNotGroupUsersList(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 CmsNotGroupUsersList(PageContext context,
100: HttpServletRequest req, HttpServletResponse res) {
101:
102: this (new CmsJspActionElement(context, req, res));
103: }
104:
105: /**
106: * Protected constructor.<p>
107: * @param jsp an initialized JSP action element
108: * @param listId the id of the specialized list
109: */
110: protected CmsNotGroupUsersList(CmsJspActionElement jsp,
111: String listId) {
112:
113: super (jsp, listId, Messages.get().container(
114: Messages.GUI_NOTGROUPUSERS_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_ADD)) {
123: // execute the remove multiaction
124: try {
125: Iterator itItems = getSelectedItems().iterator();
126: while (itItems.hasNext()) {
127: CmsListItem listItem = (CmsListItem) itItems.next();
128: getCms().addUserToGroup(
129: (String) listItem.get(LIST_COLUMN_LOGIN),
130: getParamGroupname());
131: }
132: } catch (CmsException e) {
133: // refresh the list
134: Map objects = (Map) getSettings().getListObject();
135: if (objects != null) {
136: objects.remove(CmsGroupsList.class.getName());
137: objects.remove(A_CmsUsersList.class.getName());
138: }
139: throw new CmsRuntimeException(Messages.get().container(
140: Messages.ERR_ADD_SELECTED_GROUPS_0), e);
141: }
142: } else {
143: throwListUnsupportedActionException();
144: }
145: listSave();
146: }
147:
148: /**
149: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
150: */
151: public void executeListSingleActions() throws CmsRuntimeException {
152:
153: if (m_addActionIds.contains(getParamListAction())) {
154: CmsListItem listItem = getSelectedItem();
155: try {
156: getCms().addUserToGroup(
157: (String) listItem.get(LIST_COLUMN_LOGIN),
158: getParamGroupname());
159: } catch (CmsException e) {
160: // should never happen
161: throw new CmsRuntimeException(Messages.get().container(
162: Messages.ERR_ADD_SELECTED_GROUP_0), e);
163: }
164: } else {
165: throwListUnsupportedActionException();
166: }
167: listSave();
168: }
169:
170: /**
171: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#getUsers(boolean)
172: */
173: protected List getUsers(boolean withOtherOus) throws CmsException {
174:
175: List groupusers = getCms().getUsersOfGroup(getParamGroupname(),
176: withOtherOus);
177: List users;
178: if (withOtherOus) {
179: users = OpenCms.getRoleManager().getManageableUsers(
180: getCms(), "", true);
181: } else {
182: users = OpenCms.getRoleManager().getManageableUsers(
183: getCms(), getParamOufqn(), false);
184: }
185: users.removeAll(groupusers);
186: return users;
187: }
188:
189: /**
190: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setDefaultAction(org.opencms.workplace.list.CmsListColumnDefinition)
191: */
192: protected void setDefaultAction(CmsListColumnDefinition loginCol) {
193:
194: // add add action
195: CmsListDefaultAction addAction = new CmsListDefaultAction(
196: LIST_DEFACTION_ADD);
197: addAction.setName(Messages.get().container(
198: Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
199: addAction.setHelpText(Messages.get().container(
200: Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
201: loginCol.addDefaultAction(addAction);
202: // keep the id
203: m_addActionIds.add(addAction.getId());
204: }
205:
206: /**
207: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setIconAction(org.opencms.workplace.list.CmsListColumnDefinition)
208: */
209: protected void setIconAction(CmsListColumnDefinition iconCol) {
210:
211: CmsListDirectAction iconAction = new CmsListDefaultAction(
212: LIST_ACTION_ICON) {
213:
214: /**
215: * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getIconPath()
216: */
217: public String getIconPath() {
218:
219: return ((A_CmsGroupUsersList) getWp())
220: .getIconPath(getItem());
221: }
222: };
223: iconAction.setName(Messages.get().container(
224: Messages.GUI_USERS_LIST_AVAILABLE_NAME_0));
225: iconAction.setHelpText(Messages.get().container(
226: Messages.GUI_USERS_LIST_AVAILABLE_HELP_0));
227: iconAction
228: .setIconPath(A_CmsUsersList.PATH_BUTTONS + "user.png");
229: iconAction.setEnabled(false);
230: iconCol.addDirectAction(iconAction);
231: }
232:
233: /**
234: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
235: */
236: protected void setIndependentActions(CmsListMetadata metadata) {
237:
238: super .setIndependentActions(metadata);
239:
240: metadata.getItemDetailDefinition(LIST_DETAIL_OTHEROU)
241: .setVisible(false);
242: }
243:
244: /**
245: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
246: */
247: protected void setMultiActions(CmsListMetadata metadata) {
248:
249: // add add multi action
250: CmsListMultiAction addMultiAction = new CmsListMultiAction(
251: LIST_MACTION_ADD);
252: addMultiAction.setName(Messages.get().container(
253: Messages.GUI_USERS_LIST_MACTION_ADD_NAME_0));
254: addMultiAction.setHelpText(Messages.get().container(
255: Messages.GUI_USERS_LIST_MACTION_ADD_HELP_0));
256: addMultiAction.setConfirmationMessage(Messages.get().container(
257: Messages.GUI_USERS_LIST_MACTION_ADD_CONF_0));
258: addMultiAction.setIconPath(ICON_MULTI_ADD);
259: metadata.addMultiAction(addMultiAction);
260: }
261:
262: /**
263: * @see org.opencms.workplace.tools.accounts.A_CmsGroupUsersList#setStateActionCol(org.opencms.workplace.list.CmsListMetadata)
264: */
265: protected void setStateActionCol(CmsListMetadata metadata) {
266:
267: // create column for state change
268: CmsListColumnDefinition stateCol = new CmsListColumnDefinition(
269: LIST_COLUMN_STATE);
270: stateCol.setName(Messages.get().container(
271: Messages.GUI_USERS_LIST_COLS_STATE_0));
272: stateCol.setHelpText(Messages.get().container(
273: Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
274: stateCol.setWidth("20");
275: stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
276: stateCol.setSorteable(false);
277: // add add action
278: CmsListDirectAction stateAction = new CmsListDirectAction(
279: LIST_ACTION_ADD);
280: stateAction.setName(Messages.get().container(
281: Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
282: stateAction.setHelpText(Messages.get().container(
283: Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
284: stateAction.setIconPath(ICON_ADD);
285: stateCol.addDirectAction(stateAction);
286: // add it to the list definition
287: metadata.addColumn(stateCol);
288: // keep the id
289: m_addActionIds.add(stateAction.getId());
290: }
291:
292: }
|