001/* 002 * (C) Copyright 2006-2016 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:[email protected]">Anahide Tchertchian</a> 018 */ 019package org.nuxeo.ecm.platform.forms.layout.service; 020 021import java.io.Serializable; 022import java.util.List; 023import java.util.Map; 024 025import javax.faces.view.facelets.FaceletContext; 026import javax.faces.view.facelets.TagConfig; 027 028import org.nuxeo.ecm.platform.forms.layout.api.FieldDefinition; 029import org.nuxeo.ecm.platform.forms.layout.api.Layout; 030import org.nuxeo.ecm.platform.forms.layout.api.LayoutDefinition; 031import org.nuxeo.ecm.platform.forms.layout.api.Widget; 032import org.nuxeo.ecm.platform.forms.layout.api.WidgetDefinition; 033import org.nuxeo.ecm.platform.forms.layout.api.converters.LayoutConversionContext; 034import org.nuxeo.ecm.platform.forms.layout.api.exceptions.WidgetException; 035import org.nuxeo.ecm.platform.forms.layout.api.service.LayoutManager; 036import org.nuxeo.ecm.platform.forms.layout.facelets.WidgetTypeHandler; 037 038/** 039 * Web Layout manager interface. 040 * <p> 041 * It manages registries of layout definitions and widget types and handles the creation of layouts and widgets 042 * instances. 043 * 044 * @author <a href="mailto:[email protected]">Anahide Tchertchian</a> 045 */ 046public interface WebLayoutManager extends LayoutManager { 047 048 String JSF_CATEGORY = "jsf"; 049 050 /** 051 * Returns the widget type handler for the registered widget type with this type name and type category. 052 * <p> 053 * If no widget type is found with this name, returns null. 054 * 055 * @since 8.1 056 */ 057 WidgetTypeHandler getWidgetTypeHandler(TagConfig config, String typeCategory, String typeName) 058 throws WidgetException; 059 060 /** 061 * Returns the widget type handler for the registered widget. 062 * <p> 063 * If widget is null or its widget type is unknown, returns null. 064 * 065 * @since 8.1 066 */ 067 WidgetTypeHandler getWidgetTypeHandler(TagConfig config, Widget widget) throws WidgetException; 068 069 /** 070 * Returns the computed layout for this name and mode in given context, or null if no layout with this name is 071 * found. 072 * <p> 073 * When a widget is configured not to be rendered in this mode, the layout will hold a null value instead. As well, 074 * when a row does not hold any non-null widget in this mode, the layout will not hold it. 075 * 076 * @see #getLayout(FaceletContext, String, String, String, List, boolean) 077 * @param ctx the facelet context this layout will be computed in. If context is null, no expressions can be 078 * resolved during computing. 079 * @param layoutName the layout definition name. 080 * @param mode the mode. 081 * @param valueName the value name to use when computing tag attributes. 082 * @return a layout computed in this context. 083 */ 084 Layout getLayout(FaceletContext ctx, String layoutName, String mode, String valueName); 085 086 /** 087 * Returns the computed layout for this name, mode and list of selected rows in given context, or null if no layout 088 * with this name is found. 089 * 090 * @see LayoutManager#getLayoutDefinition(String) 091 * @see #getLayout(FaceletContext, LayoutDefinition, String, String, List, boolean) 092 * @param layoutName the layout definition name. 093 * @return a layout computed in this context. 094 * @since 5.4 095 */ 096 Layout getLayout(FaceletContext ctx, String layoutName, String mode, String valueName, List<String> selectedRows, 097 boolean selectAllRowsByDefault); 098 099 /** 100 * Returns the computed layout for this name, category, mode and list of selected rows in given context, or null if 101 * no layout with this name is found. 102 * 103 * @see LayoutManager#getLayoutDefinition(String) 104 * @see #getLayout(FaceletContext, LayoutDefinition, String, String, List, boolean) 105 * @param layoutName the layout definition name. 106 * @return a layout computed in this context. 107 * @since 5.5 108 */ 109 Layout getLayout(FaceletContext ctx, String layoutName, String layoutCategory, String mode, String valueName, 110 List<String> selectedRows, boolean selectAllRowsByDefault); 111 112 /** 113 * Returns the computed layout for this definition, mode and list of selected rows in given context, or null if the 114 * layout definition is null. 115 * <p> 116 * When a widget is configured not to be rendered in this mode, the layout will hold a null value instead. As well, 117 * when a row does not hold any non-null widget in this mode, the layout will not hold it. 118 * <p> 119 * If parameter selectedRows is not null, layout rows will be filtered according to this value. If selectedRows is 120 * null and parameter selectAllRowsByDefault is true, all rows will be taken into account, even rows marked as not 121 * selected by default. 122 * 123 * @param ctx the facelet context this layout will be computed in. If context is null, no expressions can be 124 * resolved during computing. 125 * @param layoutDef the layout definition instance. 126 * @param mode the mode. 127 * @param valueName the value name to use when computing tag attributes (useful for fields mapping) 128 * @param selectedRows the list of selected rows names 129 * @param selectAllRowsByDefault boolean indicating if all rows should be considered selected by default in case 130 * parameter selectedRows resolves to null. 131 * @return a layout computed in this context, null if definition is null. 132 * @since 5.4 133 */ 134 Layout getLayout(FaceletContext ctx, LayoutDefinition layoutDef, String mode, String valueName, 135 List<String> selectedRows, boolean selectAllRowsByDefault); 136 137 /** 138 * Returns a layout with conversion. 139 * 140 * @since 7.3 141 */ 142 Layout getLayout(FaceletContext ctx, LayoutConversionContext lctx, String conversionCat, LayoutDefinition layoutDef, 143 String mode, String valueName, List<String> selectedRows, boolean selectAllRowsByDefault); 144 145 /** 146 * Returns a widget instance given a name and a category, as it would be computed when defined within a layout. 147 * 148 * @since 5.6 149 * @param ctx the facelet context this widget will be computed in. If context is null, no expressions can be 150 * resolved during computing. 151 * @param widgetName the widget name 152 * @param widgetCategory the widget category 153 * @param layoutMode the pseudo layout mode 154 * @param valueName the value name to use when computing tag attributes (useful for fields mapping) 155 * @param layoutName the pseudo layout name (if any) 156 * @return the widget instance, or null if widget definition could not be resolved. 157 */ 158 Widget getWidget(FaceletContext ctx, String widgetName, String widgetCategory, String layoutMode, String valueName, 159 String layoutName); 160 161 /** 162 * Returns a widget instance given a name and a category, as it would be computed when defined within a layout. 163 * 164 * @since 5.6 165 * @param ctx the facelet context this widget will be computed in. If context is null, no expressions can be 166 * resolved during computing. 167 * @param widgetDef the widget definition 168 * @param layoutMode the pseudo layout mode 169 * @param valueName the value name to use when computing tag attributes (useful for fields mapping) 170 * @param layoutName the pseudo layout name (if any) 171 * @return the widget instance, or null if the widget definition is null. 172 */ 173 Widget getWidget(FaceletContext ctx, WidgetDefinition widgetDef, String layoutMode, String valueName, 174 String layoutName); 175 176 /** 177 * Returns a widget with conversion. 178 * 179 * @since 7.3 180 */ 181 Widget getWidget(FaceletContext ctx, LayoutConversionContext lctx, String conversionCat, WidgetDefinition widgetDef, 182 String layoutMode, String valueName, String layoutName); 183 184 /** 185 * Returns a widget computed from given information. 186 * 187 * @param ctx the facelet context this layout will be computed in. If context is null, no expressions can be 188 * resolved during computing. 189 * @param type the widget type name. 190 * @param mode the mode. 191 * @param valueName the value name to use when computing tag attributes. 192 * @param fieldDefinitions the field definitions 193 * @param label the widget label 194 * @param helpLabel the widget help label 195 * @param translated if true, the labels will be translated 196 * @param properties optional properties to use when computing the widget. 197 * @param subWidgets optional sub widgets for this widget. 198 * @return a widget computed in this context. 199 * @since 5.4 200 */ 201 Widget createWidget(FaceletContext ctx, String type, String mode, String valueName, 202 List<FieldDefinition> fieldDefinitions, String label, String helpLabel, Boolean translated, 203 Map<String, Serializable> properties, Widget[] subWidgets); 204 205 /** 206 * Returns a widget computed from given information. 207 * 208 * @param ctx the facelet context this layout will be computed in. If context is null, no expressions can be 209 * resolved during computing. 210 * @param widgetDef the widget definition. 211 * @param mode the mode. 212 * @param valueName the value name to use when computing tag attributes. 213 * @param subWidgets optional sub widgets for this widget. 214 * @return a widget computed in this context. 215 * @since 5.7.3 216 */ 217 Widget createWidget(FaceletContext ctx, WidgetDefinition widgetDef, String mode, String valueName, 218 Widget[] subWidgets); 219 220 /** 221 * Returns true if property with given name and value should be referenced as a value expression. 222 * <p> 223 * Referencing properties as value expressions makes it possible to resolve this value again when reloading 224 * components in ajax for instance, as literal values kept by JSF components are not evaluated again. 225 * <p> 226 * But some components wait for a literal value and do not evaluate value expressions, so their properties should 227 * not be referenced as value expressions. An extension point on the service makes it possible to declare these 228 * properties: by default other properties will be using references. 229 * <p> 230 * This method returns false if it finds a matching disabled property ref for given criteria. If any of the given 231 * parameters are null, this criterion is ignored, and this looks up any matching (and enabled) contribution. 232 * 233 * @since 5.7.3 234 * @param name the property name 235 * @param value the property value 236 * @param widgetType the widget type if any 237 * @param widgetTypeCategory the widget type category if any 238 * @param mode the widget mode if any 239 * @param template the widget template if any 240 */ 241 boolean referencePropertyAsExpression(String name, Serializable value, String widgetType, String widgetTypeCategory, 242 String mode, String template); 243 244}