001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 018 * 019 * $Id: DirectorySelectOneWidgetTypeHandler.java 30416 2008-02-21 19:10:37Z atchertchian $ 020 */ 021 022package org.nuxeo.ecm.platform.forms.layout.facelets.plugins; 023 024import java.io.IOException; 025 026import javax.faces.component.UIComponent; 027import javax.faces.component.html.HtmlSelectOneMenu; 028import javax.faces.view.facelets.ComponentHandler; 029import javax.faces.view.facelets.FaceletContext; 030import javax.faces.view.facelets.FaceletHandler; 031import javax.faces.view.facelets.TagAttribute; 032import javax.faces.view.facelets.TagAttributes; 033import javax.faces.view.facelets.TagConfig; 034 035import org.nuxeo.ecm.platform.forms.layout.api.BuiltinWidgetModes; 036import org.nuxeo.ecm.platform.forms.layout.api.Widget; 037import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException; 038import org.nuxeo.ecm.platform.forms.layout.facelets.FaceletHandlerHelper; 039import org.nuxeo.ecm.platform.ui.web.component.seam.UIHtmlText; 040import org.nuxeo.ecm.platform.ui.web.directory.DirectoryEntryOutputComponent; 041 042import com.sun.faces.facelets.tag.TagAttributesImpl; 043 044/** 045 * Select one directory widget 046 * 047 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 048 */ 049public class DirectorySelectOneWidgetTypeHandler extends AbstractDirectorySelectWidgetTypeHandler { 050 051 public DirectorySelectOneWidgetTypeHandler(TagConfig config) { 052 super(config); 053 } 054 055 protected String getEditComponentType() { 056 return HtmlSelectOneMenu.COMPONENT_TYPE; 057 } 058 059 @Override 060 public void apply(FaceletContext ctx, UIComponent parent, Widget widget) throws WidgetException, IOException { 061 String mode = widget.getMode(); 062 if (BuiltinWidgetModes.EDIT.equals(mode)) { 063 super.apply(ctx, parent, widget, getEditComponentType()); 064 return; 065 } 066 067 FaceletHandlerHelper helper = new FaceletHandlerHelper(tagConfig); 068 FaceletHandler leaf = getNextHandler(ctx, tagConfig, widget, null, helper); 069 String widgetId = widget.getId(); 070 String widgetTagConfigId = widget.getTagConfigId(); 071 TagAttributes attributes; 072 if (BuiltinWidgetModes.isLikePlainMode(mode)) { 073 // use attributes without id 074 attributes = helper.getTagAttributes(widget); 075 } else { 076 attributes = helper.getTagAttributes(widgetId, widget); 077 } 078 ComponentHandler output = helper.getHtmlComponentHandler(widgetTagConfigId, attributes, leaf, 079 DirectoryEntryOutputComponent.COMPONENT_TYPE, null); 080 if (BuiltinWidgetModes.PDF.equals(mode)) { 081 // add a surrounding p:html tag handler 082 FaceletHandler h = helper.getHtmlComponentHandler(widgetTagConfigId, new TagAttributesImpl(new TagAttribute[0]), 083 output, UIHtmlText.class.getName(), null); 084 h.apply(ctx, parent); 085 } else { 086 output.apply(ctx, parent); 087 } 088 } 089}