001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.ui.web.directory;
021
022import javax.faces.model.SelectItem;
023
024import org.apache.commons.lang.StringUtils;
025
026/**
027 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
028 */
029public class DirectorySelectItem extends SelectItem {
030
031    private static final long serialVersionUID = 1L;
032
033    private String localizedLabel;
034
035    private String displayedLabel;
036
037    private long ordering;
038
039    public DirectorySelectItem(Object value, String label) {
040        this(value, label, 0);
041    }
042
043    public DirectorySelectItem(Object value, String label, long ordering) {
044        super(value, label);
045        if (value == null) {
046            throw new IllegalArgumentException("value is null");
047        }
048        if (label == null) {
049            setLabel("");
050        }
051
052        try {
053            this.ordering = ordering;
054        } catch (NumberFormatException nfe) {
055            this.ordering = 0;
056        }
057    }
058
059    public DirectorySelectItem(Object value, String label, long ordering, boolean disabled, boolean escape) {
060        this(value, label, ordering);
061        setDisabled(disabled);
062        setEscape(escape);
063    }
064
065    /**
066     * Gets the label as it should be displayed.
067     *
068     * @deprecated as of 6.0, use {@link #getLabel()} instead.
069     */
070    @Deprecated
071    public String getDisplayedLabel() {
072        return displayedLabel;
073    }
074
075    /**
076     * @deprecated as of 6.0, use {@link #setLabel(String)} instead.
077     */
078    @Deprecated
079    public void setDisplayedLabel(String displayedLabel) {
080        this.displayedLabel = displayedLabel;
081    }
082
083    /**
084     * Gets the label as it should be displayed.
085     *
086     * @deprecated as of 6.0, use {@link #getLabel()} instead.
087     */
088    @Deprecated
089    public String getLocalizedLabel() {
090        return localizedLabel;
091    }
092
093    /**
094     * @deprecated as of 6.0, use {@link #setLabel(String)} instead.
095     */
096    @Deprecated
097    public void setLocalizedLabel(String localizedLabel) {
098        this.localizedLabel = localizedLabel;
099    }
100
101    public long getOrdering() {
102        return ordering;
103    }
104
105    /**
106     * @deprecated since 6.0, seems useless
107     */
108    @Deprecated
109    public String getSortLabel() {
110        return StringUtils.isBlank(localizedLabel) ? displayedLabel : localizedLabel;
111    }
112
113}