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