001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/accounts/A_CmsUsersList.java,v $
003: * Date : $Date: 2008-02-27 12:05:26 $
004: * Version: $Revision: 1.8 $
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.file.CmsUser;
036: import org.opencms.i18n.CmsMessageContainer;
037: import org.opencms.jsp.CmsJspActionElement;
038: import org.opencms.main.CmsException;
039: import org.opencms.main.CmsRuntimeException;
040: import org.opencms.main.OpenCms;
041: import org.opencms.security.CmsRole;
042: import org.opencms.workplace.CmsDialog;
043: import org.opencms.workplace.list.A_CmsListDialog;
044: import org.opencms.workplace.list.CmsListColumnAlignEnum;
045: import org.opencms.workplace.list.CmsListColumnDefinition;
046: import org.opencms.workplace.list.CmsListDateMacroFormatter;
047: import org.opencms.workplace.list.CmsListDefaultAction;
048: import org.opencms.workplace.list.CmsListDirectAction;
049: import org.opencms.workplace.list.CmsListItem;
050: import org.opencms.workplace.list.CmsListItemActionIconComparator;
051: import org.opencms.workplace.list.CmsListItemDetails;
052: import org.opencms.workplace.list.CmsListItemDetailsFormatter;
053: import org.opencms.workplace.list.CmsListMetadata;
054: import org.opencms.workplace.list.CmsListMultiAction;
055: import org.opencms.workplace.list.CmsListOrderEnum;
056: import org.opencms.workplace.list.CmsListSearchAction;
057:
058: import java.io.IOException;
059: import java.util.ArrayList;
060: import java.util.Date;
061: import java.util.HashMap;
062: import java.util.HashSet;
063: import java.util.Iterator;
064: import java.util.List;
065: import java.util.Map;
066: import java.util.Set;
067:
068: import javax.servlet.ServletException;
069:
070: /**
071: * Main user account management view.<p>
072: *
073: * @author Michael Moossen
074: *
075: * @version $Revision: 1.8 $
076: *
077: * @since 6.0.0
078: */
079: public abstract class A_CmsUsersList extends A_CmsListDialog {
080:
081: /** list action id constant. */
082: public static final String LIST_ACTION_ACTIVATE = "aa";
083:
084: /** list action id constant. */
085: public static final String LIST_ACTION_DEACTIVATE = "ac";
086:
087: /** list action id constant. */
088: public static final String LIST_ACTION_DELETE = "ad";
089:
090: /** list action id constant. */
091: public static final String LIST_ACTION_EDIT = "ae";
092:
093: /** list action id constant. */
094: public static final String LIST_ACTION_GROUPS = "ag";
095:
096: /** list action id constant. */
097: public static final String LIST_ACTION_ROLE = "ar";
098:
099: /** list action id constant. */
100: public static final String LIST_ACTION_ROLES = "ar";
101:
102: /** list column id constant. */
103: public static final String LIST_COLUMN_ACTIVATE = "ca";
104:
105: /** list column id constant. */
106: public static final String LIST_COLUMN_DELETE = "cd";
107:
108: /** list column id constant. */
109: public static final String LIST_COLUMN_DISPLAY = "cdn";
110:
111: /** list column id constant. */
112: public static final String LIST_COLUMN_EDIT = "ce";
113:
114: /** list column id constant. */
115: public static final String LIST_COLUMN_EMAIL = "cm";
116:
117: /** list column id constant. */
118: public static final String LIST_COLUMN_GROUPS = "cg";
119:
120: /** list column id constant. */
121: public static final String LIST_COLUMN_LASTLOGIN = "cl";
122:
123: /** list column id constant. */
124: public static final String LIST_COLUMN_LOGIN = "ci";
125:
126: /** list column id constant. */
127: public static final String LIST_COLUMN_ENABLED = "ceb";
128:
129: /** list column id constant. */
130: public static final String LIST_COLUMN_NAME = "cn";
131:
132: /** list action id constant. */
133: public static final String LIST_COLUMN_ROLE = "cr";
134:
135: /** list action id constant. */
136: public static final String LIST_DEFACTION_EDIT = "de";
137:
138: /** list item detail id constant. */
139: public static final String LIST_DETAIL_ADDRESS = "da";
140:
141: /** list item detail id constant. */
142: public static final String LIST_DETAIL_GROUPS = "dg";
143:
144: /** list item detail id constant. */
145: public static final String LIST_DETAIL_ROLES = "dr";
146:
147: /** list action id constant. */
148: public static final String LIST_MACTION_ACTIVATE = "ma";
149:
150: /** list action id constant. */
151: public static final String LIST_MACTION_DEACTIVATE = "mc";
152:
153: /** list action id constant. */
154: public static final String LIST_MACTION_DELETE = "md";
155:
156: /** Path to the list buttons. */
157: public static final String PATH_BUTTONS = "tools/accounts/buttons/";
158:
159: /** a set of action id's to use for deletion. */
160: private static Set m_deleteActionIds = new HashSet();
161:
162: /** a set of action id's to use for edition. */
163: private static Set m_editActionIds = new HashSet();
164:
165: /** Stores the value of the request parameter for the organizational unit fqn. */
166: private String m_paramOufqn;
167:
168: /**
169: * Public constructor.<p>
170: *
171: * @param jsp an initialized JSP action element
172: * @param listId the id of the list
173: * @param listName the list name
174: */
175: public A_CmsUsersList(CmsJspActionElement jsp, String listId,
176: CmsMessageContainer listName) {
177:
178: super (jsp, listId, listName, LIST_COLUMN_DISPLAY,
179: CmsListOrderEnum.ORDER_ASCENDING, null);
180: }
181:
182: /**
183: * This method should handle every defined list multi action,
184: * by comparing <code>{@link #getParamListAction()}</code> with the id
185: * of the action to execute.<p>
186: *
187: * @throws CmsRuntimeException to signal that an action is not supported
188: *
189: */
190: public void executeListMultiActions() throws CmsRuntimeException {
191:
192: if (getParamListAction().equals(LIST_MACTION_DELETE)) {
193: // execute the delete multiaction
194: Map params = new HashMap();
195: params.put(A_CmsEditUserDialog.PARAM_USERID,
196: getParamSelItems());
197: // set action parameter to initial dialog call
198: params
199: .put(CmsDialog.PARAM_ACTION,
200: CmsDialog.DIALOG_INITIAL);
201:
202: try {
203: getToolManager().jspForwardTool(this ,
204: getCurrentToolPath() + "/delete", params);
205: } catch (Exception e) {
206: throw new CmsRuntimeException(Messages.get().container(
207: Messages.ERR_DELETE_SELECTED_USERS_0), e);
208: }
209: } else if (getParamListAction().equals(LIST_MACTION_ACTIVATE)) {
210: // execute the activate multiaction
211: try {
212: Iterator itItems = getSelectedItems().iterator();
213: while (itItems.hasNext()) {
214: CmsListItem listItem = (CmsListItem) itItems.next();
215: String usrName = listItem.get(LIST_COLUMN_LOGIN)
216: .toString();
217: CmsUser user = readUser(usrName);
218: if (!user.isEnabled()) {
219: user.setEnabled(true);
220: getCms().writeUser(user);
221: }
222: }
223: } catch (CmsException e) {
224: throw new CmsRuntimeException(Messages.get().container(
225: Messages.ERR_ACTIVATE_SELECTED_USERS_0), e);
226: }
227: // refreshing no needed becaus the activate action does not add/remove rows to the list
228: } else if (getParamListAction().equals(LIST_MACTION_DEACTIVATE)) {
229: // execute the activate multiaction
230: try {
231: Iterator itItems = getSelectedItems().iterator();
232: while (itItems.hasNext()) {
233: CmsListItem listItem = (CmsListItem) itItems.next();
234: String usrName = listItem.get(LIST_COLUMN_LOGIN)
235: .toString();
236: CmsUser user = readUser(usrName);
237: if (user.isEnabled()) {
238: user.setEnabled(false);
239: getCms().writeUser(user);
240: }
241: }
242: } catch (CmsException e) {
243: throw new CmsRuntimeException(Messages.get().container(
244: Messages.ERR_DEACTIVATE_SELECTED_USERS_0), e);
245: }
246: // refreshing no needed becaus the activate action does not add/remove rows to the list
247: } else {
248: throwListUnsupportedActionException();
249: }
250: listSave();
251: }
252:
253: /**
254: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
255: */
256: public void executeListSingleActions() throws IOException,
257: ServletException {
258:
259: String userId = getSelectedItem().getId();
260: String userName = getSelectedItem().get(LIST_COLUMN_LOGIN)
261: .toString();
262:
263: Map params = new HashMap();
264: params.put(A_CmsEditUserDialog.PARAM_USERID, userId);
265: params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, getParamOufqn());
266: // set action parameter to initial dialog call
267: params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
268:
269: if (getParamListAction().equals(LIST_ACTION_ROLE)) {
270: getToolManager().jspForwardTool(this ,
271: getCurrentToolPath() + "/edit/role", params);
272: } else if (getParamListAction().equals(LIST_DEFACTION_EDIT)) {
273: // forward to the edit user screen
274: getToolManager().jspForwardTool(this ,
275: getCurrentToolPath() + "/edit", params);
276: } else if (m_editActionIds.contains(getParamListAction())) {
277: getToolManager().jspForwardTool(this ,
278: getCurrentToolPath() + "/edit/user", params);
279: } else if (getParamListAction().equals(LIST_ACTION_GROUPS)) {
280: getToolManager().jspForwardTool(this ,
281: getCurrentToolPath() + "/edit/groups", params);
282: } else if (m_deleteActionIds.contains(getParamListAction())) {
283: getToolManager().jspForwardTool(this ,
284: getCurrentToolPath() + "/edit/delete", params);
285: } else if (getParamListAction().equals(LIST_ACTION_ACTIVATE)) {
286: // execute the activate action
287: try {
288: CmsUser user = readUser(userName);
289: user.setEnabled(true);
290: getCms().writeUser(user);
291: } catch (CmsException e) {
292: throw new CmsRuntimeException(Messages.get().container(
293: Messages.ERR_ACTIVATE_USER_1, userName), e);
294: }
295: } else if (getParamListAction().equals(LIST_ACTION_DEACTIVATE)) {
296: // execute the activate action
297: try {
298: CmsUser user = readUser(userName);
299: user.setEnabled(false);
300: getCms().writeUser(user);
301: } catch (CmsException e) {
302: throw new CmsRuntimeException(Messages.get().container(
303: Messages.ERR_DEACTIVATE_USER_1, userName), e);
304: }
305: } else {
306: throwListUnsupportedActionException();
307: }
308: listSave();
309: }
310:
311: /**
312: * Returns the organizational unit fqn parameter value.<p>
313: *
314: * @return the organizational unit fqn parameter value
315: */
316: public String getParamOufqn() {
317:
318: return m_paramOufqn;
319: }
320:
321: /**
322: * Sets the organizational unit fqn parameter value.<p>
323: *
324: * @param ouFqn the organizational unit fqn parameter value
325: */
326: public void setParamOufqn(String ouFqn) {
327:
328: if (ouFqn == null) {
329: ouFqn = "";
330: }
331: m_paramOufqn = ouFqn;
332: }
333:
334: /**
335: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
336: */
337: protected void fillDetails(String detailId) {
338:
339: // get content
340: List users = getList().getAllContent();
341: Iterator itUsers = users.iterator();
342: while (itUsers.hasNext()) {
343: CmsListItem item = (CmsListItem) itUsers.next();
344: String userName = item.get(LIST_COLUMN_LOGIN).toString();
345: StringBuffer html = new StringBuffer(512);
346: try {
347: if (detailId.equals(LIST_DETAIL_ADDRESS)) {
348: CmsUser user = readUser(userName);
349: // address
350: html.append(user.getAddress());
351: if (user.getCity() != null) {
352: html.append("<br>");
353: if (user.getZipcode() != null) {
354: html.append(user.getZipcode());
355: html.append(" ");
356: }
357: html.append(user.getCity());
358: }
359: if (user.getCountry() != null) {
360: html.append("<br>");
361: html.append(user.getCountry());
362: }
363: } else if (detailId.equals(LIST_DETAIL_GROUPS)) {
364: // groups
365: List groups = getCms().getGroupsOfUser(userName,
366: true, true);
367: Iterator itGroups = groups.iterator();
368: while (itGroups.hasNext()) {
369: CmsGroup group = (CmsGroup) itGroups.next();
370: if (group.getOuFqn().equals(getParamOufqn())) {
371: html.append(group.getSimpleName());
372: } else {
373: html.append(group.getDisplayName(getCms(),
374: getLocale()));
375: }
376: if (itGroups.hasNext()) {
377: html.append("<br>");
378: }
379: html.append("\n");
380: }
381: } else if (detailId.equals(LIST_DETAIL_ROLES)) {
382: // roles
383: boolean otherOuRole = false;
384: List roles = OpenCms.getRoleManager()
385: .getRolesOfUser(getCms(), userName, "/",
386: true, true, false);
387: Iterator itRoles = roles.iterator();
388: while (itRoles.hasNext()) {
389: CmsRole role = (CmsRole) itRoles.next();
390: if (!role.getOuFqn().equals(getParamOufqn())) {
391: otherOuRole = true;
392: break;
393: }
394: }
395: itRoles = roles.iterator();
396: while (itRoles.hasNext()) {
397: CmsRole role = (CmsRole) itRoles.next();
398: if (!otherOuRole) {
399: html.append(role.getName(getLocale()));
400: } else {
401: html.append(role.getDisplayName(getCms(),
402: getLocale()));
403: }
404: if (itRoles.hasNext()) {
405: html.append("<br>");
406: }
407: html.append("\n");
408: }
409: } else {
410: continue;
411: }
412: } catch (Exception e) {
413: // noop
414: }
415: item.set(detailId, html.toString());
416: }
417: }
418:
419: /**
420: * Returns the path the group icon.<p>
421: *
422: * @return the path to the group icon
423: */
424: protected abstract String getGroupIcon();
425:
426: /**
427: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
428: */
429: protected List getListItems() throws CmsException {
430:
431: List ret = new ArrayList();
432: // get content
433: List users = getUsers();
434: Iterator itUsers = users.iterator();
435: while (itUsers.hasNext()) {
436: CmsUser user = (CmsUser) itUsers.next();
437: CmsListItem item = getList().newItem(
438: user.getId().toString());
439: setUserData(user, item);
440: ret.add(item);
441: }
442: CmsListColumnDefinition colDef = getList().getMetadata()
443: .getColumnDefinition(LIST_COLUMN_ROLE);
444: if (colDef != null) {
445: colDef.setVisible(!OpenCms.getOrgUnitManager()
446: .readOrganizationalUnit(getCms(), getParamOufqn())
447: .hasFlagWebuser());
448: }
449: return ret;
450: }
451:
452: /**
453: * Returns the path the role edit icon.<p>
454: *
455: * @return the path to the role edit icon
456: */
457: protected String getRoleIcon() {
458:
459: return PATH_BUTTONS + "role.png";
460: }
461:
462: /**
463: * Returns a list of users.<p>
464: *
465: * @return the list of all users
466: *
467: * @throws CmsException if something goes wrong
468: */
469: protected abstract List getUsers() throws CmsException;
470:
471: /**
472: * @see org.opencms.workplace.CmsWorkplace#initMessages()
473: */
474: protected void initMessages() {
475:
476: // add specific dialog resource bundle
477: addMessages(Messages.get().getBundleName());
478: // add default resource bundles
479: super .initMessages();
480: }
481:
482: /**
483: * Reads the user.<p>
484: *
485: * @param name the name of the user to read
486: *
487: * @return the user
488: *
489: * @throws CmsException if something goes wrong
490: */
491: protected abstract CmsUser readUser(String name)
492: throws CmsException;
493:
494: /**
495: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
496: */
497: protected void setColumns(CmsListMetadata metadata) {
498:
499: // create column for edit
500: CmsListColumnDefinition editCol = new CmsListColumnDefinition(
501: LIST_COLUMN_EDIT);
502: editCol.setName(Messages.get().container(
503: Messages.GUI_USERS_LIST_COLS_EDIT_0));
504: editCol.setHelpText(Messages.get().container(
505: Messages.GUI_USERS_LIST_COLS_EDIT_HELP_0));
506: editCol.setWidth("20");
507: editCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
508: editCol.setSorteable(false);
509:
510: // add edit action
511: setEditAction(editCol);
512: m_editActionIds.addAll(editCol.getDirectActionIds());
513: // add it to the list definition
514: metadata.addColumn(editCol);
515:
516: // create column for group edition
517: CmsListColumnDefinition groupCol = new CmsListColumnDefinition(
518: LIST_COLUMN_GROUPS);
519: groupCol.setName(Messages.get().container(
520: Messages.GUI_USERS_LIST_COLS_GROUPS_0));
521: groupCol.setHelpText(Messages.get().container(
522: Messages.GUI_USERS_LIST_COLS_GROUPS_HELP_0));
523: groupCol.setWidth("20");
524: groupCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
525: groupCol.setSorteable(false);
526: // add groups action
527: CmsListDirectAction groupAction = new CmsListDirectAction(
528: LIST_ACTION_GROUPS);
529: groupAction.setName(Messages.get().container(
530: Messages.GUI_USERS_LIST_ACTION_GROUPS_NAME_0));
531: groupAction.setHelpText(Messages.get().container(
532: Messages.GUI_USERS_LIST_ACTION_GROUPS_HELP_0));
533: groupAction.setIconPath(getGroupIcon());
534: groupCol.addDirectAction(groupAction);
535: // add it to the list definition
536: metadata.addColumn(groupCol);
537:
538: // create column for edit role
539: CmsListColumnDefinition roleCol = new CmsListColumnDefinition(
540: LIST_COLUMN_ROLE);
541: roleCol.setName(Messages.get().container(
542: Messages.GUI_USERS_LIST_COLS_ROLE_0));
543: roleCol.setHelpText(Messages.get().container(
544: Messages.GUI_USERS_LIST_COLS_ROLE_HELP_0));
545: roleCol.setWidth("20");
546: roleCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
547: roleCol.setSorteable(false);
548: // add role action
549: CmsListDirectAction roleAction = new CmsListDirectAction(
550: LIST_ACTION_ROLE);
551: roleAction.setName(Messages.get().container(
552: Messages.GUI_USERS_LIST_ACTION_ROLE_NAME_0));
553: roleAction.setHelpText(Messages.get().container(
554: Messages.GUI_USERS_LIST_ACTION_ROLE_HELP_0));
555: roleAction.setIconPath(getRoleIcon());
556: roleCol.addDirectAction(roleAction);
557: // add it to the list definition
558: metadata.addColumn(roleCol);
559:
560: // create column for activation/deactivation
561: CmsListColumnDefinition actCol = new CmsListColumnDefinition(
562: LIST_COLUMN_ACTIVATE);
563: actCol.setName(Messages.get().container(
564: Messages.GUI_USERS_LIST_COLS_ACTIVATE_0));
565: actCol.setHelpText(Messages.get().container(
566: Messages.GUI_USERS_LIST_COLS_ACTIVATE_HELP_0));
567: actCol.setWidth("20");
568: actCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
569: actCol
570: .setListItemComparator(new CmsListItemActionIconComparator());
571:
572: // activate action
573: CmsListDirectAction actAction = new CmsListDirectAction(
574: LIST_ACTION_ACTIVATE) {
575:
576: /**
577: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
578: */
579: public boolean isVisible() {
580:
581: if (getItem() == null) {
582: return super .isVisible();
583: }
584: Boolean enabled = (Boolean) getItem().get(
585: LIST_COLUMN_ENABLED);
586: if (enabled == null) {
587: return super .isVisible();
588: }
589: return !enabled.booleanValue();
590: }
591: };
592: actAction.setName(Messages.get().container(
593: Messages.GUI_USERS_LIST_ACTION_ACTIVATE_NAME_0));
594: actAction.setHelpText(Messages.get().container(
595: Messages.GUI_USERS_LIST_ACTION_ACTIVATE_HELP_0));
596: actAction.setConfirmationMessage(Messages.get().container(
597: Messages.GUI_USERS_LIST_ACTION_ACTIVATE_CONF_0));
598: actAction.setIconPath(ICON_INACTIVE);
599: actCol.addDirectAction(actAction);
600:
601: // deactivate action
602: CmsListDirectAction deactAction = new CmsListDirectAction(
603: LIST_ACTION_DEACTIVATE) {
604:
605: /**
606: * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
607: */
608: public boolean isVisible() {
609:
610: if (getItem() == null) {
611: return super .isVisible();
612: }
613: Boolean enabled = (Boolean) getItem().get(
614: LIST_COLUMN_ENABLED);
615: if (enabled == null) {
616: return super .isVisible();
617: }
618: return enabled.booleanValue();
619: }
620: };
621: deactAction.setName(Messages.get().container(
622: Messages.GUI_USERS_LIST_ACTION_DEACTIVATE_NAME_0));
623: deactAction.setHelpText(Messages.get().container(
624: Messages.GUI_USERS_LIST_ACTION_DEACTIVATE_HELP_0));
625: deactAction.setConfirmationMessage(Messages.get().container(
626: Messages.GUI_USERS_LIST_ACTION_DEACTIVATE_CONF_0));
627: deactAction.setIconPath(ICON_ACTIVE);
628: actCol.addDirectAction(deactAction);
629:
630: // add it to the list definition
631: metadata.addColumn(actCol);
632:
633: // create column for deletion
634: CmsListColumnDefinition deleteCol = new CmsListColumnDefinition(
635: LIST_COLUMN_DELETE);
636: deleteCol.setName(Messages.get().container(
637: Messages.GUI_USERS_LIST_COLS_DELETE_0));
638: deleteCol.setHelpText(Messages.get().container(
639: Messages.GUI_USERS_LIST_COLS_DELETE_HELP_0));
640: deleteCol.setWidth("20");
641: deleteCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
642: deleteCol.setSorteable(false);
643: // add delete action
644: setDeleteAction(deleteCol);
645: m_deleteActionIds.addAll(deleteCol.getDirectActionIds());
646:
647: // add it to the list definition
648: metadata.addColumn(deleteCol);
649:
650: // create column for login
651: CmsListColumnDefinition loginCol = new CmsListColumnDefinition(
652: LIST_COLUMN_LOGIN);
653: metadata.addColumn(loginCol);
654: loginCol.setVisible(false);
655:
656: // create column for display name
657: CmsListColumnDefinition displayCol = new CmsListColumnDefinition(
658: LIST_COLUMN_DISPLAY);
659: displayCol.setName(Messages.get().container(
660: Messages.GUI_USERS_LIST_COLS_LOGIN_0));
661: displayCol.setWidth("20%");
662:
663: // create default edit action
664: CmsListDefaultAction defEditAction = new CmsListDefaultAction(
665: LIST_DEFACTION_EDIT);
666: defEditAction.setName(Messages.get().container(
667: Messages.GUI_USERS_LIST_DEFACTION_EDIT_NAME_0));
668: defEditAction.setHelpText(Messages.get().container(
669: Messages.GUI_USERS_LIST_DEFACTION_EDIT_HELP_0));
670: displayCol.addDefaultAction(defEditAction);
671:
672: // add it to the list definition
673: metadata.addColumn(displayCol);
674:
675: // add column for name
676: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
677: LIST_COLUMN_NAME);
678: nameCol.setName(Messages.get().container(
679: Messages.GUI_USERS_LIST_COLS_USERNAME_0));
680: nameCol.setWidth("30%");
681: metadata.addColumn(nameCol);
682:
683: // add column for email
684: CmsListColumnDefinition emailCol = new CmsListColumnDefinition(
685: LIST_COLUMN_EMAIL);
686: emailCol.setName(Messages.get().container(
687: Messages.GUI_USERS_LIST_COLS_EMAIL_0));
688: emailCol.setWidth("30%");
689: metadata.addColumn(emailCol);
690:
691: // add column for last login date
692: CmsListColumnDefinition lastLoginCol = new CmsListColumnDefinition(
693: LIST_COLUMN_LASTLOGIN);
694: lastLoginCol.setName(Messages.get().container(
695: Messages.GUI_USERS_LIST_COLS_LASTLOGIN_0));
696: lastLoginCol.setWidth("20%");
697: lastLoginCol.setFormatter(CmsListDateMacroFormatter
698: .getDefaultDateFormatter());
699: metadata.addColumn(lastLoginCol);
700:
701: // add column for enabled/disable
702: CmsListColumnDefinition flagCol = new CmsListColumnDefinition(
703: LIST_COLUMN_ENABLED);
704: flagCol.setName(Messages.get().container(
705: Messages.GUI_USERS_LIST_COLS_LASTLOGIN_0));
706: flagCol.setVisible(false);
707: metadata.addColumn(flagCol);
708: }
709:
710: /**
711: * Sets the needed delete action(s).<p>
712: *
713: * @param deleteCol the list column for deletion.
714: */
715: protected abstract void setDeleteAction(
716: CmsListColumnDefinition deleteCol);
717:
718: /**
719: * Sets the needed edit action(s).<p>
720: *
721: * @param editCol the list column for edition.
722: */
723: protected abstract void setEditAction(
724: CmsListColumnDefinition editCol);
725:
726: /**
727: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
728: */
729: protected void setIndependentActions(CmsListMetadata metadata) {
730:
731: // add user address details
732: CmsListItemDetails userAddressDetails = new CmsListItemDetails(
733: LIST_DETAIL_ADDRESS);
734: userAddressDetails.setAtColumn(LIST_COLUMN_DISPLAY);
735: userAddressDetails.setVisible(false);
736: userAddressDetails.setShowActionName(Messages.get().container(
737: Messages.GUI_USERS_DETAIL_SHOW_ADDRESS_NAME_0));
738: userAddressDetails.setShowActionHelpText(Messages.get()
739: .container(
740: Messages.GUI_USERS_DETAIL_SHOW_ADDRESS_HELP_0));
741: userAddressDetails.setHideActionName(Messages.get().container(
742: Messages.GUI_USERS_DETAIL_HIDE_ADDRESS_NAME_0));
743: userAddressDetails.setHideActionHelpText(Messages.get()
744: .container(
745: Messages.GUI_USERS_DETAIL_HIDE_ADDRESS_HELP_0));
746: userAddressDetails.setName(Messages.get().container(
747: Messages.GUI_USERS_DETAIL_ADDRESS_NAME_0));
748: userAddressDetails
749: .setFormatter(new CmsListItemDetailsFormatter(
750: Messages
751: .get()
752: .container(
753: Messages.GUI_USERS_DETAIL_ADDRESS_NAME_0)));
754: metadata.addItemDetails(userAddressDetails);
755:
756: // add user groups details
757: CmsListItemDetails userGroupsDetails = new CmsListItemDetails(
758: LIST_DETAIL_GROUPS);
759: userGroupsDetails.setAtColumn(LIST_COLUMN_DISPLAY);
760: userGroupsDetails.setVisible(false);
761: userGroupsDetails.setShowActionName(Messages.get().container(
762: Messages.GUI_USERS_DETAIL_SHOW_GROUPS_NAME_0));
763: userGroupsDetails
764: .setShowActionHelpText(Messages.get().container(
765: Messages.GUI_USERS_DETAIL_SHOW_GROUPS_HELP_0));
766: userGroupsDetails.setHideActionName(Messages.get().container(
767: Messages.GUI_USERS_DETAIL_HIDE_GROUPS_NAME_0));
768: userGroupsDetails
769: .setHideActionHelpText(Messages.get().container(
770: Messages.GUI_USERS_DETAIL_HIDE_GROUPS_HELP_0));
771: userGroupsDetails.setName(Messages.get().container(
772: Messages.GUI_USERS_DETAIL_GROUPS_NAME_0));
773: userGroupsDetails.setFormatter(new CmsListItemDetailsFormatter(
774: Messages.get().container(
775: Messages.GUI_USERS_DETAIL_GROUPS_NAME_0)));
776: metadata.addItemDetails(userGroupsDetails);
777:
778: // add user roles details
779: CmsListItemDetails userRolesDetails = new CmsListItemDetails(
780: LIST_DETAIL_ROLES);
781: userRolesDetails.setAtColumn(LIST_COLUMN_DISPLAY);
782: userRolesDetails.setVisible(false);
783: userRolesDetails.setShowActionName(Messages.get().container(
784: Messages.GUI_USERS_DETAIL_SHOW_ROLES_NAME_0));
785: userRolesDetails
786: .setShowActionHelpText(Messages.get().container(
787: Messages.GUI_USERS_DETAIL_SHOW_ROLES_HELP_0));
788: userRolesDetails.setHideActionName(Messages.get().container(
789: Messages.GUI_USERS_DETAIL_HIDE_ROLES_NAME_0));
790: userRolesDetails
791: .setHideActionHelpText(Messages.get().container(
792: Messages.GUI_USERS_DETAIL_HIDE_ROLES_HELP_0));
793: userRolesDetails.setName(Messages.get().container(
794: Messages.GUI_USERS_DETAIL_ROLES_NAME_0));
795: userRolesDetails.setFormatter(new CmsListItemDetailsFormatter(
796: Messages.get().container(
797: Messages.GUI_USERS_DETAIL_ROLES_NAME_0)));
798: metadata.addItemDetails(userRolesDetails);
799:
800: // makes the list searchable
801: CmsListSearchAction searchAction = new CmsListSearchAction(
802: metadata.getColumnDefinition(LIST_COLUMN_DISPLAY));
803: searchAction.addColumn(metadata
804: .getColumnDefinition(LIST_COLUMN_NAME));
805: metadata.setSearchAction(searchAction);
806: }
807:
808: /**
809: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
810: */
811: protected void setMultiActions(CmsListMetadata metadata) {
812:
813: // add delete multi action
814: CmsListMultiAction deleteMultiAction = new CmsListMultiAction(
815: LIST_MACTION_DELETE);
816: deleteMultiAction.setName(Messages.get().container(
817: Messages.GUI_USERS_LIST_MACTION_DELETE_NAME_0));
818: deleteMultiAction.setHelpText(Messages.get().container(
819: Messages.GUI_USERS_LIST_MACTION_DELETE_HELP_0));
820: deleteMultiAction.setConfirmationMessage(Messages.get()
821: .container(
822: Messages.GUI_USERS_LIST_MACTION_DELETE_CONF_0));
823: deleteMultiAction.setIconPath(ICON_MULTI_DELETE);
824: metadata.addMultiAction(deleteMultiAction);
825:
826: // add the activate user multi action
827: CmsListMultiAction activateUser = new CmsListMultiAction(
828: LIST_MACTION_ACTIVATE);
829: activateUser.setName(Messages.get().container(
830: Messages.GUI_USERS_LIST_MACTION_ACTIVATE_NAME_0));
831: activateUser.setHelpText(Messages.get().container(
832: Messages.GUI_USERS_LIST_MACTION_ACTIVATE_HELP_0));
833: activateUser.setConfirmationMessage(Messages.get().container(
834: Messages.GUI_USERS_LIST_MACTION_ACTIVATE_CONF_0));
835: activateUser.setIconPath(ICON_MULTI_ACTIVATE);
836: metadata.addMultiAction(activateUser);
837:
838: // add the deactivate user multi action
839: CmsListMultiAction deactivateUser = new CmsListMultiAction(
840: LIST_MACTION_DEACTIVATE);
841: deactivateUser.setName(Messages.get().container(
842: Messages.GUI_USERS_LIST_MACTION_DEACTIVATE_NAME_0));
843: deactivateUser.setHelpText(Messages.get().container(
844: Messages.GUI_USERS_LIST_MACTION_DEACTIVATE_HELP_0));
845: deactivateUser.setConfirmationMessage(Messages.get().container(
846: Messages.GUI_USERS_LIST_MACTION_DEACTIVATE_CONF_0));
847: deactivateUser.setIconPath(ICON_MULTI_DEACTIVATE);
848: metadata.addMultiAction(deactivateUser);
849: }
850:
851: /**
852: * Sets all needed data of the user into the list item object.<p>
853: *
854: * @param user the user to set the data for
855: * @param item the list item object to set the data into
856: */
857: protected void setUserData(CmsUser user, CmsListItem item) {
858:
859: item.set(LIST_COLUMN_LOGIN, user.getName());
860: item.set(LIST_COLUMN_DISPLAY, user.getSimpleName());
861: item.set(LIST_COLUMN_NAME, user.getFullName());
862: item.set(LIST_COLUMN_EMAIL, user.getEmail());
863: item.set(LIST_COLUMN_LASTLOGIN, new Date(user.getLastlogin()));
864: item.set(LIST_COLUMN_ENABLED, new Boolean(user.isEnabled()));
865: }
866:
867: /**
868: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
869: */
870: protected void validateParamaters() throws Exception {
871:
872: // test the needed parameters
873: OpenCms.getRoleManager().checkRole(getCms(),
874: CmsRole.ACCOUNT_MANAGER.forOrgUnit(getParamOufqn()));
875: OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(),
876: getParamOufqn()).getName();
877: }
878: }
|