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.commons;
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.CmsAccessControlEntry;
038import org.opencms.security.CmsOrganizationalUnit;
039import org.opencms.security.CmsPrincipal;
040import org.opencms.security.CmsRole;
041import org.opencms.security.I_CmsPrincipal;
042import org.opencms.workplace.I_CmsGroupNameTranslation;
043import org.opencms.workplace.list.A_CmsListDefaultJsAction;
044import org.opencms.workplace.list.A_CmsListDialog;
045import org.opencms.workplace.list.CmsListColumnAlignEnum;
046import org.opencms.workplace.list.CmsListColumnDefinition;
047import org.opencms.workplace.list.CmsListDefaultAction;
048import org.opencms.workplace.list.CmsListDirectAction;
049import org.opencms.workplace.list.CmsListIndependentAction;
050import org.opencms.workplace.list.CmsListItem;
051import org.opencms.workplace.list.CmsListItemDetails;
052import org.opencms.workplace.list.CmsListItemDetailsFormatter;
053import org.opencms.workplace.list.CmsListMetadata;
054import org.opencms.workplace.list.CmsListOrderEnum;
055import org.opencms.workplace.list.CmsListSearchAction;
056import org.opencms.workplace.list.I_CmsListItemComparator;
057
058import java.text.Collator;
059import java.util.ArrayList;
060import java.util.Comparator;
061import java.util.HashSet;
062import java.util.Iterator;
063import java.util.List;
064import java.util.Locale;
065import java.util.Set;
066
067import javax.servlet.http.HttpServletRequest;
068import javax.servlet.http.HttpServletResponse;
069import javax.servlet.jsp.PageContext;
070
071/**
072 * Principal selection dialog.<p>
073 *
074 * @since 6.5.6
075 */
076public class CmsPrincipalSelectionList extends A_CmsListDialog {
077
078    /** list action id constant. */
079    public static final String LIST_ACTION_ICON = "ai";
080
081    /** list action id constant. */
082    public static final String LIST_ACTION_SELECT = "js";
083
084    /** list column id constant. */
085    public static final String LIST_COLUMN_DESCRIPTION = "cd";
086
087    /** list column id constant. */
088    public static final String LIST_COLUMN_DISPLAY = "cdn";
089
090    /** list column id constant. */
091    public static final String LIST_COLUMN_ICON = "ci";
092
093    /** list column id constant. */
094    public static final String LIST_COLUMN_NAME = "cn";
095
096    /** list column id constant. */
097    public static final String LIST_COLUMN_ORGUNIT = "cou";
098
099    /** list item detail id constant. */
100    public static final String LIST_DETAIL_OTHEROU = "doo";
101
102    /** list action id constant. */
103    public static final String LIST_IACTION_GROUPS = "iag";
104
105    /** list action id constant. */
106    public static final String LIST_IACTION_USERS = "iau";
107
108    /** list id constant. */
109    public static final String LIST_ID = "lus";
110
111    /** Path to the list buttons. */
112    public static final String PATH_BUTTONS = "tools/accounts/buttons/";
113
114    /** Item comparator to ensure that special principals go first. */
115    private static final I_CmsListItemComparator LIST_ITEM_COMPARATOR = new I_CmsListItemComparator() {
116
117        /**
118         * @see org.opencms.workplace.list.I_CmsListItemComparator#getComparator(java.lang.String, java.util.Locale)
119         */
120        @Override
121        @SuppressWarnings({"rawtypes", "unchecked"})
122        public Comparator getComparator(final String columnId, final Locale locale) {
123
124            final Collator collator = Collator.getInstance(locale);
125            final String overwriteAll = Messages.get().getBundle(locale).key(Messages.GUI_LABEL_OVERWRITEALL_0);
126            final String allOthers = Messages.get().getBundle(locale).key(Messages.GUI_LABEL_ALLOTHERS_0);
127
128            return new Comparator() {
129
130                /**
131                 * @see org.opencms.security.CmsAccessControlEntry#COMPARATOR_PRINCIPALS
132                 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
133                 */
134                @Override
135                public int compare(Object o1, Object o2) {
136
137                    if ((o1 == o2) || !(o1 instanceof CmsListItem) || !(o2 instanceof CmsListItem)) {
138                        return 0;
139                    }
140                    CmsListItem li1 = (CmsListItem)o1;
141                    CmsListItem li2 = (CmsListItem)o2;
142
143                    String id1 = (String)li1.get(LIST_COLUMN_DISPLAY);
144                    String id2 = (String)li2.get(LIST_COLUMN_DISPLAY);
145                    if (id1.equals(id2)) {
146                        return 0;
147                    } else if (id1.equals(overwriteAll)) {
148                        return -1;
149                    } else if (id1.equals(allOthers)) {
150                        if (id2.equals(overwriteAll)) {
151                            return 1;
152                        } else {
153                            return -1;
154                        }
155                    } else if (id2.equals(allOthers)) {
156                        if (id1.equals(overwriteAll)) {
157                            return -1;
158                        } else {
159                            return 1;
160                        }
161                    } else if (id2.equals(overwriteAll)) {
162                        return 1;
163                    }
164
165                    Comparable c1 = (Comparable)li1.get(columnId);
166                    Comparable c2 = (Comparable)li2.get(columnId);
167                    if ((c1 instanceof String) && (c2 instanceof String)) {
168                        return collator.compare(c1, c2);
169                    } else if (c1 != null) {
170                        if (c2 == null) {
171                            return 1;
172                        }
173                        return c1.compareTo(c2);
174                    } else if (c2 != null) {
175                        return -1;
176                    }
177                    return 0;
178                }
179            };
180        }
181
182    };
183
184    /** Cached value. */
185    private Boolean m_hasPrincipalsInOtherOus;
186
187    /** Stores the value of the request parameter for the flags. */
188    private String m_paramFlags;
189
190    /** The use parent flag, indicates the value should be set in the parent frame, not the window opener. */
191    private String m_paramUseparent;
192
193    /** The 'realonly' parameter value.*/
194    private String m_realOnly;
195
196    /**
197     * Public constructor.<p>
198     *
199     * @param jsp an initialized JSP action element
200     */
201    public CmsPrincipalSelectionList(CmsJspActionElement jsp) {
202
203        super(
204            jsp,
205            LIST_ID + getListInstanceHash(jsp.getRequest()),
206            Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_NAME_0),
207            LIST_COLUMN_DISPLAY,
208            CmsListOrderEnum.ORDER_ASCENDING,
209            null);
210    }
211
212    /**
213     * Public constructor with JSP variables.<p>
214     *
215     * @param context the JSP page context
216     * @param req the JSP request
217     * @param res the JSP response
218     */
219    public CmsPrincipalSelectionList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
220
221        this(new CmsJspActionElement(context, req, res));
222    }
223
224    /**
225     * Gets the hash which is appended to the list name to form the list id.<p>
226     *
227     * @param request the current request
228     * @return the list instance hash
229     */
230    private static String getListInstanceHash(HttpServletRequest request) {
231
232        String result;
233        if ((request != null) && (request.getSession(false) != null)) {
234            result = "_" + String.valueOf(request.getSession(false).getId().hashCode());
235
236        } else {
237            result = "";
238        }
239        return result;
240    }
241
242    /**
243     * @see org.opencms.workplace.tools.CmsToolDialog#dialogTitle()
244     */
245    @Override
246    public String dialogTitle() {
247
248        // build title
249        StringBuffer html = new StringBuffer(512);
250        html.append("<div class='screenTitle'>\n");
251        html.append("\t<table width='100%' cellspacing='0'>\n");
252        html.append("\t\t<tr>\n");
253        html.append("\t\t\t<td>\n");
254        if (getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).isVisible()) {
255            html.append(key(Messages.GUI_GROUPSELECTION_INTRO_TITLE_0));
256            getList().setName(Messages.get().container(Messages.GUI_GROUPSELECTION_LIST_NAME_0));
257            getList().getMetadata().getIndependentAction(LIST_DETAIL_OTHEROU);
258        } else {
259            html.append(key(Messages.GUI_USERSELECTION_INTRO_TITLE_1, new Object[] {""}));
260            getList().setName(Messages.get().container(Messages.GUI_USERSELECTION_LIST_NAME_0));
261        }
262        html.append("\n\t\t\t</td>");
263        html.append("\t\t</tr>\n");
264        html.append("\t</table>\n");
265        html.append("</div>\n");
266        return html.toString();
267    }
268
269    /**
270     * @see org.opencms.workplace.list.A_CmsListDialog#executeListIndepActions()
271     */
272    @Override
273    public void executeListIndepActions() {
274
275        if (LIST_IACTION_USERS.equals(getParamListAction())) {
276            getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).setVisible(false);
277            getList().getMetadata().getIndependentAction(LIST_IACTION_GROUPS).setVisible(true);
278        } else if (LIST_IACTION_GROUPS.equals(getParamListAction())) {
279            getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).setVisible(true);
280            getList().getMetadata().getIndependentAction(LIST_IACTION_GROUPS).setVisible(false);
281        }
282        super.executeListIndepActions();
283    }
284
285    /**
286     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
287     */
288    @Override
289    public void executeListMultiActions() throws CmsRuntimeException {
290
291        throwListUnsupportedActionException();
292    }
293
294    /**
295     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
296     */
297    @Override
298    public void executeListSingleActions() throws CmsRuntimeException {
299
300        throwListUnsupportedActionException();
301    }
302
303    /**
304     * Returns the right icon path for the given list item.<p>
305     *
306     * @param item the list item to get the icon path for
307     *
308     * @return the icon path for the given role
309     */
310    public String getIconPath(CmsListItem item) {
311
312        boolean showingUsers = isShowingUsers();
313        try {
314            CmsPrincipal principal;
315            if (showingUsers) {
316                principal = getCms().readUser((String)item.get(LIST_COLUMN_NAME));
317            } else {
318                principal = getCms().readGroup((String)item.get(LIST_COLUMN_NAME));
319            }
320            if (principal.getOuFqn().equals(getCms().getRequestContext().getCurrentUser().getOuFqn())) {
321                if (showingUsers) {
322                    return PATH_BUTTONS + "user.png";
323                } else {
324                    return PATH_BUTTONS + "group.png";
325                }
326            } else {
327                if (showingUsers) {
328                    return PATH_BUTTONS + "user_other_ou.png";
329                } else {
330                    return PATH_BUTTONS + "group_other_ou.png";
331                }
332            }
333        } catch (CmsException e) {
334            if (item.get(LIST_COLUMN_DISPLAY).equals(key(Messages.GUI_LABEL_OVERWRITEALL_0))) {
335                return "commons/" + CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME.toLowerCase() + ".png";
336            } else if (item.get(LIST_COLUMN_DISPLAY).equals(key(Messages.GUI_LABEL_ALLOTHERS_0))) {
337                return "commons/" + CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME.toLowerCase() + ".png";
338            } else if (showingUsers) {
339                return PATH_BUTTONS + "user.png";
340            } else {
341                return PATH_BUTTONS + "group.png";
342            }
343        }
344    }
345
346    /**
347     * Returns the flags parameter value.<p>
348     *
349     * @return the flags parameter value
350     */
351    public String getParamFlags() {
352
353        return m_paramFlags;
354    }
355
356    /**
357     * Gets the 'realonly parameter'.<p>
358     *
359     * This controls whether pseudo-principals like 'ALL OTHERS' should be shown or not.<p>
360     *
361     * @return the parameter value
362     */
363    public String getParamRealonly() {
364
365        return m_realOnly;
366    }
367
368    /**
369     * Returns the use parent frame flag.<p>
370     *
371     * @return the use parent frame flag
372     */
373    public String getParamUseparent() {
374
375        return m_paramUseparent;
376    }
377
378    /**
379     * Returns if the list of principals has principals of other organizational units.<p>
380     *
381     * @return if the list of principals has principals of other organizational units
382     */
383    public boolean hasPrincipalsInOtherOus() {
384
385        if (m_hasPrincipalsInOtherOus == null) {
386            // lazzy initialization
387            m_hasPrincipalsInOtherOus = Boolean.FALSE;
388            try {
389                Iterator<CmsPrincipal> itPrincipals = getPrincipals(true).iterator();
390                while (itPrincipals.hasNext()) {
391                    CmsPrincipal principal = itPrincipals.next();
392                    if (!principal.getOuFqn().equals(getCms().getRequestContext().getCurrentUser().getOuFqn())) {
393                        m_hasPrincipalsInOtherOus = Boolean.TRUE;
394                        break;
395                    }
396                }
397            } catch (Exception e) {
398                // ignore
399            }
400        }
401        return m_hasPrincipalsInOtherOus.booleanValue();
402    }
403
404    /**
405     * Checks if we are currently displaying users or groups.<p>
406     *
407     * @return <code>true</code> if we are currently displaying users
408     */
409    public boolean isShowingUsers() {
410
411        return getList().getMetadata().getIndependentAction(LIST_IACTION_GROUPS).isVisible();
412    }
413
414    /**
415     * Sets the flags parameter value.<p>
416     *
417     * @param flags the flags parameter value to set
418     */
419    public void setParamFlags(String flags) {
420
421        m_paramFlags = flags;
422    }
423
424    /**
425     * Sets the 'realonly' parameter.<p>
426     *
427     * This controls whether 'pseudo-principals' like 'ALL OTHERS' should be shown or not.
428     *
429     * @param realonly the parameter value
430     */
431    public void setParamRealonly(String realonly) {
432
433        m_realOnly = realonly;
434    }
435
436    /**
437     * Sets the use parent frame flag.<p>
438     *
439     * @param useParent the use parent frame flag
440     */
441    public void setParamUseparent(String useParent) {
442
443        m_paramUseparent = useParent;
444    }
445
446    /**
447     * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
448     */
449    @Override
450    protected void fillDetails(String detailId) {
451
452        // noop
453    }
454
455    /**
456     * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
457     */
458    @Override
459    protected List<CmsListItem> getListItems() throws CmsException {
460
461        List<CmsListItem> ret = new ArrayList<CmsListItem>();
462
463        boolean withOtherOus = hasPrincipalsInOtherOus()
464            && getList().getMetadata().getItemDetailDefinition(LIST_DETAIL_OTHEROU).isVisible();
465
466        // get content
467        Iterator<CmsPrincipal> itPrincipals = getPrincipals(withOtherOus).iterator();
468        while (itPrincipals.hasNext()) {
469            I_CmsPrincipal principal = itPrincipals.next();
470            CmsListItem item = getList().newItem(principal.getId().toString());
471            item.set(LIST_COLUMN_NAME, principal.getName());
472
473            I_CmsGroupNameTranslation translation = OpenCms.getWorkplaceManager().getGroupNameTranslation();
474            if (principal.isGroup()) {
475                item.set(LIST_COLUMN_DISPLAY, translation.translateGroupName(principal.getName(), false));
476            } else {
477                item.set(LIST_COLUMN_DISPLAY, principal.getSimpleName());
478            }
479            if (principal.isUser()) {
480                if (principal.getId().equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID)
481                    || principal.getId().equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID)) {
482                    item.set(LIST_COLUMN_DESCRIPTION, ((CmsUser)principal).getDescription(getLocale()));
483                } else {
484                    item.set(LIST_COLUMN_DESCRIPTION, ((CmsUser)principal).getFullName());
485                }
486            } else {
487                item.set(LIST_COLUMN_DESCRIPTION, ((CmsGroup)principal).getDescription(getLocale()));
488            }
489            item.set(LIST_COLUMN_ORGUNIT, CmsOrganizationalUnit.SEPARATOR + principal.getOuFqn());
490            ret.add(item);
491        }
492        return ret;
493    }
494
495    /**
496     * Returns the list of principals for selection.<p>
497     *
498     * @param includeOtherOus if to include other ou's in the selection
499     *
500     * @return a list of principals
501     *
502     * @throws CmsException if womething goes wrong
503     */
504    protected List<CmsPrincipal> getPrincipals(boolean includeOtherOus) throws CmsException {
505
506        String ou = getCms().getRequestContext().getCurrentUser().getOuFqn();
507        Set<CmsPrincipal> principals = new HashSet<CmsPrincipal>();
508        boolean realOnly = Boolean.valueOf(getParamRealonly()).booleanValue();
509        if (isShowingUsers()) {
510            // include special principals
511            if (!realOnly) {
512                if (OpenCms.getRoleManager().hasRole(getCms(), CmsRole.VFS_MANAGER)) {
513                    CmsUser user = new CmsUser(
514                        CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
515                        key(Messages.GUI_LABEL_OVERWRITEALL_0),
516                        "",
517                        "",
518                        "",
519                        "",
520                        0,
521                        0,
522                        0,
523                        null);
524                    user.setDescription(key(Messages.GUI_DESCRIPTION_OVERWRITEALL_0));
525                    principals.add(user);
526                }
527                CmsUser user = new CmsUser(
528                    CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
529                    key(Messages.GUI_LABEL_ALLOTHERS_0),
530                    "",
531                    "",
532                    "",
533                    "",
534                    0,
535                    0,
536                    0,
537                    null);
538                user.setDescription(key(Messages.GUI_DESCRIPTION_ALLOTHERS_0));
539                principals.add(user);
540            }
541            if (includeOtherOus) {
542                // add all manageable users
543                principals.addAll(OpenCms.getRoleManager().getManageableUsers(getCms(), "", true));
544                // add own ou users
545                principals.addAll(OpenCms.getOrgUnitManager().getUsers(getCms(), ou, true));
546            } else {
547                // add own ou users
548                principals.addAll(OpenCms.getOrgUnitManager().getUsers(getCms(), ou, false));
549            }
550        } else {
551            // include special principals
552            if (!realOnly) {
553                if (OpenCms.getRoleManager().hasRole(getCms(), CmsRole.VFS_MANAGER)) {
554                    principals.add(
555                        new CmsGroup(
556                            CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID,
557                            null,
558                            key(Messages.GUI_LABEL_OVERWRITEALL_0),
559                            key(Messages.GUI_DESCRIPTION_OVERWRITEALL_0),
560                            0));
561                }
562                principals.add(
563                    new CmsGroup(
564                        CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID,
565                        null,
566                        key(Messages.GUI_LABEL_ALLOTHERS_0),
567                        key(Messages.GUI_DESCRIPTION_ALLOTHERS_0),
568                        0));
569            }
570            if (includeOtherOus) {
571                // add all manageable users
572                principals.addAll(OpenCms.getRoleManager().getManageableGroups(getCms(), "", true));
573                // add own ou users
574                principals.addAll(OpenCms.getOrgUnitManager().getGroups(getCms(), ou, true));
575            } else {
576                // add own ou users
577                principals.addAll(OpenCms.getOrgUnitManager().getGroups(getCms(), ou, false));
578            }
579        }
580        List<CmsPrincipal> ret = new ArrayList<CmsPrincipal>(principals);
581        if (getParamFlags() != null) {
582            int flags = Integer.parseInt(getParamFlags());
583            return new ArrayList<CmsPrincipal>(CmsPrincipal.filterFlag(ret, flags));
584        }
585        return ret;
586    }
587
588    /**
589     * @see org.opencms.workplace.list.A_CmsListDialog#initializeDetail(java.lang.String)
590     */
591    @Override
592    protected void initializeDetail(String detailId) {
593
594        super.initializeDetail(detailId);
595        if (detailId.equals(LIST_DETAIL_OTHEROU)) {
596            boolean visible = hasPrincipalsInOtherOus()
597                && getList().getMetadata().getItemDetailDefinition(LIST_DETAIL_OTHEROU).isVisible();
598            getList().getMetadata().getColumnDefinition(LIST_COLUMN_ORGUNIT).setVisible(visible);
599            getList().getMetadata().getColumnDefinition(LIST_COLUMN_ORGUNIT).setPrintable(visible);
600        }
601    }
602
603    /**
604     * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
605     */
606    @Override
607    protected void setColumns(CmsListMetadata metadata) {
608
609        // create column for icon display
610        CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON);
611        iconCol.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_COLS_ICON_0));
612        iconCol.setHelpText(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_COLS_ICON_HELP_0));
613        iconCol.setWidth("20");
614        iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
615        iconCol.setSorteable(false);
616        // set icon action
617        CmsListDirectAction iconAction = new CmsListDirectAction(LIST_ACTION_ICON) {
618
619            /**
620             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
621             */
622            @Override
623            public String getIconPath() {
624
625                return ((CmsPrincipalSelectionList)getWp()).getIconPath(getItem());
626            }
627        };
628        iconAction.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_ICON_NAME_0));
629        iconAction.setHelpText(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_ICON_HELP_0));
630        iconAction.setEnabled(false);
631        iconCol.addDirectAction(iconAction);
632        // add it to the list definition
633        metadata.addColumn(iconCol);
634
635        CmsListColumnDefinition loginCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
636        loginCol.setVisible(false);
637        metadata.addColumn(loginCol);
638        loginCol.setPrintable(false);
639
640        // create column for display name
641        CmsListColumnDefinition displayNameCol = new CmsListColumnDefinition(LIST_COLUMN_DISPLAY);
642        displayNameCol.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_COLS_NAME_0));
643        displayNameCol.setWidth("40%");
644        displayNameCol.setListItemComparator(LIST_ITEM_COMPARATOR);
645        CmsListDefaultAction selectAction = new A_CmsListDefaultJsAction(LIST_ACTION_SELECT) {
646
647            /**
648             * @see org.opencms.workplace.list.A_CmsListDirectJsAction#jsCode()
649             */
650            @Override
651            public String jsCode() {
652
653                if (Boolean.parseBoolean(getParamUseparent())) {
654                    return "parent.setPrincipalFormValue("
655                        + (((CmsPrincipalSelectionList)getWp()).isShowingUsers() ? 1 : 0)
656                        + ",'"
657                        + getItem().get(LIST_COLUMN_NAME)
658                        + "');";
659                } else {
660                    return "window.opener.setPrincipalFormValue("
661                        + (((CmsPrincipalSelectionList)getWp()).isShowingUsers() ? 1 : 0)
662                        + ",'"
663                        + getItem().get(LIST_COLUMN_NAME)
664                        + "'); window.opener.focus(); window.close();";
665                }
666            }
667        };
668        selectAction.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_ACTION_SELECT_NAME_0));
669        selectAction.setHelpText(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_ACTION_SELECT_HELP_0));
670        displayNameCol.addDefaultAction(selectAction);
671        // add it to the list definition
672        metadata.addColumn(displayNameCol);
673
674        // create column for description
675        CmsListColumnDefinition descriptionCol = new CmsListColumnDefinition(LIST_COLUMN_DESCRIPTION);
676        descriptionCol.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_COLS_DESCRIPTION_0));
677        descriptionCol.setWidth("60%");
678        descriptionCol.setTextWrapping(true);
679        descriptionCol.setListItemComparator(LIST_ITEM_COMPARATOR);
680        // add it to the list definition
681        metadata.addColumn(descriptionCol);
682
683        // create column for org unit
684        CmsListColumnDefinition ouCol = new CmsListColumnDefinition(LIST_COLUMN_ORGUNIT);
685        ouCol.setName(Messages.get().container(Messages.GUI_PRINCIPALSELECTION_LIST_COLS_ORGUNIT_0));
686        ouCol.setWidth("40%");
687        ouCol.setTextWrapping(true);
688        ouCol.setListItemComparator(LIST_ITEM_COMPARATOR);
689        // add it to the list definition
690        metadata.addColumn(ouCol);
691    }
692
693    /**
694     * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
695     */
696    @Override
697    protected void setIndependentActions(CmsListMetadata metadata) {
698
699        // add other ou button
700        CmsListItemDetails otherOuDetails = new CmsListItemDetails(LIST_DETAIL_OTHEROU);
701        otherOuDetails.setVisible(false);
702        otherOuDetails.setHideAction(new CmsListIndependentAction(LIST_DETAIL_OTHEROU) {
703
704            /**
705             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getHelpText()
706             */
707            @Override
708            public CmsMessageContainer getHelpText() {
709
710                if (getWp().getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).isVisible()) {
711                    return Messages.get().container(Messages.GUI_GROUPS_DETAIL_HIDE_OTHEROU_HELP_0);
712                } else {
713                    return Messages.get().container(Messages.GUI_USERS_DETAIL_HIDE_OTHEROU_HELP_0);
714                }
715            }
716
717            /**
718             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
719             */
720            @Override
721            public String getIconPath() {
722
723                return A_CmsListDialog.ICON_DETAILS_HIDE;
724            }
725
726            /**
727             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getName()
728             */
729            @Override
730            public CmsMessageContainer getName() {
731
732                if (getWp().getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).isVisible()) {
733                    return Messages.get().container(Messages.GUI_GROUPS_DETAIL_HIDE_OTHEROU_NAME_0);
734                } else {
735                    return Messages.get().container(Messages.GUI_USERS_DETAIL_HIDE_OTHEROU_NAME_0);
736                }
737            }
738
739            /**
740             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
741             */
742            @Override
743            public boolean isVisible() {
744
745                return ((CmsPrincipalSelectionList)getWp()).hasPrincipalsInOtherOus();
746            }
747        });
748        otherOuDetails.setShowAction(new CmsListIndependentAction(LIST_DETAIL_OTHEROU) {
749
750            /**
751             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getHelpText()
752             */
753            @Override
754            public CmsMessageContainer getHelpText() {
755
756                if (getWp().getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).isVisible()) {
757                    return Messages.get().container(Messages.GUI_GROUPS_DETAIL_SHOW_OTHEROU_HELP_0);
758                } else {
759                    return Messages.get().container(Messages.GUI_USERS_DETAIL_SHOW_OTHEROU_HELP_0);
760                }
761            }
762
763            /**
764             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath()
765             */
766            @Override
767            public String getIconPath() {
768
769                return A_CmsListDialog.ICON_DETAILS_SHOW;
770            }
771
772            /**
773             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getName()
774             */
775            @Override
776            public CmsMessageContainer getName() {
777
778                if (getWp().getList().getMetadata().getIndependentAction(LIST_IACTION_USERS).isVisible()) {
779                    return Messages.get().container(Messages.GUI_GROUPS_DETAIL_SHOW_OTHEROU_NAME_0);
780                } else {
781                    return Messages.get().container(Messages.GUI_USERS_DETAIL_SHOW_OTHEROU_NAME_0);
782                }
783            }
784
785            /**
786             * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible()
787             */
788            @Override
789            public boolean isVisible() {
790
791                return ((CmsPrincipalSelectionList)getWp()).hasPrincipalsInOtherOus();
792            }
793        });
794        otherOuDetails.setName(Messages.get().container(Messages.GUI_PRINCIPALS_DETAIL_OTHEROU_NAME_0));
795        otherOuDetails.setFormatter(
796            new CmsListItemDetailsFormatter(Messages.get().container(Messages.GUI_PRINCIPALS_DETAIL_OTHEROU_NAME_0)));
797        metadata.addItemDetails(otherOuDetails);
798
799        CmsListIndependentAction usersAction = new CmsListIndependentAction(LIST_IACTION_USERS);
800        usersAction.setName(Messages.get().container(Messages.GUI_PRINCIPALS_IA_USERS_NAME_0));
801        usersAction.setHelpText(Messages.get().container(Messages.GUI_PRINCIPALS_IA_USERS_HELP_0));
802        usersAction.setIconPath(PATH_BUTTONS + "user.png");
803        usersAction.setVisible(true);
804        metadata.addIndependentAction(usersAction);
805
806        CmsListIndependentAction groupsAction = new CmsListIndependentAction(LIST_IACTION_GROUPS);
807        groupsAction.setName(Messages.get().container(Messages.GUI_PRINCIPALS_IA_GROUPS_NAME_0));
808        groupsAction.setHelpText(Messages.get().container(Messages.GUI_PRINCIPALS_IA_GROUPS_HELP_0));
809        groupsAction.setIconPath(PATH_BUTTONS + "group.png");
810        groupsAction.setVisible(false);
811        metadata.addIndependentAction(groupsAction);
812
813        CmsListSearchAction searchAction = new CmsListSearchAction(metadata.getColumnDefinition(LIST_COLUMN_DISPLAY));
814        searchAction.addColumn(metadata.getColumnDefinition(LIST_COLUMN_DESCRIPTION));
815        searchAction.setCaseInSensitive(true);
816        metadata.setSearchAction(searchAction);
817    }
818
819    /**
820     * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
821     */
822    @Override
823    protected void setMultiActions(CmsListMetadata metadata) {
824
825        // no-op
826    }
827
828    /**
829     * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
830     */
831    @Override
832    protected void validateParamaters() throws Exception {
833
834        try {
835            Integer.valueOf(getParamFlags());
836        } catch (Throwable e) {
837            setParamFlags(null);
838        }
839    }
840}