Author: adrianc
Date: Sun Jan 25 17:18:24 2015 New Revision: 1654670 URL: http://svn.apache.org/r1654670 Log: First pass at extracting grid widget from the form widget. This commit has a lot of duplicate code - future commits will reduce and reuse the duplicate code. Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/GridFactory.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelGrid.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelSingleForm.java Modified: ofbiz/trunk/applications/accounting/widget/FixedAssetForms.xml ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml ofbiz/trunk/framework/widget/dtd/widget-form.xsd ofbiz/trunk/framework/widget/dtd/widget-screen.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelScreenWidget.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelWidgetVisitor.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/XmlWidgetVisitor.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/renderer/FormRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/renderer/FormStringRenderer.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/renderer/macro/MacroFormRenderer.java Modified: ofbiz/trunk/applications/accounting/widget/FixedAssetForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/FixedAssetForms.xml?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/FixedAssetForms.xml (original) +++ ofbiz/trunk/applications/accounting/widget/FixedAssetForms.xml Sun Jan 25 17:18:24 2015 @@ -21,7 +21,7 @@ under the License. <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-form.xsd"> <!-- list all assets in a tabular format --> - <form name="ListFixedAssets" type="list" list-name="listIt" paginate-target="ListFixedAssets" + <grid name="ListFixedAssets" type="list" list-name="listIt" paginate-target="ListFixedAssets" odd-row-style="alternate-row" header-row-style="header-row-2" default-table-style="basic-table hover-bar"> <actions> <service service-name="performFind" result-map="result" result-map-list="listIt"> @@ -60,7 +60,7 @@ under the License. <field name="depreciation" sort-field="true"><display type="currency" currency="${purchaseCostUomId}"/></field> <field name="plannedPastDepreciationTotal"><display description="${assetDepreciationResultMap.plannedPastDepreciationTotal}"/></field> <on-event-update-area event-type="paginate" area-id="search-results" area-target="FixedAssetSearchResults"/> - </form> + </grid> <form name="FindFixedAssetOptions" extends="lookupFixedAsset" extends-resource="component://accounting/widget/FieldLookupForms.xml" target="ListFixedAssets"> Modified: ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml (original) +++ ofbiz/trunk/applications/accounting/widget/FixedAssetScreens.xml Sun Jan 25 17:18:24 2015 @@ -68,7 +68,7 @@ under the License. <property-map resource="CommonUiLabels" map-name="uiLabelMap" global="true"/> </actions> <widgets> - <include-form name="ListFixedAssets" location="component://accounting/widget/FixedAssetForms.xml"/> + <include-grid name="ListFixedAssets" location="component://accounting/widget/FixedAssetForms.xml"/> </widgets> </section> </screen> Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Sun Jan 25 17:18:24 2015 @@ -23,12 +23,273 @@ under the License. <!-- ================== FORMS ==================== --> <xs:element name="forms"> <xs:complexType> + <xs:choice maxOccurs="unbounded"> + <xs:element ref="form"/> + <xs:element ref="grid"/> + </xs:choice> + </xs:complexType> + </xs:element> + <xs:element name="form"> + <xs:complexType> <xs:sequence> - <xs:element maxOccurs="unbounded" ref="form"/> + <xs:element minOccurs="0" ref="actions" /> + <xs:element minOccurs="0" ref="row-actions" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="alt-row-style" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="alt-target" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="auto-fields-service" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="auto-fields-entity" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="field" /> + <xs:element minOccurs="0" maxOccurs="unbounded" ref="on-event-update-area" /> + <xs:element minOccurs="0" ref="sort-order" /> </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required" /> + <xs:attribute name="type"> + <xs:annotation> + <xs:documentation>The form type is always required unless you are extending another form.</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="single"> + <xs:annotation> + <xs:documentation>a single form is a simple single form with values from a single set of values</xs:documentation> + </xs:annotation> + </xs:enumeration> + <xs:enumeration value="list"> + <xs:annotation> + <xs:documentation>a list form is a list of individual forms in a table (could be called a tabular form), it has a list of sets of values and creates one form for each list element</xs:documentation> + </xs:annotation> + </xs:enumeration> + <xs:enumeration value="multi"> + <xs:annotation> + <xs:documentation>a multi form is like a list/tabular form, but it creates a single form to submit all list item forms at once; the field names in the resulting form have an appendage attached to make them unique according to the pattern used for the multi-service + event handler that will call one service for each list element</xs:documentation> + </xs:annotation> + </xs:enumeration> + <xs:enumeration value="upload"> + </xs:enumeration> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="target" type="xs:string" /> + <xs:attribute name="target-window" type="xs:string" /> + <xs:attribute name="target-type" default="intra-app"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="intra-app" /> + <xs:enumeration value="inter-app" /> + <xs:enumeration value="content" /> + <xs:enumeration value="plain" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="id" type="xs:string" /> + <xs:attribute name="style" type="xs:string" /> + <xs:attribute name="focus-field-name" type="xs:string" /> + <xs:attribute name="title" type="xs:string" /> + <xs:attribute name="tooltip" type="xs:string" /> + <xs:attribute name="list-name" type="xs:string"> + <xs:annotation> + <xs:documentation>for list type and other multiple data/form types this is the name of the list in the context to iterate over</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="list-entry-name" type="xs:string"> + <xs:annotation> + <xs:documentation>if specified each list entry will be put in the context with this name; otherwise the list entry must be a Map and the entries in the Map will be put into the context by name</xs:documentation> + </xs:annotation> + </xs:attribute> + <!-- this is now deprecated, never made sense to separate anyway; use list-name instead <xs:attribute type="xs:string" name="list-iterator-name"/> --> + <xs:attribute type="xs:string" name="default-map-name" /> + <xs:attribute type="xs:string" name="default-entity-name" /> + <xs:attribute type="xs:string" name="default-service-name" /> + <xs:attribute type="xs:string" name="form-title-area-style"> + <xs:annotation> + <xs:documentation>The form-title-area-style specifies the style to use in the header or title area for the form in a multi-form widget with all form fields rendered in one area.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="form-widget-area-style"> + <xs:annotation> + <xs:documentation>The form-widget-area-style specifies the style to use in the main or widget area for the form in a multi-form widget with all form fields rendered in one area.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="default-title-area-style" /> + <xs:attribute type="xs:string" name="default-widget-area-style" /> + <xs:attribute type="xs:string" name="default-title-style" /> + <xs:attribute type="xs:string" name="default-widget-style" /> + <xs:attribute type="xs:string" name="default-tooltip-style" /> + <xs:attribute type="xs:string" name="default-required-field-style" /> + <xs:attribute type="xs:string" name="sort-field-parameter-name"> + <xs:annotation> + <xs:documentation> + The name of the request parameter that is used for specifying the sorted column. This is required when you + have more than one list on a screen - each list must use its own sort field parameter. Defaults to "sortField". + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="default-sort-field-style"> + <xs:annotation> + <xs:documentation>CSS style to used for form sort fields. Defaults to "sort-order".</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="default-sort-field-asc-style"> + <xs:annotation> + <xs:documentation>CSS style to used for form sort fields. Defaults to "sort-order-asc".</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="default-sort-field-desc-style"> + <xs:annotation> + <xs:documentation>CSS style to used for form sort fields. Defaults to "sort-order-desc".</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate" default="${paginate}"> + <xs:annotation> + <xs:documentation>Indicate if this form is paginated or not, true by default.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-target"> + <xs:annotation> + <xs:documentation>Target location for the [Previous] and [Next] buttons in a form with pagination. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-target-anchor"> + <xs:annotation> + <xs:documentation>Target anchor for the [Previous] and [Next] buttons in a form with pagination.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-size-field"> + <xs:annotation> + <xs:documentation>The name of the parameter that specifies the number of rows to display for each page in a list form with multiple pages. The default is VIEW_SIZE. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-index-field"> + <xs:annotation> + <xs:documentation>The name of the parameter that specifies what the current page is in a list form with multiple pages. The default is VIEW_INDEX Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="override-list-size"> + <xs:annotation> + <xs:documentation>The total number of rows in the original list (used for pagination). If not specified, the size of the list will be used. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-first-label"> + <xs:annotation> + <xs:documentation>Text to display for the [First] button in a form with pagination. Defaults to the CommonFirst label defined in CommonUiLabels.xml. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-previous-label"> + <xs:annotation> + <xs:documentation>Text to display for the [Previous] button in a form with pagination. Defaults to the CommonPrevious label defined in CommonUiLabels.xml. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-next-label"> + <xs:annotation> + <xs:documentation>Text to display for the [Next] button in a form with pagination. Defaults to the CommonNext label defined in CommonUiLabels.xml. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-last-label"> + <xs:annotation> + <xs:documentation>Text to display for the [Last] button in a form with pagination. Defaults to the CommonLast label defined in CommonUiLabels.xml. Accepts ${} notation.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="paginate-style"> + <xs:annotation> + <xs:documentation>CSS style to use for the whole pager in a form with pagination. Defaults to "nav-pager".</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="item-index-separator" default="_o_" /> + <xs:attribute type="xs:string" name="extends" /> + <xs:attribute type="xs:string" name="extends-resource" /> + <xs:attribute name="separate-columns" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="group-columns" default="true"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute type="xs:integer" name="view-size"> + <xs:annotation> + <xs:documentation>The number of items to display per page</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="row-count" /> + <xs:attribute name="use-row-submit" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="skip-start" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="skip-end" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="hide-header" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute type="xs:string" name="odd-row-style"> + <xs:annotation> + <xs:documentation>The odd-row-style specifies the style to use in the table content odd rows.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="even-row-style"> + <xs:annotation> + <xs:documentation>The even-row-style specifies the style to use in the table content even rows.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="header-row-style"> + <xs:annotation> + <xs:documentation>The header-row-style specifies the style to use in the header of table.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="default-table-style"> + <xs:annotation> + <xs:documentation>The default-table-style specifies the style to use in the table.</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="client-autocomplete-fields" default="true"> + <xs:annotation> + <xs:documentation>Tells the browser whether or not to try and autocomplete with values previously entered. Default to true.</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <!-- + not sure this is such a good idea <xs:attribute type="xs:string" name="hidden-values-map-name"> <xs:annotation> <xs:documentation>A map that contains hidden field name/value pairs. The reason for this is to eliminate the need to code custom forms so that auxiliary, passthru data can + be sent to the server. By doing it this way, more standard forms can be used. </xs:documentation> </xs:annotation> </xs:attribute> + --> </xs:complexType> </xs:element> - <xs:element name="form"> + <xs:element name="grid"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" ref="actions" /> Modified: ofbiz/trunk/framework/widget/dtd/widget-screen.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-screen.xsd?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-screen.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-screen.xsd Sun Jan 25 17:18:24 2015 @@ -450,6 +450,20 @@ under the License. </xs:attribute> </xs:complexType> </xs:element> + <xs:element name="include-grid" substitutionGroup="AllWidgets"> + <xs:complexType> + <xs:attribute type="xs:string" name="name" use="required" /> + <xs:attribute type="xs:string" name="location" use="required" /> + <xs:attribute name="share-scope" default="false"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + </xs:element> <xs:element name="include-menu" substitutionGroup="AllWidgets"> <xs:complexType> <xs:attribute type="xs:string" name="name" use="required" /> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/artifact/ArtifactInfoGatherer.java Sun Jan 25 17:18:24 2015 @@ -84,6 +84,7 @@ import org.ofbiz.widget.model.ModelScree import org.ofbiz.widget.model.ModelScreenWidget.DecoratorSection; import org.ofbiz.widget.model.ModelScreenWidget.DecoratorSectionInclude; import org.ofbiz.widget.model.ModelScreenWidget.Form; +import org.ofbiz.widget.model.ModelScreenWidget.Grid; import org.ofbiz.widget.model.ModelScreenWidget.HorizontalSeparator; import org.ofbiz.widget.model.ModelScreenWidget.IncludeScreen; import org.ofbiz.widget.model.ModelScreenWidget.Label; @@ -184,6 +185,12 @@ public final class ArtifactInfoGatherer } @Override + public void visit(Grid grid) throws Exception { + String gridLocation = grid.getLocation().concat("#").concat(grid.getName()); + infoContext.addFormLocation(gridLocation); + } + + @Override public void visit(GetRelated getRelated) throws Exception { infoContext.addEntityName(getRelated.getRelationName()); } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java Sun Jan 25 17:18:24 2015 @@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletReq import javax.xml.parsers.ParserConfigurationException; import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; @@ -40,7 +41,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; - /** * Widget Library - Form factory class */ @@ -90,7 +90,7 @@ public class FormFactory { URL formFileUrl = servletContext.getResource(resourceName); Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); - modelForm = new ModelForm(formElement, resourceName, delegator.getModelReader(), dispatcher.getDispatchContext()); + modelForm = createModelForm(formElement, delegator.getModelReader(), dispatcher.getDispatchContext(), resourceName, formName); modelForm = formWebappCache.putIfAbsentAndGet(cacheKey, modelForm); } if (modelForm == null) { @@ -125,7 +125,11 @@ public class FormFactory { } public static ModelForm createModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { - ModelForm modelForm = new ModelForm(formElement, formLocation, entityModelReader, dispatchContext); - return modelForm; + String formType = formElement.getAttribute("type"); + if (formType.isEmpty() || "single".equals(formType) || "upload".equals(formType)) { + return new ModelSingleForm(formElement, formLocation, entityModelReader, dispatchContext); + } else { + return new ModelGrid(formElement, formLocation, entityModelReader, dispatchContext); + } } } Added: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/GridFactory.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/GridFactory.java?rev=1654670&view=auto ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/GridFactory.java (added) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/GridFactory.java Sun Jan 25 17:18:24 2015 @@ -0,0 +1,134 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.widget.model; + +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.xml.parsers.ParserConfigurationException; + +import org.ofbiz.base.location.FlexibleLocation; +import org.ofbiz.base.util.UtilHttp; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.cache.UtilCache; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.model.ModelReader; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.LocalDispatcher; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + + +/** + * Widget Library - Grid factory class + */ +public class GridFactory { + + public static final String module = GridFactory.class.getName(); + private static final UtilCache<String, ModelGrid> gridLocationCache = UtilCache.createUtilCache("widget.grid.locationResource", 0, 0, false); + private static final UtilCache<String, ModelGrid> gridWebappCache = UtilCache.createUtilCache("widget.grid.webappResource", 0, 0, false); + + public static Map<String, ModelGrid> getGridsFromLocation(String resourceName, ModelReader entityModelReader, DispatchContext dispatchContext) + throws IOException, SAXException, ParserConfigurationException { + URL gridFileUrl = FlexibleLocation.resolveLocation(resourceName); + Document gridFileDoc = UtilXml.readXmlDocument(gridFileUrl, true, true); + return readGridDocument(gridFileDoc, entityModelReader, dispatchContext, resourceName); + } + + public static ModelGrid getGridFromLocation(String resourceName, String gridName, ModelReader entityModelReader, DispatchContext dispatchContext) + throws IOException, SAXException, ParserConfigurationException { + StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName()); + sb.append(":").append(resourceName).append("#").append(gridName); + String cacheKey = sb.toString(); + ModelGrid modelGrid = gridLocationCache.get(cacheKey); + if (modelGrid == null) { + URL gridFileUrl = FlexibleLocation.resolveLocation(resourceName); + Document gridFileDoc = UtilXml.readXmlDocument(gridFileUrl, true, true); + if (gridFileDoc == null) { + throw new IllegalArgumentException("Could not find resource [" + resourceName + "]"); + } + modelGrid = createModelGrid(gridFileDoc, entityModelReader, dispatchContext, resourceName, gridName); + modelGrid = gridLocationCache.putIfAbsentAndGet(cacheKey, modelGrid); + } + if (modelGrid == null) { + throw new IllegalArgumentException("Could not find grid with name [" + gridName + "] in class resource [" + resourceName + "]"); + } + return modelGrid; + } + + public static ModelGrid getGridFromWebappContext(String resourceName, String gridName, HttpServletRequest request) + throws IOException, SAXException, ParserConfigurationException { + String webappName = UtilHttp.getApplicationName(request); + String cacheKey = webappName + "::" + resourceName + "::" + gridName; + ModelGrid modelGrid = gridWebappCache.get(cacheKey); + if (modelGrid == null) { + ServletContext servletContext = (ServletContext) request.getAttribute("servletContext"); + Delegator delegator = (Delegator) request.getAttribute("delegator"); + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + URL gridFileUrl = servletContext.getResource(resourceName); + Document gridFileDoc = UtilXml.readXmlDocument(gridFileUrl, true, true); + Element gridElement = UtilXml.firstChildElement(gridFileDoc.getDocumentElement(), "grid", "name", gridName); + modelGrid = createModelGrid(gridElement, delegator.getModelReader(), dispatcher.getDispatchContext(), resourceName, gridName); + modelGrid = gridWebappCache.putIfAbsentAndGet(cacheKey, modelGrid); + } + if (modelGrid == null) { + throw new IllegalArgumentException("Could not find grid with name [" + gridName + "] in webapp resource [" + resourceName + "] in the webapp [" + webappName + "]"); + } + return modelGrid; + } + + public static Map<String, ModelGrid> readGridDocument(Document gridFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation) { + Map<String, ModelGrid> modelGridMap = new HashMap<String, ModelGrid>(); + if (gridFileDoc != null) { + // read document and construct ModelGrid for each grid element + Element rootElement = gridFileDoc.getDocumentElement(); + List<? extends Element> gridElements = UtilXml.childElementList(rootElement, "grid"); + for (Element gridElement : gridElements) { + String gridName = gridElement.getAttribute("name"); + String cacheKey = gridLocation + "#" + gridName; + ModelGrid modelGrid = gridLocationCache.get(cacheKey); + if (modelGrid == null) { + modelGrid = createModelGrid(gridElement, entityModelReader, dispatchContext, gridLocation, gridName); + modelGrid = gridLocationCache.putIfAbsentAndGet(cacheKey, modelGrid); + } + modelGridMap.put(gridName, modelGrid); + } + } + return modelGridMap; + } + + public static ModelGrid createModelGrid(Document gridFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) { + Element gridElement = UtilXml.firstChildElement(gridFileDoc.getDocumentElement(), "grid", "name", gridName); + if (gridElement == null) { + // Backwards compatibility - look for form definition + gridElement = UtilXml.firstChildElement(gridFileDoc.getDocumentElement(), "form", "name", gridName); + } + return createModelGrid(gridElement, entityModelReader, dispatchContext, gridLocation, gridName); + } + + public static ModelGrid createModelGrid(Element gridElement, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) { + return new ModelGrid(gridElement, gridLocation, entityModelReader, dispatchContext); + } +} Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelForm.java?rev=1654670&r1=1654669&r2=1654670&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelForm.java Sun Jan 25 17:18:24 2015 @@ -62,7 +62,7 @@ import bsh.Interpreter; * @see <code>widget-form.xsd</code> */ @SuppressWarnings("serial") -public class ModelForm extends ModelWidget { +public abstract class ModelForm extends ModelWidget { /* * ----------------------------------------------------------------------- * @@ -98,41 +98,41 @@ public class ModelForm extends ModelWidg public static String DEFAULT_SORT_FIELD_STYLE = "sort-order"; public static String DEFAULT_SORT_FIELD_ASC_STYLE = "sort-order-asc"; public static String DEFAULT_SORT_FIELD_DESC_STYLE = "sort-order-desc"; - private final List<ModelAction> actions; - private final List<AltRowStyle> altRowStyles; - private final List<AltTarget> altTargets; - private final List<AutoFieldsEntity> autoFieldsEntities; - private final List<AutoFieldsService> autoFieldsServices; - private final boolean clientAutocompleteFields; - private final String containerId; - private final String containerStyle; - private final String defaultEntityName; + protected final List<ModelAction> actions; + protected final List<AltRowStyle> altRowStyles; + protected final List<AltTarget> altTargets; + protected final List<AutoFieldsEntity> autoFieldsEntities; + protected final List<AutoFieldsService> autoFieldsServices; + protected final boolean clientAutocompleteFields; + protected final String containerId; + protected final String containerStyle; + protected final String defaultEntityName; /** This field group will be the "catch-all" group for fields that are not * included in an explicit field-group. */ - private final FieldGroup defaultFieldGroup; - private final FlexibleMapAccessor<Map<String, ? extends Object>> defaultMapName; - private final String defaultRequiredFieldStyle; - private final String defaultServiceName; - private final String defaultSortFieldAscStyle; - private final String defaultSortFieldDescStyle; - private final String defaultSortFieldStyle; - private final String defaultTableStyle; - private final String defaultTitleAreaStyle; - private final String defaultTitleStyle; - private final String defaultTooltipStyle; - private final int defaultViewSize; - private final String defaultWidgetAreaStyle; - private final String defaultWidgetStyle; - private final String evenRowStyle; + protected final FieldGroup defaultFieldGroup; + protected final FlexibleMapAccessor<Map<String, ? extends Object>> defaultMapName; + protected final String defaultRequiredFieldStyle; + protected final String defaultServiceName; + protected final String defaultSortFieldAscStyle; + protected final String defaultSortFieldDescStyle; + protected final String defaultSortFieldStyle; + protected final String defaultTableStyle; + protected final String defaultTitleAreaStyle; + protected final String defaultTitleStyle; + protected final String defaultTooltipStyle; + protected final int defaultViewSize; + protected final String defaultWidgetAreaStyle; + protected final String defaultWidgetStyle; + protected final String evenRowStyle; /** This is a list of FieldGroups in the order they were created. * Can also include Banner objects. */ - private final List<FieldGroupBase> fieldGroupList; + protected final List<FieldGroupBase> fieldGroupList; /** This Map is keyed with the field name and has a FieldGroup for the value. * Can also include Banner objects. */ - private final Map<String, FieldGroupBase> fieldGroupMap; + protected final Map<String, FieldGroupBase> fieldGroupMap; /** This List will contain one copy of each field for each field name in the order * they were encountered in the service, entity, or form definition; field definitions * with constraints will also be in this list but may appear multiple times for the same @@ -142,67 +142,67 @@ public class ModelForm extends ModelWidg * necessary to use the Map. The Map is used when loading the form definition to keep the * list clean and implement the override features for field definitions. */ - private final List<ModelFormField> fieldList; - private final String focusFieldName; - private final String formLocation; - private final String formTitleAreaStyle; - private final String formWidgetAreaStyle; - private final boolean groupColumns; - private final String headerRowStyle; - private final boolean hideHeader; - private final String itemIndexSeparator; - private final List<String> lastOrderFields; - private final String listEntryName; - private final String listName; - private final List<ModelFormField> multiSubmitFields; - private final String oddRowStyle; + protected final List<ModelFormField> fieldList; + protected final String focusFieldName; + protected final String formLocation; + protected final String formTitleAreaStyle; + protected final String formWidgetAreaStyle; + protected final boolean groupColumns; + protected final String headerRowStyle; + protected final boolean hideHeader; + protected final String itemIndexSeparator; + protected final List<String> lastOrderFields; + protected final String listEntryName; + protected final String listName; + protected final List<ModelFormField> multiSubmitFields; + protected final String oddRowStyle; /** On Paginate areas to be updated. */ - private final List<UpdateArea> onPaginateUpdateAreas; + protected final List<UpdateArea> onPaginateUpdateAreas; /** On Sort Column areas to be updated. */ - private final List<UpdateArea> onSortColumnUpdateAreas; + protected final List<UpdateArea> onSortColumnUpdateAreas; /** On Submit areas to be updated. */ - private final List<UpdateArea> onSubmitUpdateAreas; - private final FlexibleStringExpander overrideListSize; - private final FlexibleStringExpander paginate; - private final FlexibleStringExpander paginateFirstLabel; - private final FlexibleStringExpander paginateIndexField; - private final FlexibleStringExpander paginateLastLabel; - private final FlexibleStringExpander paginateNextLabel; - private final FlexibleStringExpander paginatePreviousLabel; - private final FlexibleStringExpander paginateSizeField; - private final String paginateStyle; - private final FlexibleStringExpander paginateTarget; - private final String paginateTargetAnchor; - private final FlexibleStringExpander paginateViewSizeLabel; - private final ModelForm parentModelForm; - private final List<ModelAction> rowActions; - private final FlexibleStringExpander rowCountExdr; - private final boolean separateColumns; - private final boolean skipEnd; - private final boolean skipStart; - private final String sortFieldParameterName; - private final List<SortField> sortOrderFields; - private final FlexibleStringExpander target; - private final String targetType; - private final FlexibleStringExpander targetWindowExdr; - private final String title; - private final String tooltip; - private final String type; - private final boolean useRowSubmit; + protected final List<UpdateArea> onSubmitUpdateAreas; + protected final FlexibleStringExpander overrideListSize; + protected final FlexibleStringExpander paginate; + protected final FlexibleStringExpander paginateFirstLabel; + protected final FlexibleStringExpander paginateIndexField; + protected final FlexibleStringExpander paginateLastLabel; + protected final FlexibleStringExpander paginateNextLabel; + protected final FlexibleStringExpander paginatePreviousLabel; + protected final FlexibleStringExpander paginateSizeField; + protected final String paginateStyle; + protected final FlexibleStringExpander paginateTarget; + protected final String paginateTargetAnchor; + protected final FlexibleStringExpander paginateViewSizeLabel; + protected final ModelForm parentModel; + protected final List<ModelAction> rowActions; + protected final FlexibleStringExpander rowCountExdr; + protected final boolean separateColumns; + protected final boolean skipEnd; + protected final boolean skipStart; + protected final String sortFieldParameterName; + protected final List<SortField> sortOrderFields; + protected final FlexibleStringExpander target; + protected final String targetType; + protected final FlexibleStringExpander targetWindowExdr; + protected final String title; + protected final String tooltip; + protected final String type; + protected final boolean useRowSubmit; /** Keeps track of conditional fields to help ensure that only one is rendered */ - private final Set<String> useWhenFields; + protected final Set<String> useWhenFields; /** XML Constructor */ - public ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext) { + protected ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext) { super(formElement); this.formLocation = formLocation; - parentModelForm = getParentForm(formElement, entityModelReader, dispatchContext); + parentModel = getParentModel(formElement, entityModelReader, dispatchContext); int defaultViewSizeInt = DEFAULT_PAGE_SIZE; String viewSize = formElement.getAttribute("view-size"); if (viewSize.isEmpty()) { - if (parentModelForm != null) { - defaultViewSizeInt = parentModelForm.defaultViewSize; + if (parentModel != null) { + defaultViewSizeInt = parentModel.defaultViewSize; } else { defaultViewSizeInt = UtilProperties.getPropertyAsInteger("widget.properties", "widget.form.defaultViewSize", defaultViewSizeInt); @@ -215,167 +215,167 @@ public class ModelForm extends ModelWidg } this.defaultViewSize = defaultViewSizeInt; String type = formElement.getAttribute("type"); - if (type.isEmpty() && parentModelForm != null) { - type = parentModelForm.type; + if (type.isEmpty() && parentModel != null) { + type = parentModel.type; } this.type = type; FlexibleStringExpander target = FlexibleStringExpander.getInstance(formElement.getAttribute("target")); - if (target.isEmpty() && parentModelForm != null) { - target = parentModelForm.target; + if (target.isEmpty() && parentModel != null) { + target = parentModel.target; } this.target = target; String containerId = formElement.getAttribute("id"); - if (containerId.isEmpty() && parentModelForm != null) { - containerId = parentModelForm.containerId; + if (containerId.isEmpty() && parentModel != null) { + containerId = parentModel.containerId; } this.containerId = containerId; String containerStyle = formElement.getAttribute("style"); - if (containerStyle.isEmpty() && parentModelForm != null) { - containerStyle = parentModelForm.containerStyle; + if (containerStyle.isEmpty() && parentModel != null) { + containerStyle = parentModel.containerStyle; } this.containerStyle = containerStyle; String title = formElement.getAttribute("title"); - if (title.isEmpty() && parentModelForm != null) { - title = parentModelForm.title; + if (title.isEmpty() && parentModel != null) { + title = parentModel.title; } this.title = title; String tooltip = formElement.getAttribute("tooltip"); - if (tooltip.isEmpty() && parentModelForm != null) { - tooltip = parentModelForm.tooltip; + if (tooltip.isEmpty() && parentModel != null) { + tooltip = parentModel.tooltip; } this.tooltip = tooltip; String listName = formElement.getAttribute("list-name"); if (listName.isEmpty()) { - if (parentModelForm != null) { - listName = parentModelForm.listName; + if (parentModel != null) { + listName = parentModel.listName; } else { listName = DEFAULT_FORM_RESULT_LIST_NAME; } } this.listName = listName; String listEntryName = formElement.getAttribute("list-entry-name"); - if (listEntryName.isEmpty() && parentModelForm != null) { - listEntryName = parentModelForm.listEntryName; + if (listEntryName.isEmpty() && parentModel != null) { + listEntryName = parentModel.listEntryName; } this.listEntryName = listEntryName; String defaultEntityName = formElement.getAttribute("default-entity-name"); - if (defaultEntityName.isEmpty() && parentModelForm != null) { - defaultEntityName = parentModelForm.defaultEntityName; + if (defaultEntityName.isEmpty() && parentModel != null) { + defaultEntityName = parentModel.defaultEntityName; } this.defaultEntityName = defaultEntityName; String defaultServiceName = formElement.getAttribute("default-service-name"); - if (defaultServiceName.isEmpty() && parentModelForm != null) { - defaultServiceName = parentModelForm.defaultServiceName; + if (defaultServiceName.isEmpty() && parentModel != null) { + defaultServiceName = parentModel.defaultServiceName; } this.defaultServiceName = defaultServiceName; String formTitleAreaStyle = formElement.getAttribute("form-title-area-style"); - if (formTitleAreaStyle.isEmpty() && parentModelForm != null) { - formTitleAreaStyle = parentModelForm.formTitleAreaStyle; + if (formTitleAreaStyle.isEmpty() && parentModel != null) { + formTitleAreaStyle = parentModel.formTitleAreaStyle; } this.formTitleAreaStyle = formTitleAreaStyle; String formWidgetAreaStyle = formElement.getAttribute("form-widget-area-style"); - if (formWidgetAreaStyle.isEmpty() && parentModelForm != null) { - formWidgetAreaStyle = parentModelForm.formWidgetAreaStyle; + if (formWidgetAreaStyle.isEmpty() && parentModel != null) { + formWidgetAreaStyle = parentModel.formWidgetAreaStyle; } this.formWidgetAreaStyle = formWidgetAreaStyle; String defaultTitleAreaStyle = formElement.getAttribute("default-title-area-style"); - if (defaultTitleAreaStyle.isEmpty() && parentModelForm != null) { - defaultTitleAreaStyle = parentModelForm.defaultTitleAreaStyle; + if (defaultTitleAreaStyle.isEmpty() && parentModel != null) { + defaultTitleAreaStyle = parentModel.defaultTitleAreaStyle; } this.defaultTitleAreaStyle = defaultTitleAreaStyle; String defaultWidgetAreaStyle = formElement.getAttribute("default-widget-area-style"); - if (defaultWidgetAreaStyle.isEmpty() && parentModelForm != null) { - defaultWidgetAreaStyle = parentModelForm.defaultWidgetAreaStyle; + if (defaultWidgetAreaStyle.isEmpty() && parentModel != null) { + defaultWidgetAreaStyle = parentModel.defaultWidgetAreaStyle; } this.defaultWidgetAreaStyle = defaultWidgetAreaStyle; String oddRowStyle = formElement.getAttribute("odd-row-style"); - if (oddRowStyle.isEmpty() && parentModelForm != null) { - oddRowStyle = parentModelForm.oddRowStyle; + if (oddRowStyle.isEmpty() && parentModel != null) { + oddRowStyle = parentModel.oddRowStyle; } this.oddRowStyle = oddRowStyle; String evenRowStyle = formElement.getAttribute("even-row-style"); - if (evenRowStyle.isEmpty() && parentModelForm != null) { - evenRowStyle = parentModelForm.evenRowStyle; + if (evenRowStyle.isEmpty() && parentModel != null) { + evenRowStyle = parentModel.evenRowStyle; } this.evenRowStyle = evenRowStyle; String defaultTableStyle = formElement.getAttribute("default-table-style"); - if (defaultTableStyle.isEmpty() && parentModelForm != null) { - defaultTableStyle = parentModelForm.defaultTableStyle; + if (defaultTableStyle.isEmpty() && parentModel != null) { + defaultTableStyle = parentModel.defaultTableStyle; } this.defaultTableStyle = defaultTableStyle; String headerRowStyle = formElement.getAttribute("header-row-style"); - if (headerRowStyle.isEmpty() && parentModelForm != null) { - headerRowStyle = parentModelForm.headerRowStyle; + if (headerRowStyle.isEmpty() && parentModel != null) { + headerRowStyle = parentModel.headerRowStyle; } this.headerRowStyle = headerRowStyle; String defaultTitleStyle = formElement.getAttribute("default-title-style"); - if (defaultTitleStyle.isEmpty() && parentModelForm != null) { - defaultTitleStyle = parentModelForm.defaultTitleStyle; + if (defaultTitleStyle.isEmpty() && parentModel != null) { + defaultTitleStyle = parentModel.defaultTitleStyle; } this.defaultTitleStyle = defaultTitleStyle; String defaultWidgetStyle = formElement.getAttribute("default-widget-style"); - if (defaultWidgetStyle.isEmpty() && parentModelForm != null) { - defaultWidgetStyle = parentModelForm.defaultWidgetStyle; + if (defaultWidgetStyle.isEmpty() && parentModel != null) { + defaultWidgetStyle = parentModel.defaultWidgetStyle; } this.defaultWidgetStyle = defaultWidgetStyle; String defaultTooltipStyle = formElement.getAttribute("default-tooltip-style"); - if (defaultTooltipStyle.isEmpty() && parentModelForm != null) { - defaultTooltipStyle = parentModelForm.defaultTooltipStyle; + if (defaultTooltipStyle.isEmpty() && parentModel != null) { + defaultTooltipStyle = parentModel.defaultTooltipStyle; } this.defaultTooltipStyle = defaultTooltipStyle; String itemIndexSeparator = formElement.getAttribute("item-index-separator"); - if (itemIndexSeparator.isEmpty() && parentModelForm != null) { - itemIndexSeparator = parentModelForm.itemIndexSeparator; + if (itemIndexSeparator.isEmpty() && parentModel != null) { + itemIndexSeparator = parentModel.itemIndexSeparator; } this.itemIndexSeparator = itemIndexSeparator; String separateColumns = formElement.getAttribute("separate-columns"); - if (separateColumns.isEmpty() && parentModelForm != null) { - this.separateColumns = parentModelForm.separateColumns; + if (separateColumns.isEmpty() && parentModel != null) { + this.separateColumns = parentModel.separateColumns; } else { this.separateColumns = "true".equals(separateColumns); } String groupColumns = formElement.getAttribute("group-columns"); - if (groupColumns.isEmpty() && parentModelForm != null) { - this.groupColumns = parentModelForm.groupColumns; + if (groupColumns.isEmpty() && parentModel != null) { + this.groupColumns = parentModel.groupColumns; } else { this.groupColumns = !"false".equals(groupColumns); } String targetType = formElement.getAttribute("target-type"); - if (targetType.isEmpty() && parentModelForm != null) { - targetType = parentModelForm.targetType; + if (targetType.isEmpty() && parentModel != null) { + targetType = parentModel.targetType; } this.targetType = targetType; FlexibleMapAccessor<Map<String, ? extends Object>> defaultMapName = FlexibleMapAccessor.getInstance(formElement .getAttribute("default-map-name")); - if (defaultMapName.isEmpty() && parentModelForm != null) { - defaultMapName = parentModelForm.defaultMapName; + if (defaultMapName.isEmpty() && parentModel != null) { + defaultMapName = parentModel.defaultMapName; } this.defaultMapName = defaultMapName; FlexibleStringExpander targetWindowExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("target-window")); - if (targetWindowExdr.isEmpty() && parentModelForm != null) { - targetWindowExdr = parentModelForm.targetWindowExdr; + if (targetWindowExdr.isEmpty() && parentModel != null) { + targetWindowExdr = parentModel.targetWindowExdr; } this.targetWindowExdr = targetWindowExdr; String hideHeader = formElement.getAttribute("hide-header"); - if (hideHeader.isEmpty() && parentModelForm != null) { - this.hideHeader = parentModelForm.hideHeader; + if (hideHeader.isEmpty() && parentModel != null) { + this.hideHeader = parentModel.hideHeader; } else { this.hideHeader = "true".equals(hideHeader); } String clientAutocompleteFields = formElement.getAttribute("client-autocomplete-fields"); - if (clientAutocompleteFields.isEmpty() && parentModelForm != null) { - this.clientAutocompleteFields = parentModelForm.clientAutocompleteFields; + if (clientAutocompleteFields.isEmpty() && parentModel != null) { + this.clientAutocompleteFields = parentModel.clientAutocompleteFields; } else { this.clientAutocompleteFields = !"false".equals(formElement.getAttribute("client-autocomplete-fields")); } FlexibleStringExpander paginateTarget = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate-target")); - if (paginateTarget.isEmpty() && parentModelForm != null) { - paginateTarget = parentModelForm.paginateTarget; + if (paginateTarget.isEmpty() && parentModel != null) { + paginateTarget = parentModel.paginateTarget; } this.paginateTarget = paginateTarget; ArrayList<AltTarget> altTargets = new ArrayList<AltTarget>(); - if (parentModelForm != null) { - altTargets.addAll(parentModelForm.altTargets); + if (parentModel != null) { + altTargets.addAll(parentModel.altTargets); } for (Element altTargetElement : UtilXml.childElementList(formElement, "alt-target")) { altTargets.add(new AltTarget(altTargetElement)); @@ -383,8 +383,8 @@ public class ModelForm extends ModelWidg altTargets.trimToSize(); this.altTargets = Collections.unmodifiableList(altTargets); ArrayList<ModelAction> actions = new ArrayList<ModelAction>(); - if (parentModelForm != null) { - actions.addAll(parentModelForm.actions); + if (parentModel != null) { + actions.addAll(parentModel.actions); } Element actionsElement = UtilXml.firstChildElement(formElement, "actions"); if (actionsElement != null) { @@ -393,8 +393,8 @@ public class ModelForm extends ModelWidg actions.trimToSize(); this.actions = Collections.unmodifiableList(actions); ArrayList<ModelAction> rowActions = new ArrayList<ModelAction>(); - if (parentModelForm != null) { - rowActions.addAll(parentModelForm.rowActions); + if (parentModel != null) { + rowActions.addAll(parentModel.rowActions); } Element rowActionsElement = UtilXml.firstChildElement(formElement, "row-actions"); if (rowActionsElement != null) { @@ -405,10 +405,10 @@ public class ModelForm extends ModelWidg ArrayList<UpdateArea> onPaginateUpdateAreas = new ArrayList<UpdateArea>(); ArrayList<UpdateArea> onSubmitUpdateAreas = new ArrayList<UpdateArea>(); ArrayList<UpdateArea> onSortColumnUpdateAreas = new ArrayList<UpdateArea>(); - if (parentModelForm != null) { - onPaginateUpdateAreas.addAll(parentModelForm.onPaginateUpdateAreas); - onSubmitUpdateAreas.addAll(parentModelForm.onSubmitUpdateAreas); - onSortColumnUpdateAreas.addAll(parentModelForm.onSortColumnUpdateAreas); + if (parentModel != null) { + onPaginateUpdateAreas.addAll(parentModel.onPaginateUpdateAreas); + onSubmitUpdateAreas.addAll(parentModel.onSubmitUpdateAreas); + onSortColumnUpdateAreas.addAll(parentModel.onSortColumnUpdateAreas); } for (Element updateAreaElement : UtilXml.childElementList(formElement, "on-event-update-area")) { UpdateArea updateArea = new UpdateArea(updateAreaElement, defaultServiceName, defaultEntityName); @@ -452,8 +452,8 @@ public class ModelForm extends ModelWidg onSortColumnUpdateAreas.trimToSize(); this.onSortColumnUpdateAreas = Collections.unmodifiableList(onSortColumnUpdateAreas); ArrayList<AltRowStyle> altRowStyles = new ArrayList<AltRowStyle>(); - if (parentModelForm != null) { - altRowStyles.addAll(parentModelForm.altRowStyles); + if (parentModel != null) { + altRowStyles.addAll(parentModel.altRowStyles); } for (Element altRowStyleElement : UtilXml.childElementList(formElement, "alt-row-style")) { AltRowStyle altRowStyle = new AltRowStyle(altRowStyleElement); @@ -462,14 +462,14 @@ public class ModelForm extends ModelWidg altRowStyles.trimToSize(); this.altRowStyles = Collections.unmodifiableList(altRowStyles); Set<String> useWhenFields = new HashSet<String>(); - if (parentModelForm != null) { - useWhenFields.addAll(parentModelForm.useWhenFields); + if (parentModel != null) { + useWhenFields.addAll(parentModel.useWhenFields); } ArrayList<ModelFormFieldBuilder> fieldBuilderList = new ArrayList<ModelFormFieldBuilder>(); Map<String, ModelFormFieldBuilder> fieldBuilderMap = new HashMap<String, ModelFormFieldBuilder>(); - if (parentModelForm != null) { - // Create this fieldList/Map from clones of parentModelForm's - for (ModelFormField parentChildField : parentModelForm.fieldList) { + if (parentModel != null) { + // Create this fieldList/Map from clones of parentModel's + for (ModelFormField parentChildField : parentModel.fieldList) { ModelFormFieldBuilder builder = new ModelFormFieldBuilder(parentChildField); builder.setModelForm(this); fieldBuilderList.add(builder); @@ -477,131 +477,131 @@ public class ModelForm extends ModelWidg } } Map<String, FieldGroupBase> fieldGroupMap = new HashMap<String, FieldGroupBase>(); - if (parentModelForm != null) { - fieldGroupMap.putAll(parentModelForm.fieldGroupMap); + if (parentModel != null) { + fieldGroupMap.putAll(parentModel.fieldGroupMap); } ArrayList<FieldGroupBase> fieldGroupList = new ArrayList<FieldGroupBase>(); - if (parentModelForm != null) { - fieldGroupList.addAll(parentModelForm.fieldGroupList); + if (parentModel != null) { + fieldGroupList.addAll(parentModel.fieldGroupList); } ArrayList<String> lastOrderFields = new ArrayList<String>(); - if (parentModelForm != null) { - lastOrderFields.addAll(parentModelForm.lastOrderFields); + if (parentModel != null) { + lastOrderFields.addAll(parentModel.lastOrderFields); } String sortFieldParameterName = formElement.getAttribute("sort-field-parameter-name"); - if (sortFieldParameterName.isEmpty() && parentModelForm != null) { - this.sortFieldParameterName = parentModelForm.targetType; + if (sortFieldParameterName.isEmpty() && parentModel != null) { + this.sortFieldParameterName = parentModel.targetType; } else { this.sortFieldParameterName = "sortField"; } String defaultRequiredFieldStyle = formElement.getAttribute("default-required-field-style"); - if (defaultRequiredFieldStyle.isEmpty() && parentModelForm != null) { - defaultRequiredFieldStyle = parentModelForm.defaultRequiredFieldStyle; + if (defaultRequiredFieldStyle.isEmpty() && parentModel != null) { + defaultRequiredFieldStyle = parentModel.defaultRequiredFieldStyle; } this.defaultRequiredFieldStyle = defaultRequiredFieldStyle; String defaultSortFieldStyle = formElement.getAttribute("default-sort-field-style"); - if (defaultSortFieldStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldStyle = parentModelForm.defaultSortFieldStyle; + if (defaultSortFieldStyle.isEmpty() && parentModel != null) { + this.defaultSortFieldStyle = parentModel.defaultSortFieldStyle; } else { this.defaultSortFieldStyle = DEFAULT_SORT_FIELD_STYLE; } String defaultSortFieldAscStyle = formElement.getAttribute("default-sort-field-asc-style"); - if (defaultSortFieldAscStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldAscStyle = parentModelForm.defaultSortFieldAscStyle; + if (defaultSortFieldAscStyle.isEmpty() && parentModel != null) { + this.defaultSortFieldAscStyle = parentModel.defaultSortFieldAscStyle; } else { this.defaultSortFieldAscStyle = DEFAULT_SORT_FIELD_ASC_STYLE; } String defaultSortFieldDescStyle = formElement.getAttribute("default-sort-field-desc-style"); - if (defaultSortFieldDescStyle.isEmpty() && parentModelForm != null) { - this.defaultSortFieldDescStyle = parentModelForm.defaultSortFieldDescStyle; + if (defaultSortFieldDescStyle.isEmpty() && parentModel != null) { + this.defaultSortFieldDescStyle = parentModel.defaultSortFieldDescStyle; } else { this.defaultSortFieldDescStyle = DEFAULT_SORT_FIELD_DESC_STYLE; } String paginateTargetAnchor = formElement.getAttribute("paginate-target-anchor"); - if (paginateTargetAnchor.isEmpty() && parentModelForm != null) { - paginateTargetAnchor = parentModelForm.paginateTargetAnchor; + if (paginateTargetAnchor.isEmpty() && parentModel != null) { + paginateTargetAnchor = parentModel.paginateTargetAnchor; } this.paginateTargetAnchor = paginateTargetAnchor; FlexibleStringExpander paginateIndexField = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-index-field")); - if (paginateIndexField.isEmpty() && parentModelForm != null) { - paginateIndexField = parentModelForm.paginateIndexField; + if (paginateIndexField.isEmpty() && parentModel != null) { + paginateIndexField = parentModel.paginateIndexField; } this.paginateIndexField = paginateIndexField; FlexibleStringExpander paginateSizeField = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-size-field")); - if (paginateSizeField.isEmpty() && parentModelForm != null) { - paginateSizeField = parentModelForm.paginateSizeField; + if (paginateSizeField.isEmpty() && parentModel != null) { + paginateSizeField = parentModel.paginateSizeField; } this.paginateSizeField = paginateSizeField; FlexibleStringExpander overrideListSize = FlexibleStringExpander.getInstance(formElement .getAttribute("override-list-size")); - if (overrideListSize.isEmpty() && parentModelForm != null) { - overrideListSize = parentModelForm.overrideListSize; + if (overrideListSize.isEmpty() && parentModel != null) { + overrideListSize = parentModel.overrideListSize; } this.overrideListSize = overrideListSize; FlexibleStringExpander paginateFirstLabel = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-first-label")); - if (paginateFirstLabel.isEmpty() && parentModelForm != null) { - paginateFirstLabel = parentModelForm.paginateFirstLabel; + if (paginateFirstLabel.isEmpty() && parentModel != null) { + paginateFirstLabel = parentModel.paginateFirstLabel; } this.paginateFirstLabel = paginateFirstLabel; FlexibleStringExpander paginatePreviousLabel = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-previous-label")); - if (paginatePreviousLabel.isEmpty() && parentModelForm != null) { - paginatePreviousLabel = parentModelForm.paginatePreviousLabel; + if (paginatePreviousLabel.isEmpty() && parentModel != null) { + paginatePreviousLabel = parentModel.paginatePreviousLabel; } this.paginatePreviousLabel = paginatePreviousLabel; FlexibleStringExpander paginateNextLabel = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-next-label")); - if (paginateNextLabel.isEmpty() && parentModelForm != null) { - paginateNextLabel = parentModelForm.paginateNextLabel; + if (paginateNextLabel.isEmpty() && parentModel != null) { + paginateNextLabel = parentModel.paginateNextLabel; } this.paginateNextLabel = paginateNextLabel; FlexibleStringExpander paginateLastLabel = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-last-label")); - if (paginateLastLabel.isEmpty() && parentModelForm != null) { - paginateLastLabel = parentModelForm.paginateLastLabel; + if (paginateLastLabel.isEmpty() && parentModel != null) { + paginateLastLabel = parentModel.paginateLastLabel; } this.paginateLastLabel = paginateLastLabel; FlexibleStringExpander paginateViewSizeLabel = FlexibleStringExpander.getInstance(formElement .getAttribute("paginate-viewsize-label")); - if (paginateViewSizeLabel.isEmpty() && parentModelForm != null) { - paginateViewSizeLabel = parentModelForm.paginateViewSizeLabel; + if (paginateViewSizeLabel.isEmpty() && parentModel != null) { + paginateViewSizeLabel = parentModel.paginateViewSizeLabel; } this.paginateViewSizeLabel = paginateViewSizeLabel; String paginateStyle = formElement.getAttribute("paginate-style"); - if (paginateStyle.isEmpty() && parentModelForm != null) { - this.paginateStyle = parentModelForm.paginateStyle; + if (paginateStyle.isEmpty() && parentModel != null) { + this.paginateStyle = parentModel.paginateStyle; } else { this.paginateStyle = DEFAULT_PAG_STYLE; } FlexibleStringExpander paginate = FlexibleStringExpander.getInstance(formElement.getAttribute("paginate")); - if (paginate.isEmpty() && parentModelForm != null) { - paginate = parentModelForm.paginate; + if (paginate.isEmpty() && parentModel != null) { + paginate = parentModel.paginate; } this.paginate = paginate; String skipStart = formElement.getAttribute("skip-start"); - if (skipStart.isEmpty() && parentModelForm != null) { - this.skipStart = parentModelForm.skipStart; + if (skipStart.isEmpty() && parentModel != null) { + this.skipStart = parentModel.skipStart; } else { this.skipStart = "true".equals(skipStart); } String skipEnd = formElement.getAttribute("skip-end"); - if (skipEnd.isEmpty() && parentModelForm != null) { - this.skipEnd = parentModelForm.skipEnd; + if (skipEnd.isEmpty() && parentModel != null) { + this.skipEnd = parentModel.skipEnd; } else { this.skipEnd = "true".equals(skipEnd); } String useRowSubmit = formElement.getAttribute("use-row-submit"); - if (useRowSubmit.isEmpty() && parentModelForm != null) { - this.useRowSubmit = parentModelForm.useRowSubmit; + if (useRowSubmit.isEmpty() && parentModel != null) { + this.useRowSubmit = parentModel.useRowSubmit; } else { this.useRowSubmit = "true".equals(useRowSubmit); } FlexibleStringExpander rowCountExdr = FlexibleStringExpander.getInstance(formElement.getAttribute("row-count")); - if (rowCountExdr.isEmpty() && parentModelForm != null) { - rowCountExdr = parentModelForm.rowCountExdr; + if (rowCountExdr.isEmpty() && parentModel != null) { + rowCountExdr = parentModel.rowCountExdr; } this.rowCountExdr = paginate; ArrayList<ModelFormFieldBuilder> multiSubmitBuilders = new ArrayList<ModelFormFieldBuilder>(); @@ -728,8 +728,8 @@ public class ModelForm extends ModelWidg sortOrderFields.trimToSize(); this.sortOrderFields = Collections.unmodifiableList(sortOrderFields); String focusFieldName = formElement.getAttribute("focus-field-name"); - if (focusFieldName.isEmpty() && parentModelForm != null) { - focusFieldName = parentModelForm.focusFieldName; + if (focusFieldName.isEmpty() && parentModel != null) { + focusFieldName = parentModel.focusFieldName; } this.focusFieldName = focusFieldName; } @@ -1245,51 +1245,18 @@ public class ModelForm extends ModelWidg return field; } - private ModelForm getParentForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) { - ModelForm parent = null; - String parentResource = formElement.getAttribute("extends-resource"); - String parentForm = formElement.getAttribute("extends"); - if (parentForm.length() > 0) { - // check if we have a resource name (part of the string before the ?) - if (parentResource.length() > 0) { - try { - parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext); - } catch (Exception e) { - Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource - + "'", module); - } - } else if (!parentForm.equals(formElement.getAttribute("name"))) { - // try to find a form definition in the same file - Element rootElement = formElement.getOwnerDocument().getDocumentElement(); - List<? extends Element> formElements = UtilXml.childElementList(rootElement, "form"); - //Uncomment below to add support for abstract forms - //formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form")); - for (Element formElementEntry : formElements) { - if (formElementEntry.getAttribute("name").equals(parentForm)) { - parent = new ModelForm(formElementEntry, parentResource, entityModelReader, dispatchContext); - break; - } - } - if (parent == null) { - Debug.logError("Failed to find parent form definition '" + parentForm + "' in same document.", module); - } - } else { - Debug.logError("Recursive form definition found for '" + formElement.getAttribute("name") + ".'", module); - } - } - return parent; - } + protected abstract ModelForm getParentModel(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext); public String getParentFormLocation() { - return this.parentModelForm == null ? null : this.parentModelForm.getFormLocation(); + return this.parentModel == null ? null : this.parentModel.getFormLocation(); } public String getParentFormName() { - return this.parentModelForm == null ? null : this.parentModelForm.getName(); + return this.parentModel == null ? null : this.parentModel.getName(); } public ModelForm getParentModelForm() { - return parentModelForm; + return parentModel; } public String getPassedRowCount(Map<String, Object> context) { @@ -1588,12 +1555,12 @@ public class ModelForm extends ModelWidg public static class FieldGroup implements FieldGroupBase { private static AtomicInteger baseSeqNo = new AtomicInteger(0); private static final String baseId = "_G"; - private final String id; - private final String style; - private final String title; - private final boolean collapsible; - private final boolean initiallyCollapsed; - private final ModelForm modelForm; + protected final String id; + protected final String style; + protected final String title; + protected final boolean collapsible; + protected final boolean initiallyCollapsed; + protected final ModelForm modelForm; public FieldGroup(Element sortOrderElement, ModelForm modelForm, List<SortField> sortOrderFields, Map<String, FieldGroupBase> fieldGroupMap) { @@ -1694,8 +1661,8 @@ public class ModelForm extends ModelWidg } public static class SortField { - private final String fieldName; - private final Integer position; + protected final String fieldName; + protected final Integer position; public SortField(String name) { this(name, null); @@ -1728,14 +1695,14 @@ public class ModelForm extends ModelWidg * elements used in form widgets. */ public static class UpdateArea { - private final String eventType; - private final String areaId; - private final String areaTarget; - private final String defaultServiceName; - private final String defaultEntityName; - private final CommonWidgetModels.AutoEntityParameters autoEntityParameters; - private final CommonWidgetModels.AutoServiceParameters autoServiceParameters; - private final List<CommonWidgetModels.Parameter> parameterList; + protected final String eventType; + protected final String areaId; + protected final String areaTarget; + protected final String defaultServiceName; + protected final String defaultEntityName; + protected final CommonWidgetModels.AutoEntityParameters autoEntityParameters; + protected final CommonWidgetModels.AutoServiceParameters autoServiceParameters; + protected final List<CommonWidgetModels.Parameter> parameterList; public UpdateArea(Element updateAreaElement) { this(updateAreaElement, null, null); |
Free forum by Nabble | Edit this page |