001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsNotRoleUsersList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.4 $
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.CmsUser;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsRole;
040: import org.opencms.workplace.list.CmsListColumnAlignEnum;
041: import org.opencms.workplace.list.CmsListColumnDefinition;
042: import org.opencms.workplace.list.CmsListDirectAction;
043: import org.opencms.workplace.list.CmsListItem;
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: * Not role users view.<p>
058: *
059: * @author Raphael Schnuck
060: *
061: * @version $Revision: 1.4 $
062: *
063: * @since 6.5.6
064: */
065: public class CmsNotRoleUsersList extends A_CmsRoleUsersList {
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 = "lnru";
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 CmsNotRoleUsersList(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 CmsNotRoleUsersList(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 CmsNotRoleUsersList(CmsJspActionElement jsp, String listId) {
111:
112: super (jsp, listId, Messages.get().container(
113: Messages.GUI_NOTROLEUSERS_LIST_NAME_0), true);
114: }
115:
116: /**
117: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
118: */
119: public void executeListMultiActions() throws CmsRuntimeException {
120:
121: if (getParamListAction().equals(LIST_MACTION_ADD)) {
122: // execute the remove multiaction
123: try {
124: Iterator itItems = getSelectedItems().iterator();
125: while (itItems.hasNext()) {
126: CmsListItem listItem = (CmsListItem) itItems.next();
127: OpenCms.getRoleManager().addUserToRole(
128: getCms(),
129: CmsRole.valueOf(getCms().readGroup(
130: getParamRole())),
131: (String) listItem.get(LIST_COLUMN_LOGIN));
132: }
133: } catch (CmsException e) {
134: // refresh the list
135: throw new CmsRuntimeException(Messages.get().container(
136: Messages.ERR_ADD_SELECTED_USERS_0), e);
137: }
138: } else {
139: throwListUnsupportedActionException();
140: }
141: listSave();
142: }
143:
144: /**
145: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
146: */
147: public void executeListSingleActions() throws CmsRuntimeException {
148:
149: if (m_addActionIds.contains(getParamListAction())) {
150: CmsListItem listItem = getSelectedItem();
151: try {
152: OpenCms.getRoleManager().addUserToRole(
153: getCms(),
154: CmsRole.valueOf(getCms().readGroup(
155: getParamRole())),
156: (String) listItem.get(LIST_COLUMN_LOGIN));
157: } catch (CmsException e) {
158: // should never happen
159: throw new CmsRuntimeException(Messages.get().container(
160: Messages.ERR_ADD_SELECTED_USER_0), e);
161: }
162: } else {
163: throwListUnsupportedActionException();
164: }
165: listSave();
166: }
167:
168: /**
169: * @see org.opencms.workplace.tools.accounts.A_CmsRoleUsersList#getUsers(boolean)
170: */
171: protected List getUsers(boolean withOtherOus) throws CmsException {
172:
173: List roleUsers = OpenCms.getRoleManager().getUsersOfRole(
174: getCms(),
175: CmsRole.valueOf(getCms().readGroup(getParamRole())),
176: withOtherOus, false);
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(roleUsers);
186: return users;
187: }
188:
189: /**
190: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
191: */
192: protected void setColumns(CmsListMetadata metadata) {
193:
194: super .setColumns(metadata);
195:
196: // create column for state change
197: CmsListColumnDefinition stateCol = new CmsListColumnDefinition(
198: LIST_COLUMN_STATE);
199: stateCol.setName(Messages.get().container(
200: Messages.GUI_USERS_LIST_COLS_STATE_0));
201: stateCol.setHelpText(Messages.get().container(
202: Messages.GUI_USERS_LIST_COLS_STATE_HELP_0));
203: stateCol.setWidth("20");
204: stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
205: stateCol.setSorteable(false);
206: // add add action
207: CmsListDirectAction stateAction = new CmsListDirectAction(
208: LIST_ACTION_ADD);
209: stateAction.setName(Messages.get().container(
210: Messages.GUI_USERS_LIST_DEFACTION_ADD_NAME_0));
211: stateAction.setHelpText(Messages.get().container(
212: Messages.GUI_USERS_LIST_DEFACTION_ADD_HELP_0));
213: stateAction.setIconPath(ICON_ADD);
214: stateCol.addDirectAction(stateAction);
215: // add it to the list definition
216: metadata.addColumn(stateCol, 1);
217: // keep the id
218: m_addActionIds.add(stateAction.getId());
219:
220: CmsListDirectAction iconAction = new CmsListDirectAction(
221: LIST_ACTION_ICON) {
222:
223: /**
224: * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#getIconPath()
225: */
226: public String getIconPath() {
227:
228: try {
229: CmsUser user = getCms().readUser(
230: (String) getItem().get(LIST_COLUMN_LOGIN));
231: if (user.getOuFqn().equals(
232: ((A_CmsRoleUsersList) getWp())
233: .getParamOufqn())) {
234: return A_CmsUsersList.PATH_BUTTONS + "user.png";
235:
236: } else {
237: return A_CmsUsersList.PATH_BUTTONS
238: + "user_other_ou.png";
239: }
240: } catch (CmsException e) {
241: return A_CmsUsersList.PATH_BUTTONS + "user.png";
242: }
243: }
244: };
245: iconAction.setName(Messages.get().container(
246: Messages.GUI_USERS_LIST_INROLE_NAME_0));
247: iconAction.setHelpText(Messages.get().container(
248: Messages.GUI_USERS_LIST_INROLE_HELP_0));
249: iconAction.setIconPath(PATH_BUTTONS + "user.png");
250: iconAction.setEnabled(false);
251: metadata.getColumnDefinition(LIST_COLUMN_ICON)
252: .removeDirectAction(LIST_ACTION_ICON);
253: metadata.getColumnDefinition(LIST_COLUMN_ICON).addDirectAction(
254: iconAction);
255: }
256:
257: /**
258: * @see org.opencms.workplace.tools.accounts.A_CmsRoleUsersList#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
259: */
260: protected void setIndependentActions(CmsListMetadata metadata) {
261:
262: super .setIndependentActions(metadata);
263:
264: metadata.getItemDetailDefinition(LIST_DETAIL_ORGUNIT)
265: .setVisible(false);
266: }
267:
268: /**
269: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
270: */
271: protected void setMultiActions(CmsListMetadata metadata) {
272:
273: // add add multi action
274: CmsListMultiAction addMultiAction = new CmsListMultiAction(
275: LIST_MACTION_ADD);
276: addMultiAction.setName(Messages.get().container(
277: Messages.GUI_USERS_LIST_MACTION_ADD_NAME_0));
278: addMultiAction.setHelpText(Messages.get().container(
279: Messages.GUI_USERS_LIST_MACTION_ADD_HELP_0));
280: addMultiAction.setConfirmationMessage(Messages.get().container(
281: Messages.GUI_USERS_LIST_MACTION_ADD_CONF_0));
282: addMultiAction.setIconPath(ICON_MULTI_ADD);
283: metadata.addMultiAction(addMultiAction);
284: }
285: }
|