001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/CmsOrgUnitsAdminList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.6 $
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.i18n.CmsMessageContainer;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.OpenCms;
038: import org.opencms.security.CmsOrganizationalUnit;
039: import org.opencms.workplace.CmsDialog;
040: import org.opencms.workplace.list.CmsListColumnAlignEnum;
041: import org.opencms.workplace.list.CmsListColumnDefinition;
042: import org.opencms.workplace.list.CmsListDefaultAction;
043: import org.opencms.workplace.list.CmsListDirectAction;
044: import org.opencms.workplace.list.CmsListMetadata;
045:
046: import java.io.IOException;
047: import java.util.HashMap;
048: import java.util.List;
049: import java.util.Map;
050:
051: import javax.servlet.ServletException;
052: import javax.servlet.http.HttpServletRequest;
053: import javax.servlet.http.HttpServletResponse;
054: import javax.servlet.jsp.PageContext;
055:
056: /**
057: * Admin organization unit management view.<p>
058: *
059: * @author Raphael Schnuck
060: *
061: * @version $Revision: 1.6 $
062: *
063: * @since 6.5.6
064: */
065: public class CmsOrgUnitsAdminList extends A_CmsOrgUnitsList {
066:
067: /** list id constant. */
068: public static final String LIST_ID = "lsoua";
069:
070: /** list action id constant. */
071: protected static final String LIST_ACTION_OVERVIEW = "ao";
072:
073: /** list column id constant. */
074: protected static final String LIST_COLUMN_OVERVIEW = "co";
075:
076: /**
077: * Public constructor.<p>
078: *
079: * @param jsp an initialized JSP action element
080: */
081: public CmsOrgUnitsAdminList(CmsJspActionElement jsp) {
082:
083: super (jsp, LIST_ID, Messages.get().container(
084: Messages.GUI_ADMINORGUNITS_LIST_NAME_0));
085: }
086:
087: /**
088: * Public constructor with JSP variables.<p>
089: *
090: * @param context the JSP page context
091: * @param req the JSP request
092: * @param res the JSP response
093: */
094: public CmsOrgUnitsAdminList(PageContext context,
095: HttpServletRequest req, HttpServletResponse res) {
096:
097: this (new CmsJspActionElement(context, req, res));
098: }
099:
100: /**
101: *
102: * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtml()
103: */
104: public String defaultActionHtml() {
105:
106: if ((getList() != null) && getList().getAllContent().isEmpty()) {
107: // TODO: check the need for this
108: refreshList();
109: }
110: StringBuffer result = new StringBuffer(2048);
111: result.append(defaultActionHtmlStart());
112: result.append(customHtmlStart());
113: try {
114:
115: if (hasMoreAdminOUs()) {
116: result.append(defaultActionHtmlContent());
117: }
118: } catch (CmsException e) {
119: // noop
120: }
121: result.append(customHtmlEnd());
122: result.append(defaultActionHtmlEnd());
123: return result.toString();
124: }
125:
126: /**
127: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
128: */
129: public void executeListSingleActions() throws IOException,
130: ServletException {
131:
132: String ouFqn = getSelectedItem().get(LIST_COLUMN_NAME)
133: .toString();
134: if (ouFqn == null) {
135: ouFqn = "";
136: }
137: Map params = new HashMap();
138: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, ouFqn.substring(1));
139: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
140: if (getParamListAction().equals(LIST_ACTION_OVERVIEW)) {
141: // forward to the edit user screen
142: getToolManager().jspForwardTool(this ,
143: getCurrentToolPath() + "/orgunit", params);
144: } else if (getParamListAction().equals(LIST_ACTION_USER)) {
145: // forward to the edit user screen
146: getToolManager().jspForwardTool(this , getUsersToolPath(),
147: params);
148: } else if (getParamListAction().equals(LIST_ACTION_GROUP)) {
149: // forward to the edit user screen
150: getToolManager().jspForwardTool(this , getGroupsToolPath(),
151: params);
152: } else if (getParamListAction().equals(LIST_DEFACTION_OVERVIEW)) {
153: // forward to the edit user screen
154: getToolManager().jspForwardTool(this ,
155: getCurrentToolPath() + "/orgunit", params);
156: } else {
157: throwListUnsupportedActionException();
158: }
159: listSave();
160: }
161:
162: /**
163: * Returns the tool path of the groups management tool.<p>
164: *
165: * @return the tool path of the groups management tool
166: */
167: protected String getGroupsToolPath() {
168:
169: return getCurrentToolPath() + "/orgunit/groups";
170: }
171:
172: /**
173: * Returns the tool path of the users management tool.<p>
174: *
175: * @return the tool path of the users management tool
176: */
177: protected String getUsersToolPath() {
178:
179: return getCurrentToolPath() + "/orgunit/users";
180: }
181:
182: /**
183: * Performs a forward to the overview of the single organizational unit the current user
184: * is allowed to administrate.<p>
185: *
186: * @throws ServletException in case of errors during forwarding
187: * @throws IOException in case of errors during forwarding
188: * @throws CmsException in case of errors during getting orgunits
189: */
190: public void forwardToSingleAdminOU() throws ServletException,
191: IOException, CmsException {
192:
193: List orgUnits = getOrgUnits();
194:
195: if (orgUnits.isEmpty()) {
196: OpenCms.getWorkplaceManager().getToolManager()
197: .jspForwardTool(this , "/", null);
198: return;
199: }
200:
201: Map params = new HashMap();
202: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN,
203: ((CmsOrganizationalUnit) orgUnits.get(0)).getName());
204: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
205:
206: OpenCms.getWorkplaceManager().getToolManager().jspForwardTool(
207: this , getForwardToolPath(), params);
208: }
209:
210: /**
211: * Returns the tool path to forward if there is only one single organizational unit.<p>
212: *
213: * @return the tool path to forward
214: */
215: protected String getForwardToolPath() {
216:
217: return "/accounts/orgunit";
218: }
219:
220: /**
221: * Returns the path of the overview icon.<p>
222: *
223: * @return the path of the overview icon
224: */
225: public String getOverviewIcon() {
226:
227: return PATH_BUTTONS + "orgunit.png";
228: }
229:
230: /**
231: * Checks if the user has more then one organizational unit to administrate.<p>
232: *
233: * @return true if the user has more then then one organizational unit to administrate
234: * otherwise false
235: * @throws CmsException if the organizational units can not be read
236: */
237: public boolean hasMoreAdminOUs() throws CmsException {
238:
239: List orgUnits = getOrgUnits();
240:
241: if (orgUnits == null) {
242: return false;
243: }
244: if (orgUnits.size() <= 1) {
245: return false;
246: }
247: return true;
248: }
249:
250: /**
251: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
252: */
253: protected void setColumns(CmsListMetadata metadata) {
254:
255: // create column for overview
256: CmsListColumnDefinition overviewCol = new CmsListColumnDefinition(
257: LIST_COLUMN_OVERVIEW);
258: overviewCol.setName(Messages.get().container(
259: Messages.GUI_ORGUNITS_LIST_COLS_OVERVIEW_0));
260: overviewCol.setHelpText(Messages.get().container(
261: Messages.GUI_ORGUNITS_LIST_COLS_OVERVIEW_HELP_0));
262: overviewCol.setWidth("20");
263: overviewCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
264: overviewCol.setSorteable(false);
265: // add overview action
266: CmsListDirectAction overviewAction = new CmsListDirectAction(
267: LIST_ACTION_OVERVIEW) {
268:
269: /**
270: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getName()
271: */
272: public CmsMessageContainer getName() {
273:
274: if (getItem() != null) {
275: if (((Boolean) getItem().get(LIST_COLUMN_WEBUSER))
276: .booleanValue()) {
277: return Messages
278: .get()
279: .container(
280: Messages.GUI_WEBOUS_LIST_ACTION_OVERVIEW_NAME_0);
281: }
282: }
283: return super .getName();
284: }
285:
286: /**
287: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
288: */
289: public String getIconPath() {
290:
291: if (getItem() != null) {
292: if (((Boolean) getItem().get(LIST_COLUMN_WEBUSER))
293: .booleanValue()) {
294: return PATH_BUTTONS + "webuser_ou.png";
295: }
296: }
297: return super .getIconPath();
298: }
299: };
300: overviewAction.setName(Messages.get().container(
301: Messages.GUI_ORGUNITS_LIST_ACTION_OVERVIEW_NAME_0));
302: overviewAction.setHelpText(Messages.get().container(
303: Messages.GUI_ORGUNITS_LIST_COLS_OVERVIEW_HELP_0));
304: overviewAction.setIconPath(getOverviewIcon());
305: overviewCol.addDirectAction(overviewAction);
306: // add it to the list definition
307: metadata.addColumn(overviewCol);
308:
309: // create column for user
310: CmsListColumnDefinition userCol = new CmsListColumnDefinition(
311: LIST_COLUMN_USER);
312: userCol.setName(Messages.get().container(
313: Messages.GUI_ORGUNITS_LIST_COLS_USER_0));
314: userCol.setHelpText(Messages.get().container(
315: Messages.GUI_ORGUNITS_LIST_COLS_USER_HELP_0));
316: userCol.setWidth("20");
317: userCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
318: userCol.setSorteable(false);
319: // add user action
320: CmsListDirectAction userAction = new CmsListDirectAction(
321: LIST_ACTION_USER);
322: userAction.setName(Messages.get().container(
323: Messages.GUI_ORGUNITS_LIST_ACTION_USER_NAME_0));
324: userAction.setHelpText(Messages.get().container(
325: Messages.GUI_ORGUNITS_LIST_COLS_USER_HELP_0));
326: userAction.setIconPath(getUserIcon());
327: userCol.addDirectAction(userAction);
328: // add it to the list definition
329: metadata.addColumn(userCol);
330:
331: // create column for group
332: CmsListColumnDefinition groupCol = new CmsListColumnDefinition(
333: LIST_COLUMN_GROUP);
334: groupCol.setName(Messages.get().container(
335: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_0));
336: groupCol.setHelpText(Messages.get().container(
337: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_HELP_0));
338: groupCol.setWidth("20");
339: groupCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
340: groupCol.setSorteable(false);
341: // add group action
342: CmsListDirectAction groupAction = new CmsListDirectAction(
343: LIST_ACTION_GROUP);
344: groupAction.setName(Messages.get().container(
345: Messages.GUI_ORGUNITS_LIST_ACTION_GROUP_NAME_0));
346: groupAction.setHelpText(Messages.get().container(
347: Messages.GUI_ORGUNITS_LIST_COLS_GROUP_HELP_0));
348: groupAction.setIconPath(getGroupIcon());
349: groupCol.addDirectAction(groupAction);
350: // add it to the list definition
351: metadata.addColumn(groupCol);
352:
353: // create column for description
354: CmsListColumnDefinition descCol = new CmsListColumnDefinition(
355: LIST_COLUMN_DESCRIPTION);
356: descCol.setName(Messages.get().container(
357: Messages.GUI_ORGUNITS_LIST_COLS_DESCRIPTION_0));
358: descCol.setWidth("60%");
359: descCol.setSorteable(true);
360: // create default overview action
361: CmsListDefaultAction defOverviewAction = new CmsListDefaultAction(
362: LIST_DEFACTION_OVERVIEW);
363: defOverviewAction.setName(Messages.get().container(
364: Messages.GUI_ORGUNITS_LIST_DEFACTION_OVERVIEW_NAME_0));
365: defOverviewAction.setHelpText(Messages.get().container(
366: Messages.GUI_ORGUNITS_LIST_COLS_OVERVIEW_HELP_0));
367: descCol.addDefaultAction(defOverviewAction);
368: // add it to the list definition
369: metadata.addColumn(descCol);
370:
371: // create column for name / path
372: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
373: LIST_COLUMN_NAME);
374: nameCol.setName(Messages.get().container(
375: Messages.GUI_ORGUNITS_LIST_COLS_NAME_0));
376: nameCol.setWidth("40%");
377: nameCol.setSorteable(true);
378: // add it to the list definition
379: metadata.addColumn(nameCol);
380:
381: // create column for manageable flag
382: CmsListColumnDefinition adminCol = new CmsListColumnDefinition(
383: LIST_COLUMN_ADMIN);
384: adminCol.setVisible(false);
385: metadata.addColumn(adminCol);
386:
387: // create column for webuser flag
388: CmsListColumnDefinition webuserCol = new CmsListColumnDefinition(
389: LIST_COLUMN_WEBUSER);
390: webuserCol.setVisible(false);
391: metadata.addColumn(webuserCol);
392: }
393: }
|