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 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
016 *
017 * $Id: UIDirectorySelectItem.java 29556 2008-01-23 00:59:39Z jcarsique $
018 */
019
020package org.nuxeo.ecm.platform.ui.web.directory;
021
022import javax.faces.model.SelectItem;
023
024import org.nuxeo.ecm.platform.ui.web.component.UISelectItem;
025
026/**
027 * Component that deals with a select item from a directory.
028 *
029 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
030 */
031public class UIDirectorySelectItem extends UISelectItem {
032
033    public static final String COMPONENT_TYPE = UIDirectorySelectItem.class.getName();
034
035    enum PropertyKeys {
036        directoryName
037    }
038
039    // setters & getters
040
041    public String getDirectoryName() {
042        return (String) getStateHelper().eval(PropertyKeys.directoryName);
043    }
044
045    public void setDirectoryName(String directoryName) {
046        getStateHelper().put(PropertyKeys.directoryName, directoryName);
047    }
048
049    @Override
050    public Object getValue() {
051        Object value = super.getValue();
052        return new DirectorySelectItemFactory() {
053
054            @Override
055            protected String getVar() {
056                return UIDirectorySelectItem.this.getVar();
057            }
058
059            @Override
060            protected SelectItem createSelectItem() {
061                return UIDirectorySelectItem.this.createSelectItem();
062            }
063
064            @Override
065            protected String getDirectoryName() {
066                return UIDirectorySelectItem.this.getDirectoryName();
067            }
068        }.createSelectItem(value);
069    }
070
071}