001/*
002 * (C) Copyright 2014 Nuxeo SA (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-2.1.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 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.platform.contentview.jsf.facelets.plugins;
018
019import java.io.Serializable;
020import java.util.List;
021import java.util.Map;
022
023import javax.faces.view.facelets.FaceletContext;
024
025import org.nuxeo.ecm.platform.contentview.jsf.facelets.plugins.SelectAggregateWidgetTypeHandler.AggregatePropertyMappings;
026import org.nuxeo.ecm.platform.forms.layout.api.Widget;
027import org.nuxeo.ecm.platform.forms.layout.api.WidgetSelectOption;
028import org.nuxeo.ecm.platform.forms.layout.facelets.plugins.AbstractDirectorySelectWidgetTypeHandler;
029
030/**
031 * @since 6.0
032 */
033public abstract class SelectDirectoryAggregateWidgetTypeHandler extends AbstractDirectorySelectWidgetTypeHandler {
034
035    private static final long serialVersionUID = 1L;
036
037    @Override
038    protected List<String> getExcludedProperties() {
039        List<String> res = super.getExcludedProperties();
040        for (AggregatePropertyMappings mapping : AggregatePropertyMappings.values()) {
041            res.add(mapping.name());
042        }
043        return res;
044    }
045
046    @Override
047    protected Map<String, Serializable> getOptionProperties(FaceletContext ctx, Widget widget,
048            WidgetSelectOption selectOption) {
049        Map<String, Serializable> props = super.getOptionProperties(ctx, widget, selectOption);
050        props.put(SelectPropertyMappings.itemLabelSuffix.name(),
051                widget.getProperty(AggregatePropertyMappings.itemCount.name()));
052        return props;
053    }
054
055}