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: DirectorySelectOneWidgetTypeHandler.java 30416 2008-02-21 19:10:37Z atchertchian $ 018 */ 019 020package org.nuxeo.ecm.platform.forms.layout.facelets.plugins; 021 022import javax.faces.component.html.HtmlSelectOneMenu; 023import javax.faces.view.facelets.ComponentHandler; 024import javax.faces.view.facelets.FaceletContext; 025import javax.faces.view.facelets.FaceletHandler; 026import javax.faces.view.facelets.TagAttribute; 027import javax.faces.view.facelets.TagAttributes; 028import javax.faces.view.facelets.TagConfig; 029 030import org.nuxeo.ecm.platform.forms.layout.api.BuiltinWidgetModes; 031import org.nuxeo.ecm.platform.forms.layout.api.Widget; 032import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException; 033import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; 034import org.nuxeo.ecm.platform.ui.web.component.seam.UIHtmlText; 035import org.nuxeo.ecm.platform.ui.web.directory.DirectoryEntryOutputComponent; 036 037import com.sun.faces.facelets.tag.TagAttributesImpl; 038 039/** 040 * Select one directory widget 041 * 042 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 043 */ 044public class DirectorySelectOneWidgetTypeHandler extends AbstractDirectorySelectWidgetTypeHandler { 045 046 private static final long serialVersionUID = 1L; 047 048 protected String getEditComponentType() { 049 return HtmlSelectOneMenu.COMPONENT_TYPE; 050 } 051 052 @Override 053 public FaceletHandler getFaceletHandler(FaceletContext ctx, TagConfig tagConfig, Widget widget, 054 FaceletHandler[] subHandlers) throws WidgetException { 055 String mode = widget.getMode(); 056 if (BuiltinWidgetModes.EDIT.equals(mode)) { 057 return super.getFaceletHandler(ctx, tagConfig, widget, subHandlers, getEditComponentType()); 058 } 059 060 FaceletHandlerHelper helper = new FaceletHandlerHelper(ctx, tagConfig); 061 FaceletHandler leaf = getNextHandler(ctx, tagConfig, widget, subHandlers, helper); 062 String widgetId = widget.getId(); 063 String widgetTagConfigId = widget.getTagConfigId(); 064 TagAttributes attributes; 065 if (BuiltinWidgetModes.isLikePlainMode(mode)) { 066 // use attributes without id 067 attributes = helper.getTagAttributes(widget); 068 } else { 069 attributes = helper.getTagAttributes(widgetId, widget); 070 } 071 ComponentHandler output = helper.getHtmlComponentHandler(widgetTagConfigId, attributes, leaf, 072 DirectoryEntryOutputComponent.COMPONENT_TYPE, null); 073 if (BuiltinWidgetModes.PDF.equals(mode)) { 074 // add a surrounding p:html tag handler 075 return helper.getHtmlComponentHandler(widgetTagConfigId, new TagAttributesImpl(new TagAttribute[0]), 076 output, UIHtmlText.class.getName(), null); 077 } else { 078 return output; 079 } 080 } 081}