This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a change to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git. from 01bd096 Fixed: The "stream" request-map in ecommerce and commonext controllers requires authentication (OFBIZ-11349) new d8641bc Fixed: Correct FoFormMacro to support form list with non separate fields (OFBIZ-11335) new 1941a05 Improved: Manage VisualTheme in ModelForm (OFBIZ-11335) new 38f972a Improved: Add CommonForms as template pattern configured by theme (OFBIZ-11335) new 296417a Fixed: Correct check style issue on ModelTheme The 4 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../ofbiz/content/data/DataResourceWorker.java | 3 +- framework/common/groovyScripts/InitTheme.groovy | 1 + framework/common/widget/CommonForms.xml | 40 +++++++++++ .../webtools/artifactinfo/ArtifactInfoFactory.java | 7 +- framework/webtools/widget/MiscForms.xml | 60 +++++++++++++++-- framework/webtools/widget/MiscScreens.xml | 34 ++-------- framework/widget/dtd/widget-theme.xsd | 58 ++++++++++------ .../org/apache/ofbiz/widget/model/FormFactory.java | 48 ++++++++----- .../org/apache/ofbiz/widget/model/GridFactory.java | 49 ++++++++++---- .../org/apache/ofbiz/widget/model/ModelForm.java | 11 +-- .../apache/ofbiz/widget/model/ModelFormField.java | 6 +- .../org/apache/ofbiz/widget/model/ModelGrid.java | 27 +++++--- .../ofbiz/widget/model/ModelScreenWidget.java | 7 +- .../apache/ofbiz/widget/model/ModelSingleForm.java | 22 ++++-- .../org/apache/ofbiz/widget/model/ModelTheme.java | 78 ++++++++++++++++++---- .../template/macro/FoFormMacroLibrary.ftl | 8 +-- .../common-theme/widget/CommonForms.xml | 18 ++++- themes/common-theme/widget/Theme.xml | 10 +++ 18 files changed, 358 insertions(+), 129 deletions(-) create mode 100644 framework/common/widget/CommonForms.xml copy applications/humanres/widget/forms/PartyAbilityForms.xml => themes/common-theme/widget/CommonForms.xml (54%) |
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit d8641bce8c1d33703b85ca7366915e4ae0033fe2 Author: Nicolas Malin <[hidden email]> AuthorDate: Thu Feb 20 14:13:57 2020 +0100 Fixed: Correct FoFormMacro to support form list with non separate fields (OFBIZ-11335) Related to issue OFBIZ-11335 when a form list haven't the attribute separate-column to true, the screen engine failed to rendering it through screen-fop due to a block present on table-row without table-cell. We have in log some line like : ScreenFopViewHandler |E| Unable to transform FO file: org.apache.fop.apps.FOPException: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: null:150:2: "fo:block" is not a valid child of "fo:table-row"! Simple fix is to open and close a table-cell when renderFormatHeaderRowFormCell[Open/Close] and renderFormatItemRowFormCell[Open/Close] are called. --- themes/common-theme/template/macro/FoFormMacroLibrary.ftl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/common-theme/template/macro/FoFormMacroLibrary.ftl b/themes/common-theme/template/macro/FoFormMacroLibrary.ftl index c99efc9..948203f 100644 --- a/themes/common-theme/template/macro/FoFormMacroLibrary.ftl +++ b/themes/common-theme/template/macro/FoFormMacroLibrary.ftl @@ -98,16 +98,16 @@ under the License. <#macro renderFormatHeaderRowCellOpen style="" positionSpan=""><fo:table-cell <#if positionSpan?has_content && positionSpan gt 1 >number-columns-spanned="${positionSpan}"</#if><#if style?has_content><@getFoStyle "${style}"/><#else><@getFoStyle "listtitlestyle"/></#if>><fo:block></#macro> <#macro renderFormatHeaderRowCellClose></fo:block></fo:table-cell></#macro> -<#macro renderFormatHeaderRowFormCellOpen style></#macro> -<#macro renderFormatHeaderRowFormCellClose></#macro> +<#macro renderFormatHeaderRowFormCellOpen style><fo:table-cell></#macro> +<#macro renderFormatHeaderRowFormCellClose></fo:table-cell></#macro> <#macro renderFormatHeaderRowFormCellTitleSeparator style isLast></#macro> <#macro renderFormatItemRowOpen formName itemIndex altRowStyles evenRowStyle oddRowStyle><fo:table-row <@getFoStyle "${altRowStyles}"/>></#macro> <#macro renderFormatItemRowClose formName></fo:table-row></#macro> <#macro renderFormatItemRowCellOpen fieldName style="" positionSpan=""><fo:table-cell <#if positionSpan?has_content && positionSpan gt 1 >number-columns-spanned="${positionSpan}"</#if><#if style?has_content><@getFoStyle style/><#else><@getFoStyle "tabletext"/></#if>><fo:block></#macro> <#macro renderFormatItemRowCellClose fieldName></fo:block></fo:table-cell></#macro> -<#macro renderFormatItemRowFormCellOpen style></#macro> -<#macro renderFormatItemRowFormCellClose></#macro> +<#macro renderFormatItemRowFormCellOpen style><fo:table-cell></#macro> +<#macro renderFormatItemRowFormCellClose></fo:table-cell></#macro> <#macro renderFormatSingleWrapperOpen formName style><fo:table><fo:table-column column-width="1.75in"/><fo:table-column column-width="1.75in"/><fo:table-column column-width="1.75in"/><fo:table-column column-width="1.75in"/><fo:table-body></#macro> <#macro renderFormatSingleWrapperClose formName></fo:table-body></fo:table></#macro> |
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit 1941a05a349865b8505ec373de3fce3b3a96c2a0 Author: Nicolas Malin <[hidden email]> AuthorDate: Thu Feb 20 14:34:28 2020 +0100 Improved: Manage VisualTheme in ModelForm (OFBIZ-11335) Related to issue OFBIZ-11335, extends form's factories and form's models to support a visualTheme during the model creation. This extend help centralize style information used by forms on a theme. For performance reason when the model is loaded in memory, all theme information need to be present to set immutable as possible to put it in cache (implies why the key cache contains now the visualThemeId). --- .../ofbiz/content/data/DataResourceWorker.java | 3 +- .../webtools/artifactinfo/ArtifactInfoFactory.java | 7 +++- .../org/apache/ofbiz/widget/model/FormFactory.java | 48 ++++++++++++++------- .../org/apache/ofbiz/widget/model/GridFactory.java | 49 +++++++++++++++------- .../org/apache/ofbiz/widget/model/ModelForm.java | 9 ++-- .../apache/ofbiz/widget/model/ModelFormField.java | 6 ++- .../org/apache/ofbiz/widget/model/ModelGrid.java | 27 ++++++++---- .../ofbiz/widget/model/ModelScreenWidget.java | 7 +++- .../apache/ofbiz/widget/model/ModelSingleForm.java | 22 +++++++--- 9 files changed, 125 insertions(+), 53 deletions(-) diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java index 114e763..f87936a 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/data/DataResourceWorker.java @@ -803,7 +803,8 @@ public class DataResourceWorker implements org.apache.ofbiz.widget.content.Data ModelReader entityModelReader = delegator.getModelReader(); String formText = getDataResourceText(dataResource, targetMimeTypeId, locale, templateContext, delegator, cache); Document formXml = UtilXml.readXmlDocument(formText, true, true); - Map<String, ModelForm> modelFormMap = FormFactory.readFormDocument(formXml, entityModelReader, dispatcher.getDispatchContext(), null); + Map<String, ModelForm> modelFormMap = FormFactory.readFormDocument(formXml, entityModelReader, + UtilHttp.getVisualTheme(request), dispatcher.getDispatchContext(), null); if (UtilValidate.isNotEmpty(modelFormMap)) { Map.Entry<String, ModelForm> entry = modelFormMap.entrySet().iterator().next(); // get first entry, only one form allowed per file diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java index 62fb527..6afa3be 100644 --- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java +++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java @@ -57,6 +57,7 @@ import org.apache.ofbiz.widget.model.FormFactory; import org.apache.ofbiz.widget.model.ModelForm; import org.apache.ofbiz.widget.model.ModelScreen; import org.apache.ofbiz.widget.model.ScreenFactory; +import org.apache.ofbiz.widget.model.ThemeFactory; import org.xml.sax.SAXException; public class ArtifactInfoFactory { @@ -185,7 +186,8 @@ public class ArtifactInfoFactory { return getModelForm(formNameAndLocation.substring(formNameAndLocation.indexOf("#") + 1), formNameAndLocation.substring(0, formNameAndLocation.indexOf("#"))); } public ModelForm getModelForm(String formName, String formLocation) throws ParserConfigurationException, SAXException, IOException { - return FormFactory.getFormFromLocation(formLocation, formName, this.entityModelReader, this.dispatchContext); + return FormFactory.getFormFromLocation(formLocation, formName, this.entityModelReader, + ThemeFactory.getVisualThemeFromId("COMMON"), this.dispatchContext); } public ModelScreen getModelScreen(String screenName, String screenLocation) throws ParserConfigurationException, SAXException, IOException { @@ -436,7 +438,8 @@ public class ArtifactInfoFactory { String formLocation = "component://" + componentName + "/" + formFileRelativePath; Map<String, ModelForm> modelFormMap = null; try { - modelFormMap = FormFactory.getFormsFromLocation(formLocation, getEntityModelReader(), getDispatchContext()); + modelFormMap = FormFactory.getFormsFromLocation(formLocation, getEntityModelReader(), + ThemeFactory.getVisualThemeFromId("COMMON"), getDispatchContext()); } catch (Exception exc) { Debug.logWarning(exc.getMessage(), module); } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/FormFactory.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/FormFactory.java index 78810cd..49d0ebe 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/FormFactory.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/FormFactory.java @@ -35,6 +35,7 @@ import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.model.ModelReader; import org.apache.ofbiz.service.DispatchContext; import org.apache.ofbiz.service.LocalDispatcher; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -48,17 +49,19 @@ public class FormFactory { private static final UtilCache<String, ModelForm> formLocationCache = UtilCache.createUtilCache("widget.form.locationResource", 0, 0, false); private static final UtilCache<String, ModelForm> formWebappCache = UtilCache.createUtilCache("widget.form.webappResource", 0, 0, false); - public static Map<String, ModelForm> getFormsFromLocation(String resourceName, ModelReader entityModelReader, DispatchContext dispatchContext) + public static Map<String, ModelForm> getFormsFromLocation(String resourceName, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) throws IOException, SAXException, ParserConfigurationException { URL formFileUrl = FlexibleLocation.resolveLocation(resourceName); Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); - return readFormDocument(formFileDoc, entityModelReader, dispatchContext, resourceName); + return readFormDocument(formFileDoc, entityModelReader, visualTheme, dispatchContext, resourceName); } - public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, DispatchContext dispatchContext) + public static ModelForm getFormFromLocation(String resourceName, String formName, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) throws IOException, SAXException, ParserConfigurationException { StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName()); - sb.append(":").append(resourceName).append("#").append(formName); + sb.append(":").append(resourceName).append("#").append(formName).append(visualTheme.getVisualThemeId()); String cacheKey = sb.toString(); ModelForm modelForm = formLocationCache.get(cacheKey); if (modelForm == null) { @@ -67,7 +70,7 @@ public class FormFactory { if (formFileDoc == null) { throw new IllegalArgumentException("Could not find resource [" + resourceName + "]"); } - modelForm = createModelForm(formFileDoc, entityModelReader, dispatchContext, resourceName, formName); + modelForm = createModelForm(formFileDoc, entityModelReader, visualTheme, dispatchContext, resourceName, formName); modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); } if (modelForm == null) { @@ -79,7 +82,15 @@ public class FormFactory { public static ModelForm getFormFromWebappContext(String resourceName, String formName, HttpServletRequest request) throws IOException, SAXException, ParserConfigurationException { String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName + "::" + formName; + VisualTheme visualTheme = UtilHttp.getVisualTheme(request); + String cacheKey = new StringBuilder().append(webappName) + .append("::") + .append(resourceName) + .append("::") + .append(formName) + .append("::") + .append(visualTheme.getVisualThemeId()) + .toString(); ModelForm modelForm = formWebappCache.get(cacheKey); if (modelForm == null) { Delegator delegator = (Delegator) request.getAttribute("delegator"); @@ -87,7 +98,7 @@ public class FormFactory { URL formFileUrl = request.getServletContext().getResource(resourceName); Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true, true); Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); - modelForm = createModelForm(formElement, delegator.getModelReader(), dispatcher.getDispatchContext(), resourceName, formName); + modelForm = createModelForm(formElement, delegator.getModelReader(), visualTheme, dispatcher.getDispatchContext(), resourceName, formName); modelForm = formWebappCache.putIfAbsentAndGet(cacheKey, modelForm); } if (modelForm == null) { @@ -96,7 +107,8 @@ public class FormFactory { return modelForm; } - public static Map<String, ModelForm> readFormDocument(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation) { + public static Map<String, ModelForm> readFormDocument(Document formFileDoc, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext, String formLocation) { Map<String, ModelForm> modelFormMap = new HashMap<>(); if (formFileDoc != null) { // read document and construct ModelForm for each form element @@ -107,10 +119,14 @@ public class FormFactory { List<? extends Element> formElements = UtilXml.childElementList(rootElement, "form"); for (Element formElement : formElements) { String formName = formElement.getAttribute("name"); - String cacheKey = formLocation + "#" + formName; + String cacheKey = new StringBuilder().append(formLocation) + .append("#") + .append(formName) + .append(visualTheme.getVisualThemeId()) + .toString(); ModelForm modelForm = formLocationCache.get(cacheKey); if (modelForm == null) { - modelForm = createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); + modelForm = createModelForm(formElement, entityModelReader, visualTheme, dispatchContext, formLocation, formName); modelForm = formLocationCache.putIfAbsentAndGet(cacheKey, modelForm); } modelFormMap.put(formName, modelForm); @@ -119,20 +135,22 @@ public class FormFactory { return modelFormMap; } - public static ModelForm createModelForm(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { + public static ModelForm createModelForm(Document formFileDoc, ModelReader entityModelReader, VisualTheme visualTheme, + DispatchContext dispatchContext, String formLocation, String formName) { Element rootElement = formFileDoc.getDocumentElement(); if (!"forms".equalsIgnoreCase(rootElement.getTagName())) { rootElement = UtilXml.firstChildElement(rootElement, "forms"); } Element formElement = UtilXml.firstChildElement(rootElement, "form", "name", formName); - return createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); + return createModelForm(formElement, entityModelReader, visualTheme, dispatchContext, formLocation, formName); } - public static ModelForm createModelForm(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { + public static ModelForm createModelForm(Element formElement, ModelReader entityModelReader, VisualTheme visualTheme, + DispatchContext dispatchContext, String formLocation, String formName) { String formType = formElement.getAttribute("type"); if (formType.isEmpty() || "single".equals(formType) || "upload".equals(formType)) { - return new ModelSingleForm(formElement, formLocation, entityModelReader, dispatchContext); + return new ModelSingleForm(formElement, formLocation, entityModelReader, visualTheme, dispatchContext); } - return new ModelGrid(formElement, formLocation, entityModelReader, dispatchContext); + return new ModelGrid(formElement, formLocation, entityModelReader, visualTheme, dispatchContext); } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java index 94350f3..458af2a 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/GridFactory.java @@ -36,6 +36,7 @@ import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.model.ModelReader; import org.apache.ofbiz.service.DispatchContext; import org.apache.ofbiz.service.LocalDispatcher; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; @@ -50,17 +51,19 @@ public class GridFactory { 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) + public static Map<String, ModelGrid> getGridsFromLocation(String resourceName, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) throws IOException, SAXException, ParserConfigurationException { URL gridFileUrl = FlexibleLocation.resolveLocation(resourceName); Document gridFileDoc = UtilXml.readXmlDocument(gridFileUrl, true, true); - return readGridDocument(gridFileDoc, entityModelReader, dispatchContext, resourceName); + return readGridDocument(gridFileDoc, entityModelReader, visualTheme, dispatchContext, resourceName); } - public static ModelGrid getGridFromLocation(String resourceName, String gridName, ModelReader entityModelReader, DispatchContext dispatchContext) + public static ModelGrid getGridFromLocation(String resourceName, String gridName, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) throws IOException, SAXException, ParserConfigurationException { StringBuilder sb = new StringBuilder(dispatchContext.getDelegator().getDelegatorName()); - sb.append(":").append(resourceName).append("#").append(gridName); + sb.append(":").append(resourceName).append("#").append(gridName).append(visualTheme.getVisualThemeId()); String cacheKey = sb.toString(); ModelGrid modelGrid = gridLocationCache.get(cacheKey); if (modelGrid == null) { @@ -69,7 +72,8 @@ public class GridFactory { if (gridFileDoc == null) { throw new IllegalArgumentException("Could not find resource [" + resourceName + "]"); } - modelGrid = createModelGrid(gridFileDoc, entityModelReader, dispatchContext, resourceName, gridName); + modelGrid = createModelGrid(gridFileDoc, entityModelReader, visualTheme, + dispatchContext, resourceName, gridName); modelGrid = gridLocationCache.putIfAbsentAndGet(cacheKey, modelGrid); } if (modelGrid == null) { @@ -81,7 +85,15 @@ public class GridFactory { public static ModelGrid getGridFromWebappContext(String resourceName, String gridName, HttpServletRequest request) throws IOException, SAXException, ParserConfigurationException { String webappName = UtilHttp.getApplicationName(request); - String cacheKey = webappName + "::" + resourceName + "::" + gridName; + VisualTheme visualTheme = UtilHttp.getVisualTheme(request); + String cacheKey = new StringBuilder().append(webappName) + .append("::") + .append(resourceName) + .append("::") + .append(gridName) + .append("::") + .append(visualTheme.getVisualThemeId()) + .toString(); ModelGrid modelGrid = gridWebappCache.get(cacheKey); if (modelGrid == null) { ServletContext servletContext = request.getServletContext(); @@ -90,7 +102,8 @@ public class GridFactory { 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 = createModelGrid(gridElement, delegator.getModelReader(), visualTheme, + dispatcher.getDispatchContext(), resourceName, gridName); modelGrid = gridWebappCache.putIfAbsentAndGet(cacheKey, modelGrid); } if (modelGrid == null) { @@ -99,7 +112,8 @@ public class GridFactory { return modelGrid; } - public static Map<String, ModelGrid> readGridDocument(Document gridFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation) { + public static Map<String, ModelGrid> readGridDocument(Document gridFileDoc, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext, String gridLocation) { Map<String, ModelGrid> modelGridMap = new HashMap<>(); if (gridFileDoc != null) { // read document and construct ModelGrid for each grid element @@ -107,10 +121,15 @@ public class GridFactory { List<? extends Element> gridElements = UtilXml.childElementList(rootElement, "grid"); for (Element gridElement : gridElements) { String gridName = gridElement.getAttribute("name"); - String cacheKey = gridLocation + "#" + gridName; + String cacheKey = new StringBuilder().append(gridLocation) + .append("#") + .append(gridName) + .append(visualTheme.getVisualThemeId()) + .toString(); ModelGrid modelGrid = gridLocationCache.get(cacheKey); if (modelGrid == null) { - modelGrid = createModelGrid(gridElement, entityModelReader, dispatchContext, gridLocation, gridName); + modelGrid = createModelGrid(gridElement, entityModelReader, visualTheme, + dispatchContext, gridLocation, gridName); modelGrid = gridLocationCache.putIfAbsentAndGet(cacheKey, modelGrid); } modelGridMap.put(gridName, modelGrid); @@ -119,16 +138,18 @@ public class GridFactory { return modelGridMap; } - public static ModelGrid createModelGrid(Document gridFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) { + public static ModelGrid createModelGrid(Document gridFileDoc, ModelReader entityModelReader, VisualTheme visualTheme, + 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); + return createModelGrid(gridElement, entityModelReader, visualTheme, dispatchContext, gridLocation, gridName); } - public static ModelGrid createModelGrid(Element gridElement, ModelReader entityModelReader, DispatchContext dispatchContext, String gridLocation, String gridName) { - return new ModelGrid(gridElement, gridLocation, entityModelReader, dispatchContext); + public static ModelGrid createModelGrid(Element gridElement, ModelReader entityModelReader, VisualTheme visualTheme, + DispatchContext dispatchContext, String gridLocation, String gridName) { + return new ModelGrid(gridElement, gridLocation, entityModelReader, visualTheme, dispatchContext); } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java index 7556ee4..e9a139a 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java @@ -51,6 +51,7 @@ import org.apache.ofbiz.service.ModelParam; import org.apache.ofbiz.service.ModelService; import org.apache.ofbiz.widget.WidgetWorker; import org.apache.ofbiz.widget.renderer.FormStringRenderer; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.codehaus.groovy.control.CompilationFailedException; import org.w3c.dom.Element; @@ -193,10 +194,11 @@ public abstract class ModelForm extends ModelWidget { private final Set<String> useWhenFields; /** XML Constructor */ - protected ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext, String defaultType) { + protected ModelForm(Element formElement, String formLocation, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext, String defaultType) { super(formElement); this.formLocation = formLocation; - parentModel = getParentModel(formElement, entityModelReader, dispatchContext); + parentModel = getParentModel(formElement, entityModelReader, visualTheme, dispatchContext); int defaultViewSizeInt = DEFAULT_PAGE_SIZE; String viewSize = formElement.getAttribute("view-size"); if (viewSize.isEmpty()) { @@ -1236,7 +1238,8 @@ public abstract class ModelForm extends ModelWidget { return field; } - protected abstract ModelForm getParentModel(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext); + protected abstract ModelForm getParentModel(Element formElement, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext); public String getParentFormLocation() { return this.parentModel == null ? null : this.parentModel.getFormLocation(); diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java index 2e4968d..7d56524 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormField.java @@ -2318,7 +2318,8 @@ public class ModelFormField { try { org.apache.ofbiz.entity.model.ModelReader entityModelReader = ((org.apache.ofbiz.entity.Delegator)context.get("delegator")).getModelReader(); org.apache.ofbiz.service.DispatchContext dispatchContext = ((org.apache.ofbiz.service.LocalDispatcher)context.get("dispatcher")).getDispatchContext(); - modelForm = FormFactory.getFormFromLocation(location, name, entityModelReader, dispatchContext); + VisualTheme visualTheme = (VisualTheme) context.get("visualTheme"); + modelForm = FormFactory.getFormFromLocation(location, name, entityModelReader, visualTheme, dispatchContext); } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -2399,7 +2400,8 @@ public class ModelFormField { try { org.apache.ofbiz.entity.model.ModelReader entityModelReader = ((org.apache.ofbiz.entity.Delegator)context.get("delegator")).getModelReader(); org.apache.ofbiz.service.DispatchContext dispatchContext = ((org.apache.ofbiz.service.LocalDispatcher)context.get("dispatcher")).getDispatchContext(); - modelForm = GridFactory.getGridFromLocation(location, name, entityModelReader, dispatchContext); + VisualTheme visualTheme = (VisualTheme) context.get("visualTheme"); + modelForm = GridFactory.getGridFromLocation(location, name, entityModelReader, visualTheme, dispatchContext); } catch (RuntimeException e) { throw e; } catch (Exception e) { diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelGrid.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelGrid.java index 712988f..086760e 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelGrid.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelGrid.java @@ -20,10 +20,14 @@ package org.apache.ofbiz.widget.model; import java.util.List; +import java.util.Map; import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilXml; +import org.apache.ofbiz.base.util.string.FlexibleStringExpander; import org.apache.ofbiz.entity.model.ModelReader; import org.apache.ofbiz.service.DispatchContext; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Element; /** @@ -51,8 +55,9 @@ public class ModelGrid extends ModelForm { public static final String module = ModelGrid.class.getName(); /** XML Constructor */ - public ModelGrid(Element formElement, String formLocation, ModelReader entityModelReader, DispatchContext dispatchContext) { - super(formElement, formLocation, entityModelReader, dispatchContext, "list"); + public ModelGrid(Element formElement, String formLocation, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) { + super(formElement, formLocation, entityModelReader, visualTheme, dispatchContext, "list"); } @Override @@ -61,7 +66,8 @@ public class ModelGrid extends ModelForm { } @Override - protected ModelForm getParentModel(Element gridElement, ModelReader entityModelReader, DispatchContext dispatchContext) { + protected ModelForm getParentModel(Element gridElement, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) { ModelForm parentModel = null; String parentResource = gridElement.getAttribute("extends-resource"); String parentGrid = gridElement.getAttribute("extends"); @@ -69,10 +75,15 @@ public class ModelGrid extends ModelForm { // check if we have a resource name if (!parentResource.isEmpty()) { try { - parentModel = GridFactory.getGridFromLocation(parentResource, parentGrid, entityModelReader, dispatchContext); + FlexibleStringExpander parentResourceExp = FlexibleStringExpander.getInstance(parentResource); + Map<String, String> visualRessources = UtilMisc.toMap( + "commonFormLocations", visualTheme.getModelTheme().getModelCommonForms()); + parentResource = parentResourceExp.expandString(visualRessources); + parentModel = GridFactory.getGridFromLocation(parentResource, parentGrid, entityModelReader, + visualTheme, dispatchContext); } catch (Exception e) { - Debug.logError(e, "Failed to load parent grid definition '" + parentGrid + "' at resource '" + parentResource - + "'", module); + Debug.logError(e, "Failed to load parent grid definition '" + parentGrid + + "' at resource '" + parentResource + "'", module); } } else if (!parentGrid.equals(gridElement.getAttribute("name"))) { // try to find a grid definition in the same file @@ -84,8 +95,8 @@ public class ModelGrid extends ModelForm { } for (Element parentElement : gridElements) { if (parentElement.getAttribute("name").equals(parentGrid)) { - parentModel = GridFactory.createModelGrid(parentElement, entityModelReader, dispatchContext, - parentResource, parentGrid); + parentModel = GridFactory.createModelGrid(parentElement, entityModelReader, visualTheme, + dispatchContext, parentResource, parentGrid); break; } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java index 58ec24f..8303948 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelScreenWidget.java @@ -1082,8 +1082,9 @@ public abstract class ModelScreenWidget extends ModelWidget { public ModelForm getModelForm(Map<String, Object> context) throws IOException, SAXException, ParserConfigurationException { String name = this.getName(context); String location = this.getLocation(context); + VisualTheme visualTheme = (VisualTheme) context.get("visualTheme"); return FormFactory.getFormFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), - getModelScreen().getDispatcher(context).getDispatchContext()); + visualTheme, getModelScreen().getDispatcher(context).getDispatchContext()); } public String getName(Map<String, Object> context) { @@ -1169,7 +1170,9 @@ public abstract class ModelScreenWidget extends ModelWidget { String name = this.getName(context); String location = this.getLocation(context); try { - modelForm = GridFactory.getGridFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), getModelScreen().getDispatcher(context).getDispatchContext()); + VisualTheme visualTheme = (VisualTheme) context.get("visualTheme"); + modelForm = GridFactory.getGridFromLocation(location, name, getModelScreen().getDelegator(context).getModelReader(), + visualTheme, getModelScreen().getDispatcher(context).getDispatchContext()); } catch (RuntimeException e) { throw e; } catch (Exception e) { diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelSingleForm.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelSingleForm.java index 197bf17..1b925d0 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelSingleForm.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelSingleForm.java @@ -20,10 +20,14 @@ package org.apache.ofbiz.widget.model; import java.util.List; +import java.util.Map; import org.apache.ofbiz.base.util.Debug; +import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilXml; +import org.apache.ofbiz.base.util.string.FlexibleStringExpander; import org.apache.ofbiz.entity.model.ModelReader; import org.apache.ofbiz.service.DispatchContext; +import org.apache.ofbiz.widget.renderer.VisualTheme; import org.w3c.dom.Element; /** @@ -52,8 +56,8 @@ public class ModelSingleForm extends ModelForm { /** XML Constructor */ public ModelSingleForm(Element formElement, String formLocation, ModelReader entityModelReader, - DispatchContext dispatchContext) { - super(formElement, formLocation, entityModelReader, dispatchContext, "single"); + VisualTheme visualTheme, DispatchContext dispatchContext) { + super(formElement, formLocation, entityModelReader, visualTheme, dispatchContext, "single"); } @Override @@ -62,7 +66,8 @@ public class ModelSingleForm extends ModelForm { } @Override - protected ModelForm getParentModel(Element formElement, ModelReader entityModelReader, DispatchContext dispatchContext) { + protected ModelForm getParentModel(Element formElement, ModelReader entityModelReader, + VisualTheme visualTheme, DispatchContext dispatchContext) { ModelForm parent = null; String parentResource = formElement.getAttribute("extends-resource"); String parentForm = formElement.getAttribute("extends"); @@ -70,7 +75,12 @@ public class ModelSingleForm extends ModelForm { // check if we have a resource name if (!parentResource.isEmpty()) { try { - parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext); + FlexibleStringExpander parentResourceExp = FlexibleStringExpander.getInstance(parentResource); + Map<String, String> visualRessources = UtilMisc.toMap( + "commonFormLocations", visualTheme.getModelTheme().getModelCommonForms()); + parentResource = parentResourceExp.expandString(visualRessources); + parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, + visualTheme, dispatchContext); } catch (Exception e) { Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + "'", module); @@ -83,8 +93,8 @@ public class ModelSingleForm extends ModelForm { //formElements.addAll(UtilXml.childElementList(rootElement, "abstract-form")); for (Element parentElement : formElements) { if (parentElement.getAttribute("name").equals(parentForm)) { - parent = FormFactory.createModelForm(parentElement, entityModelReader, dispatchContext, parentResource, - parentForm); + parent = FormFactory.createModelForm(parentElement, entityModelReader, visualTheme, + dispatchContext, parentResource, parentForm); break; } } |
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit 38f972a0d0c0865b1d6fc5cf7bc71c50b4873355 Author: Nicolas Malin <[hidden email]> AuthorDate: Thu Feb 20 14:49:11 2020 +0100 Improved: Add CommonForms as template pattern configured by theme (OFBIZ-11335) Currently on OFBiz we implemented a process to define some different screen and menu that can be implemented by the theming. But for the form we have nothing. All style are hard coded on each <grid name="ListEntities" ... odd-row-style="alternate-row" default-table-style="basic-table hover-bar"> I extend the theming implementation principle to forms element with adding : * a new xsd element common-forms (like common-screens) * some default form templates to extend : * grid CommonSimpleGrid * grid CommonBasicGrid * form CommonSimpleList * form CommonBasicList * form CommonInLineEditList * form CommonBasicSingle We can use its like : <form name="LayoutDemoList" extends="CommonBasicList" extends-resource="component://common/widget/CommonForms.xml" The main difficulty raise to this task was propage the visualTheme during the ModelForm intanciation, because we need to load wiget style (and some other information wanted on the template) on model load in memory. This is cover by commit 1941a05a349865b8505ec373de3fce3b3a96c2a0. Forms present on the screen https://localhost:8443/webtools/control/WebtoolsLayoutDemo are now extend through with theme. Finally with this we can extend style form (pagination, header, line and so on ...) directly by your theme without change the framework. --- framework/common/groovyScripts/InitTheme.groovy | 1 + framework/common/widget/CommonForms.xml | 40 +++++++++++++++ framework/webtools/widget/MiscForms.xml | 60 ++++++++++++++++++++-- framework/webtools/widget/MiscScreens.xml | 34 ++---------- framework/widget/dtd/widget-theme.xsd | 58 +++++++++++++-------- .../org/apache/ofbiz/widget/model/ModelForm.java | 2 +- .../org/apache/ofbiz/widget/model/ModelTheme.java | 32 +++++++++++- themes/common-theme/widget/CommonForms.xml | 37 +++++++++++++ themes/common-theme/widget/Theme.xml | 10 ++++ 9 files changed, 217 insertions(+), 57 deletions(-) diff --git a/framework/common/groovyScripts/InitTheme.groovy b/framework/common/groovyScripts/InitTheme.groovy index 1481c62..be1afb0 100644 --- a/framework/common/groovyScripts/InitTheme.groovy +++ b/framework/common/groovyScripts/InitTheme.groovy @@ -31,6 +31,7 @@ else visualTheme = ThemeFactory.resolveVisualTheme(context.request?:null) if (visualTheme) { ModelTheme modelTheme = visualTheme.getModelTheme() globalContext.commonScreenLocations = modelTheme.getModelCommonScreens() + globalContext.commonFormLocations = modelTheme.getModelCommonForms() globalContext.visualTheme = visualTheme globalContext.modelTheme = modelTheme diff --git a/framework/common/widget/CommonForms.xml b/framework/common/widget/CommonForms.xml new file mode 100644 index 0000000..9d5bd30 --- /dev/null +++ b/framework/common/widget/CommonForms.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd"> + + <grid name="CommonSimpleGrid" extends="CommonSimpleGrid" extends-resource="${groovy: + commonFormLocations.CommonSimpleGrid ?: 'component://common-theme/widget/CommonForms.xml'}"/> + <grid name="CommonBasicGrid" extends="CommonBasicGrid" extends-resource="${groovy: + commonFormLocations.CommonBasicGrid ?: 'component://common-theme/widget/CommonForms.xml'}"/> + + <form name="CommonSimpleList" extends="CommonSimpleList" extends-resource="${groovy: + commonFormLocations.CommonSimpleList ?: 'component://common-theme/widget/CommonForms.xml'}"/> + <form name="CommonBasicList" extends="CommonBasicList" extends-resource="${groovy: + commonFormLocations.CommonBasicList ?: 'component://common-theme/widget/CommonForms.xml'}"/> + <form name="CommonInLineEditList" extends="CommonInLineEditList" extends-resource="${groovy: + commonFormLocations.CommonInLineEditList ?: 'component://common-theme/widget/CommonForms.xml'}"/> + + <form name="CommonBasicSingle" extends="CommonBasicSingle" extends-resource="${groovy: + commonFormLocations.CommonBasicSingle ?: 'component://common-theme/widget/CommonForms.xml'}"/> + + +</forms> diff --git a/framework/webtools/widget/MiscForms.xml b/framework/webtools/widget/MiscForms.xml index 1d72e5b..22ab232 100644 --- a/framework/webtools/widget/MiscForms.xml +++ b/framework/webtools/widget/MiscForms.xml @@ -20,14 +20,16 @@ under the License. <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd"> - <form name="ProgramExport" type="single" target="ProgramExport" default-map-name="parameters"> + <form name="ProgramExport" extends="CommonBasicSingle" extends-resource="component://common/widget/CommonForms.xml" + target="ProgramExport" default-map-name="parameters"> <field name="groovyProgram" required-field="true"> <textarea cols="120" rows="20" /> </field> <field name="submitButton" title="${uiLabelMap.CommonRun}"><submit button-type="button"/></field> </form> - <form name="LayoutDemoForm" type="single" target="${demoTargetUrl}" default-map-name="demoMap"> + <form name="LayoutDemoForm" extends="CommonBasicSingle" extends-resource="component://common/widget/CommonForms.xml" + target="${demoTargetUrl}" default-map-name="demoMap"> <actions> <set field="numberValue" value="-9.958"/> </actions> @@ -62,8 +64,30 @@ under the License. </field> </form> - <form name="LayoutDemoList" type="list" list-name="demoList" paginate-target="${demoTargetUrl}" separate-columns="true" - odd-row-style="${altRowStyle}" header-row-style="${headerStyle}" default-table-style="${tableStyle}"> + <form name="LayoutDemoList" extends="CommonBasicList" extends-resource="component://common/widget/CommonForms.xml" + list-name="demoList" paginate-target="${demoTargetUrl}"> + <field name="name" title="${uiLabelMap.CommonName}"><display/></field> +<!-- <field name="description" title="${uiLabelMap.CommonDescription}"><text/></field>--> + <field name="dropDown" title="${uiLabelMap.CommonEnabled}"> + <drop-down> + <option key="Y" description="${uiLabelMap.CommonYes}" /> + <option key="N" description="${uiLabelMap.CommonNo}" /> + </drop-down> + </field> +<!-- <field name="checkBox" title="${uiLabelMap.CommonEnabled}">--> +<!-- <check/>--> +<!-- </field>--> +<!-- <field name="radioButton" title="${uiLabelMap.CommonEnabled}">--> +<!-- <radio>--> +<!-- <option key="Y" description="${uiLabelMap.CommonYes}" />--> +<!-- <option key="N" description="${uiLabelMap.CommonNo}" />--> +<!-- </radio>--> +<!-- </field>--> +<!-- <field name="updateButton" widget-style="button-col"><submit/></field>--> + </form> + + <form name="LayoutDemoInLineList" extends="CommonInLineEditList" extends-resource="component://common/widget/CommonForms.xml" + list-name="demoList" paginate-target="${demoTargetUrl}"> <field name="name" title="${uiLabelMap.CommonName}"><display/></field> <field name="description" title="${uiLabelMap.CommonDescription}"><text/></field> <field name="dropDown" title="${uiLabelMap.CommonEnabled}"> @@ -86,4 +110,32 @@ under the License. </field> </form> + <grid name="LayoutDemoSimpleGrid" extends="CommonSimpleGrid" extends-resource="component://common/widget/CommonForms.xml" + list-name="demoList" paginate-target="${demoTargetUrl}"> + <actions> + <set field="numberValue" value="876.543"/> + </actions> + <field name="name" title="${uiLabelMap.CommonName}"><display/></field> + <field name="description" title="${uiLabelMap.CommonDescription}"><display/></field> + <field name="default"><display type="number" description="${numberValue}"/></field> + <field name="quantity"><display type="number" format="quantity" description="${numberValue}"/></field> + <field name="amount"><display type="number" format="amount" description="${numberValue}"/></field> + <field name="spelled"><display type="number" format="spelled-out" description="${numberValue}"/></field> + <field name="percentage"><display type="number" format="percentage" description="${numberValue}"/></field> + <field name="accounting"><display type="number" format="accounting" description="${numberValue}"/></field> + </grid> + <grid name="LayoutDemoBasicGrid" extends="CommonBasicGrid" extends-resource="component://common/widget/CommonForms.xml" + list-name="demoList" paginate-target="${demoTargetUrl}"> + <actions> + <set field="numberValue" value="789.1230"/> + </actions> + <field name="name" title="${uiLabelMap.CommonName}"><display/></field> + <field name="description" title="${uiLabelMap.CommonDescription}"><display/></field> + <field name="default"><display type="number" description="${numberValue}"/></field> + <field name="quantity"><display type="number" format="quantity" description="${numberValue}"/></field> + <field name="amount"><display type="number" format="amount" description="${numberValue}"/></field> + <field name="spelled"><display type="number" format="spelled-out" description="${numberValue}"/></field> + <field name="percentage"><display type="number" format="percentage" description="${numberValue}"/></field> + <field name="accounting"><display type="number" format="accounting" description="${numberValue}"/></field> + </grid> </forms> diff --git a/framework/webtools/widget/MiscScreens.xml b/framework/webtools/widget/MiscScreens.xml index 7c75796..e60abfa 100644 --- a/framework/webtools/widget/MiscScreens.xml +++ b/framework/webtools/widget/MiscScreens.xml @@ -164,24 +164,9 @@ under the License. <section name="Form/List Styles"> <widgets> <horizontal-separator/> - <include-form name="LayoutDemoForm" location="component://webtools/widget/MiscForms.xml"/> - <include-form name="LayoutDemoList" location="component://webtools/widget/MiscForms.xml"/> - <section> - <actions> - <set field="tableStyle" value="basic-table dark-grid"/> - </actions> - <widgets/> - </section> - <include-form name="LayoutDemoList" location="component://webtools/widget/MiscForms.xml"/> - <section> - <actions> - <set field="altRowStyle" value="alternate-row"/> - <set field="headerStyle" value="header-row-2"/> - <set field="tableStyle" value="basic-table hover-bar"/> - </actions> - <widgets/> - </section> + <include-grid name="LayoutDemoSimpleGrid" location="component://webtools/widget/MiscForms.xml"/> <include-form name="LayoutDemoList" location="component://webtools/widget/MiscForms.xml"/> + <include-form name="LayoutDemoInLineList" location="component://webtools/widget/MiscForms.xml"/> </widgets> </section> <section name="Screenlet Styles"> @@ -195,25 +180,14 @@ under the License. <label style="h3" text="${demoText}"/> </screenlet> <screenlet title="${uiLabelMap.WebtoolsLayoutDemo}" id="screenlet-demo" collapsible="true"> - <include-form name="LayoutDemoForm" location="component://webtools/widget/MiscForms.xml"/> + <include-grid name="LayoutDemoSimpleGrid" location="component://webtools/widget/MiscForms.xml"/> </screenlet> <screenlet title="${uiLabelMap.WebtoolsLayoutDemo}" padded="false"> - <section> - <actions> - <set field="altRowStyle" value="alternate-row"/> - <set field="headerStyle" value="header-row-1"/> - <set field="tableStyle" value="basic-table light-grid hover-bar"/> - </actions> - <widgets/> - </section> - <include-form name="LayoutDemoList" location="component://webtools/widget/MiscForms.xml"/> + <include-grid name="LayoutDemoBasicGrid" location="component://webtools/widget/MiscForms.xml"/> </screenlet> <screenlet title="${uiLabelMap.WebtoolsLayoutDemo}" padded="false"> <section> <actions> - <set field="altRowStyle" value="alternate-row"/> - <set field="headerStyle" value="header-row-2"/> - <set field="tableStyle" value="basic-table hover-bar"/> <set field="viewSize" value="1" type="Integer"/> </actions> <widgets/> diff --git a/framework/widget/dtd/widget-theme.xsd b/framework/widget/dtd/widget-theme.xsd index 40fd549..3362cef 100644 --- a/framework/widget/dtd/widget-theme.xsd +++ b/framework/widget/dtd/widget-theme.xsd @@ -27,6 +27,7 @@ under the License. <xs:element minOccurs="0" maxOccurs="1" ref="theme-properties"/> <xs:element minOccurs="0" maxOccurs="1" ref="templates"/> <xs:element minOccurs="0" maxOccurs="1" ref="common-screens"/> + <xs:element minOccurs="0" maxOccurs="1" ref="common-forms"/> <xs:element minOccurs="0" maxOccurs="1" ref="common-menus"/> </xs:sequence> <xs:attribute type="xs:string" name="name" use="required" /> @@ -125,9 +126,9 @@ under the License. </xs:sequence> </xs:complexType> </xs:element> - <xs:annotation><xs:documentation> - This element contains all properties dedicate with the theme technology - </xs:documentation></xs:annotation> + <xs:annotation><xs:documentation> + This element contains all properties dedicate with the theme technology + </xs:documentation></xs:annotation> <xs:element name="property"> <xs:complexType> <xs:attribute type="xs:string" name="name" use="required"> @@ -146,9 +147,9 @@ under the License. </xs:sequence> </xs:complexType> </xs:element> - <xs:annotation><xs:documentation> - This element contains all ftl macro template supported by this theme - </xs:documentation></xs:annotation> + <xs:annotation><xs:documentation> + This element contains all ftl macro template supported by this theme + </xs:documentation></xs:annotation> <xs:element name="template"> <xs:complexType> <xs:sequence> @@ -163,20 +164,20 @@ under the License. </xs:complexType> </xs:element> <xs:element name="template-file"> - <xs:complexType> - <xs:attribute name="widget" use="required" > - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="screen" /> - <xs:enumeration value="form" /> - <xs:enumeration value="tree" /> - <xs:enumeration value="menu" /> - <xs:enumeration value="error" /> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute type="xs:string" name="location" use="required"/> - </xs:complexType> + <xs:complexType> + <xs:attribute name="widget" use="required" > + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="screen" /> + <xs:enumeration value="form" /> + <xs:enumeration value="tree" /> + <xs:enumeration value="menu" /> + <xs:enumeration value="error" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute type="xs:string" name="location" use="required"/> + </xs:complexType> </xs:element> <xs:element name="common-screens"> <xs:annotation><xs:documentation> @@ -190,6 +191,16 @@ under the License. </xs:sequence> </xs:complexType> </xs:element> + <xs:element name="common-forms"> + <xs:annotation><xs:documentation> + List the location of each common forms that the theme implement + </xs:documentation></xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element ref="root-decorator" /> + </xs:sequence> + </xs:complexType> + </xs:element> <xs:element name="common-menus"> <xs:annotation><xs:documentation> List the location of each common menus that the theme implement @@ -204,6 +215,7 @@ under the License. <xs:complexType> <xs:choice> <xs:element maxOccurs="unbounded" ref="screen"/> + <xs:element maxOccurs="unbounded" ref="form"/> <xs:element maxOccurs="unbounded" ref="menu"/> </xs:choice> <xs:attribute type="xs:string" name="default-location" use="optional" /> @@ -231,6 +243,12 @@ under the License. <xs:attribute type="xs:string" name="location" use="optional"/> </xs:complexType> </xs:element> + <xs:element name="form"> + <xs:complexType> + <xs:attribute type="xs:string" name="name" use="required"/> + <xs:attribute type="xs:string" name="location" use="optional"/> + </xs:complexType> + </xs:element> <xs:element name="menu"> <xs:complexType> <xs:attribute type="xs:string" name="name" use="required"/> diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java index e9a139a..5c8d9c9 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelForm.java @@ -1330,7 +1330,7 @@ public abstract class ModelForm extends ModelWidget { } public String getTarget() { - return target.getOriginal(); + return target != null ? target.getOriginal() : null; } /** iterate through altTargets list to see if any should be used, if not return original target diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java index b9e93e2..8230161 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java @@ -74,6 +74,7 @@ public class ModelTheme implements Serializable { //template rendering private final Map<String, ModelTemplate> modelTemplateMap; private final Map<String, String> modelCommonScreensMap; + private final Map<String, String> modelCommonFormsMap; private final Map<String, String> modelCommonMenusMap; /** @@ -87,6 +88,7 @@ public class ModelTheme implements Serializable { Map<String, Object> initThemePropertiesMap = new HashMap<>(); Map<String, ModelTemplate> initModelTemplateMap = new HashMap<>(); Map<String, String> initModelCommonScreensMap = new HashMap<>(); + Map<String, String> initModelCommonFormsMap = new HashMap<>(); Map<String, String> initModelCommonMenusMap = new HashMap<>(); // first resolve value from the origin theme @@ -123,6 +125,9 @@ public class ModelTheme implements Serializable { if (originTheme.modelCommonScreensMap != null) { initModelCommonScreensMap = UtilMisc.makeMapWritable(originTheme.modelCommonScreensMap); } + if (originTheme.modelCommonFormsMap != null) { + initModelCommonFormsMap = UtilMisc.makeMapWritable(originTheme.modelCommonFormsMap); + } if (originTheme.modelCommonMenusMap != null) { initModelCommonMenusMap = UtilMisc.makeMapWritable(originTheme.modelCommonMenusMap); } @@ -173,6 +178,23 @@ public class ModelTheme implements Serializable { } } break; + case "common-forms": + for (Element formPurpose : UtilXml.childElementList(childElement)) { + String defaultLocation = formPurpose.getAttribute("default-location"); + for (Element form : UtilXml.childElementList(formPurpose)) { + String name = form.getAttribute("name"); + String location = form.getAttribute("location"); + if (UtilValidate.isEmpty(location)) { + location = defaultLocation; + } + if (UtilValidate.isEmpty(location)) { + Debug.logWarning("We can resolve the form location " + name + " in the theme " + this.name + " so no added it", module); + continue; + } + initModelCommonFormsMap.put(name, location); + } + } + break; case "common-menus": for (Element menuPurpose : UtilXml.childElementList(childElement)) { String defaultLocation = menuPurpose.getAttribute("default-location"); @@ -209,6 +231,7 @@ public class ModelTheme implements Serializable { this.themePropertiesMap = Collections.unmodifiableMap(initThemePropertiesMap); this.modelTemplateMap = Collections.unmodifiableMap(initModelTemplateMap); this.modelCommonScreensMap = Collections.unmodifiableMap(initModelCommonScreensMap); + this.modelCommonFormsMap = Collections.unmodifiableMap(initModelCommonFormsMap); this.modelCommonMenusMap = Collections.unmodifiableMap(initModelCommonMenusMap); } @@ -401,7 +424,12 @@ public class ModelTheme implements Serializable { public Map<String,String> getModelCommonScreens() { return modelCommonScreensMap; } - public Map<String,String> getModelCommonMenus() { return modelCommonMenusMap; } + public Map<String,String> getModelCommonForms() { + return modelCommonFormsMap; + } + public Map<String,String> getModelCommonMenus() { + return modelCommonMenusMap; + } /** * the ModelTemplate class, manage the complexity of macro library definition and the rendering technology @@ -467,7 +495,7 @@ public class ModelTheme implements Serializable { * @param currentModelTemplate * @param originModelTemplate */ - public ModelTemplate (ModelTemplate currentModelTemplate, ModelTemplate originModelTemplate) { + public ModelTemplate(ModelTemplate currentModelTemplate, ModelTemplate originModelTemplate) { boolean exist = currentModelTemplate != null; this.name = exist ? currentModelTemplate.name : originModelTemplate.name; this.type = exist ? currentModelTemplate.type : originModelTemplate.type; diff --git a/themes/common-theme/widget/CommonForms.xml b/themes/common-theme/widget/CommonForms.xml new file mode 100644 index 0000000..40aace9 --- /dev/null +++ b/themes/common-theme/widget/CommonForms.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd"> + + + <grid name="CommonSimpleGrid" default-table-style="basic-table dark-grid"/> + <grid name="CommonBasicGrid" default-table-style="basic-table hover-bar" + odd-row-style="alternate-row" header-row-style="header-row-2"/> + + <form name="CommonSimpleList" type="list" default-table-style="basic-table dark-grid"/> + <form name="CommonBasicList" type="list" default-table-style="basic-table hover-bar" + odd-row-style="alternate-row" header-row-style="header-row-2"/> + <form name="CommonInLineEditList" type="list" default-table-style="basic-table hover-bar" + odd-row-style="alternate-row" header-row-style="header-row-2" separate-columns="true"/> + + <form name="CommonBasicSingle" type="single"/> + +</forms> diff --git a/themes/common-theme/widget/Theme.xml b/themes/common-theme/widget/Theme.xml index e289532..9ead18d 100644 --- a/themes/common-theme/widget/Theme.xml +++ b/themes/common-theme/widget/Theme.xml @@ -165,6 +165,16 @@ under the License. <screen name="ShowHelp" location="component://common-theme/widget/HelpScreens.xml"/> </generic-screen> </common-screens> + <common-forms><!--list all common form to each application that each theme can be surcharge or not and use the form present on common theme--> + <root-decorator default-location="component://common-theme/widget/CommonForms.xml"> + <form name="CommonSimpleGrid"/> + <form name="CommonBasicGrid"/> + <form name="CommonSimpleList"/> + <form name="CommonBasicList"/> + <form name="CommonInLineEditList"/> + <form name="CommonBasicSingle"/> + </root-decorator> + </common-forms> <common-menus><!--list all common menu to each application that each theme can be surcharge or not and use the menu present on common theme--> <root-decorator default-location="component://common-theme/widget/CommonMenus.xml"> <menu name="CommonAppBarMenu"/> |
In reply to this post by nmalin
This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git commit 296417a7bd0ca8e5472958631813dfee8c0956e8 Author: Nicolas Malin <[hidden email]> AuthorDate: Thu Feb 20 14:50:19 2020 +0100 Fixed: Correct check style issue on ModelTheme --- .../org/apache/ofbiz/widget/model/ModelTheme.java | 46 ++++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java index 8230161..c4bebc5 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelTheme.java @@ -53,7 +53,8 @@ public class ModelTheme implements Serializable { private final Integer autocompleterDefaultViewSize; // Default minimum number of characters an user has to type before the ajax autocompleter activates (jQuery default is 1) private final Integer autocompleterDefaultMinLength; - // Default delay in milliseconds the Autocomplete waits after a keystroke to activate itself. A zero-delay makes sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive. + // Default delay in milliseconds the Autocomplete waits after a keystroke to activate itself. A zero-delay makes + // sense for local data (more responsive), but can produce a lot of load for remote data, while being less responsive. private final Integer autocompleterDefaultDelay; // Show/hide the ID field that is returned from ajax autocompleter private final Boolean autocompleterDisplayReturnField; @@ -329,7 +330,8 @@ public class ModelTheme implements Serializable { try { name.put(initThemePropertiesMap, ObjectType.simpleTypeOrObjectConvert(value, type, null, null)); } catch (GeneralException e) { - Debug.logError("Impossible to parse the value " + value + " to type " + type + " for the property " + name + " on theme " + this.name, module); + Debug.logError("Impossible to parse the value " + value + " to type " + type + + " for the property " + name + " on theme " + this.name, module); } } } @@ -499,20 +501,40 @@ public class ModelTheme implements Serializable { boolean exist = currentModelTemplate != null; this.name = exist ? currentModelTemplate.name : originModelTemplate.name; this.type = exist ? currentModelTemplate.type : originModelTemplate.type; - this.compress = exist && currentModelTemplate.compress != null ? currentModelTemplate.compress : originModelTemplate.compress; - this.encoder = exist && currentModelTemplate.encoder != null ? currentModelTemplate.encoder : originModelTemplate.encoder; - this.contentType = exist && currentModelTemplate.contentType != null ? currentModelTemplate.contentType : originModelTemplate.contentType; - this.encoding = exist && currentModelTemplate.encoding != null ? currentModelTemplate.encoding : originModelTemplate.encoding; - this.screenRendererLocation = exist && currentModelTemplate.screenRendererLocation != null ? currentModelTemplate.screenRendererLocation : originModelTemplate.screenRendererLocation; - this.formRendererLocation = exist && currentModelTemplate.formRendererLocation != null ? currentModelTemplate.formRendererLocation : originModelTemplate.formRendererLocation; - this.treeRendererLocation = exist && currentModelTemplate.treeRendererLocation != null ? currentModelTemplate.treeRendererLocation : originModelTemplate.treeRendererLocation; - this.menuRendererLocation = exist && currentModelTemplate.menuRendererLocation != null ? currentModelTemplate.menuRendererLocation : originModelTemplate.menuRendererLocation; - this.errorTemplateLocation = exist && currentModelTemplate.errorTemplateLocation != null ? currentModelTemplate.errorTemplateLocation : originModelTemplate.errorTemplateLocation; + this.compress = exist && currentModelTemplate.compress != null + ? currentModelTemplate.compress + : originModelTemplate.compress; + this.encoder = exist && currentModelTemplate.encoder != null + ? currentModelTemplate.encoder + : originModelTemplate.encoder; + this.contentType = exist && currentModelTemplate.contentType != null + ? currentModelTemplate.contentType + : originModelTemplate.contentType; + this.encoding = exist && currentModelTemplate.encoding != null + ? currentModelTemplate.encoding + : originModelTemplate.encoding; + this.screenRendererLocation = exist && currentModelTemplate.screenRendererLocation != null + ? currentModelTemplate.screenRendererLocation + : originModelTemplate.screenRendererLocation; + this.formRendererLocation = exist && currentModelTemplate.formRendererLocation != null + ? currentModelTemplate.formRendererLocation + : originModelTemplate.formRendererLocation; + this.treeRendererLocation = exist && currentModelTemplate.treeRendererLocation != null + ? currentModelTemplate.treeRendererLocation + : originModelTemplate.treeRendererLocation; + this.menuRendererLocation = exist && currentModelTemplate.menuRendererLocation != null + ? currentModelTemplate.menuRendererLocation + : originModelTemplate.menuRendererLocation; + this.errorTemplateLocation = exist && currentModelTemplate.errorTemplateLocation != null + ? currentModelTemplate.errorTemplateLocation + : originModelTemplate.errorTemplateLocation; } public String getEncoder() { return encoder; } - public String getType() { return type; } + public String getType() { + return type; + } public String getCompress() { return compress; } |
Free forum by Nabble | Edit this page |