Author: jleroux
Date: Wed Apr 13 15:38:16 2016
New Revision: 1738958

URL: http://svn.apache.org/viewvc?rev=1738958&view=rev
Log:
A combined patch from Adrian's, James Yong's and my work for "Add Support For 
Compound Screen Widget XML Files" - 
https://issues.apache.org/jira/browse/OFBIZ-4090 and "Add Example for Compound 
Screen Widget" - https://issues.apache.org/jira/browse/OFBIZ-6990

Adrian: This adds the ability to include screen widgets, form widgets, menu 
widgets, and simple methods in a single XML file. This approach could be used 
in situations where the widgets share a logical grouping - so they can be kept 
in one place.

James: An example to test out Compound Screen Widget

jlerouxc: here are the changes and tests globally
# As James mentionned we no longer need *-v2.xsd files, I removed them from 
Adrian's patch
# I created a compound-widgets.xsd based on Adrian's and James Yong's previous 
work. From Paul Foxworthy's comment in OFBIZ-4090, I decided to name the root 
compound-widgets (hence the file name). I arranged its elements in another way, 
see below with ExampleCompoundWidgets.xml
# I slightly modified James Yong's ExampleCompoundScreenWidget.xml file and 
renamed it ExampleCompoundWidgets.xml. I added an "s" because there are several 
OFBiz widgets gathered in one place. For the modifications: I simply changed 
the names and arranged the elements in another way which I find better suited. 
I'm used to 1st create the query, then the menus, the screens and their forms. 
We rarely use widget-trees but it's there also. Finally the simple-method at 
end if any. The order is not enforced though, so everybody can use her/his own 
:)
# I added a French label
# I completed the widget-catalog.xml with this new entry and tested locally in 
Eclipse by reloading the XML catalog entries.

I hope I did not miss nor mixed things, the local instance I used is a bit 
overcrowded with pending changes...



Added:
    ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd   (with props)
    
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml   
(with props)
Modified:
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
    ofbiz/trunk/framework/widget/dtd/widget-catalog.xml
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FormFactory.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java
    ofbiz/trunk/specialpurpose/example/config/ExampleUiLabels.xml
    ofbiz/trunk/specialpurpose/example/webapp/example/WEB-INF/controller.xml
    ofbiz/trunk/specialpurpose/example/widget/example/ExampleMenus.xml

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java 
(original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java Wed 
Apr 13 15:38:16 2016
@@ -142,7 +142,12 @@ public final class SimpleMethod extends
         } catch (Exception e) {
             throw new MiniLangException("Could not read SimpleMethod XML 
document [" + xmlURL + "]: ", e);
         }
-        compileAllSimpleMethods(document.getDocumentElement(), simpleMethods, 
xmlURL.toString());
+        Element rootElement = document.getDocumentElement();
+        if (!"simple-methods".equalsIgnoreCase(rootElement.getTagName())) {
+            rootElement = UtilXml.firstChildElement(rootElement, 
"simple-methods");
+        }
+        
+        compileAllSimpleMethods(rootElement, simpleMethods, xmlURL.toString());
         if (MiniLangUtil.isDocumentAutoCorrected(document)) {
             MiniLangUtil.writeMiniLangDocument(xmlURL, document);
         }

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
Wed Apr 13 15:38:16 2016
@@ -159,6 +159,9 @@ public class ConfigXMLReader {
         try {
             Document document = UtilXml.readXmlDocument(location, true);
             Element rootElement = document.getDocumentElement();
+            if (!"site-conf".equalsIgnoreCase(rootElement.getTagName())) {
+                rootElement = UtilXml.firstChildElement(rootElement, 
"site-conf");
+            }
             if (Debug.verboseOn())
                 Debug.logVerbose("Loaded XML Config - " + location, module);
             return rootElement;

Added: ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd?rev=1738958&view=auto
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd (added)
+++ ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd Wed Apr 13 15:38:16 
2016
@@ -0,0 +1,15 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+           elementFormDefault="qualified">
+    <xs:element name="compound-widgets">
+        <xs:complexType>
+            <xs:all minOccurs="0" maxOccurs="1">
+                <xs:element name="site-conf"/>
+                <xs:element name="menus"/>
+                <xs:element name="screens"/>
+                <xs:element name="trees"/>
+                <xs:element name="forms"/>
+                <xs:element name="simple-methods"/>
+            </xs:all>
+        </xs:complexType>
+    </xs:element>
+</xs:schema>
\ No newline at end of file

Propchange: ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xsd

Modified: ofbiz/trunk/framework/widget/dtd/widget-catalog.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-catalog.xml?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-catalog.xml (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-catalog.xml Wed Apr 13 15:38:16 2016
@@ -31,4 +31,5 @@ under the License.
   <system systemId="http://ofbiz.apache.org/dtds/widget-menu.xsd"; 
uri="widget-menu.xsd"/>
   <system systemId="http://ofbiz.apache.org/dtds/widget-screen.xsd"; 
uri="widget-screen.xsd"/>
   <system systemId="http://ofbiz.apache.org/dtds/widget-tree.xsd"; 
uri="widget-tree.xsd"/>
+  <system systemId="http://ofbiz.apache.org/dtds/compound-widgets.xsd"; 
uri="compound-widgets.xsd"/>
 </catalog>

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=1738958&r1=1738957&r2=1738958&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 
Wed Apr 13 15:38:16 2016
@@ -103,6 +103,9 @@ public class FormFactory {
         if (formFileDoc != null) {
             // read document and construct ModelForm for each form element
             Element rootElement = formFileDoc.getDocumentElement();
+            if (!"forms".equalsIgnoreCase(rootElement.getTagName())) {
+                rootElement = UtilXml.firstChildElement(rootElement, "forms");
+            }
             List<? extends Element> formElements = 
UtilXml.childElementList(rootElement, "form");
             for (Element formElement : formElements) {
                 String formName = formElement.getAttribute("name");
@@ -119,7 +122,11 @@ public class FormFactory {
     }
 
     public static ModelForm createModelForm(Document formFileDoc, ModelReader 
entityModelReader, DispatchContext dispatchContext, String formLocation, String 
formName) {
-        Element formElement = 
UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", 
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);
     }
 

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java 
Wed Apr 13 15:38:16 2016
@@ -79,6 +79,9 @@ public class MenuFactory {
         if (menuFileDoc != null) {
             // read document and construct ModelMenu for each menu element
             Element rootElement = menuFileDoc.getDocumentElement();
+            if (!"menus".equalsIgnoreCase(rootElement.getTagName())) {
+                rootElement = UtilXml.firstChildElement(rootElement, "menus");
+            }
             for (Element menuElement: UtilXml.childElementList(rootElement, 
"menu")){
                 ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation);
                 modelMenuMap.put(modelMenu.getName(), modelMenu);

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java 
Wed Apr 13 15:38:16 2016
@@ -166,6 +166,9 @@ public class ScreenFactory {
         if (screenFileDoc != null) {
             // read document and construct ModelScreen for each screen element
             Element rootElement = screenFileDoc.getDocumentElement();
+            if (!"screens".equalsIgnoreCase(rootElement.getTagName())) {
+                rootElement = UtilXml.firstChildElement(rootElement, 
"screens");
+            }
             List<? extends Element> screenElements = 
UtilXml.childElementList(rootElement, "screen");
             for (Element screenElement: screenElements) {
                 ModelScreen modelScreen = new ModelScreen(screenElement, 
modelScreenMap, sourceLocation);

Modified: ofbiz/trunk/specialpurpose/example/config/ExampleUiLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/example/config/ExampleUiLabels.xml?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/example/config/ExampleUiLabels.xml (original)
+++ ofbiz/trunk/specialpurpose/example/config/ExampleUiLabels.xml Wed Apr 13 
15:38:16 2016
@@ -137,6 +137,10 @@
         <value xml:lang="fr">Graphes</value>
         <value xml:lang="zh">绘图样例</value>
     </property>
+    <property key="ExampleCompoundWidgets">
+        <value xml:lang="en">Compound Screen Widget</value>
+        <value xml:lang="fr">Screen Widget composé</value>
+    </property>
     <property key="ExampleDashboard">
         <value xml:lang="en">Dashboard</value>
         <value xml:lang="fr">Personnalisation des pages</value>

Modified: 
ofbiz/trunk/specialpurpose/example/webapp/example/WEB-INF/controller.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/example/webapp/example/WEB-INF/controller.xml?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/example/webapp/example/WEB-INF/controller.xml 
(original)
+++ ofbiz/trunk/specialpurpose/example/webapp/example/WEB-INF/controller.xml 
Wed Apr 13 15:38:16 2016
@@ -25,6 +25,7 @@ under the License.
          elements found in the common-controller.xml file. -->
     <include 
location="component://common/webcommon/WEB-INF/common-controller.xml"/>
     <include 
location="component://common/webcommon/WEB-INF/portal-controller.xml"/>
+    <include 
location="component://example/widget/example/ExampleCompoundWidgets.xml"/>
 
     <description>Example Component Site Configuration File</description>
 

Added: 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml?rev=1738958&view=auto
==============================================================================
--- 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml 
(added)
+++ 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml 
Wed Apr 13 15:38:16 2016
@@ -0,0 +1,115 @@
+<?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.
+-->
+
+<!-- This document serves as an example for Compound Screen Widget feature -->
+<compound-widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/compound-widgets.xsd";>
+
+    <site-conf xmlns="http://ofbiz.apache.org/Site-Conf"; 
xsi:schemaLocation="http://ofbiz.apache.org/Site-Conf 
http://ofbiz.apache.org/dtds/site-conf.xsd";>
+        <request-map uri="CompoundWidgets1">
+            <security https="true" auth="true"/>
+            <event type="simple" invoke="CompoundWidgetsFunc" 
path="component://example/widget/example/ExampleCompoundWidgets.xml"/>
+            <response name="success" type="view" value="CompoundWidgets1"/>
+        </request-map>
+        <request-map uri="CompoundWidgets2"><security https="true" 
auth="true"/><response name="success" type="view" 
value="CompoundWidgets2"/></request-map>
+        
+        <view-map name="CompoundWidgets1" type="screen" 
page="component://example/widget/example/ExampleCompoundWidgets.xml#CompoundWidgets1"/>
+        <view-map name="CompoundWidgets2" type="screen" 
page="component://example/widget/example/ExampleCompoundWidgets.xml#CompoundWidgets2"/>
+    </site-conf>
+
+    <menus xmlns="http://ofbiz.apache.org/Widget-Menu"; 
xsi:schemaLocation="http://ofbiz.apache.org/Widget-Menu 
http://ofbiz.apache.org/dtds/widget-menu.xsd";>
+        <menu name="CompoundWidgetsMenu" extends="CommonTabBarMenu" 
extends-resource="component://common/widget/CommonMenus.xml">
+            <menu-item name="Example1" title="${uiLabelMap.ExampleExample} 1">
+                <link target="CompoundWidgets1"/>
+            </menu-item>
+            <menu-item name="Example2" title="${uiLabelMap.ExampleExample} 2">
+                <link target="CompoundWidgets2"/>
+            </menu-item>
+        </menu>
+    </menus>
+
+    <screens xmlns="http://ofbiz.apache.org/Widget-Screen"; 
xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen 
http://ofbiz.apache.org/dtds/widget-screen.xsd";>
+        <screen name="CompoundWidgets1">
+            <section>
+                <actions>
+                    <set field="headerItem" value="ExampleCompoundWidgets" />
+                    <set field="tabButtonItem" value="Example1"/>
+                </actions>
+                <widgets>
+                    <decorator-screen name="main-decorator" 
location="${parameters.mainDecoratorLocation}">
+                        <decorator-section name="pre-body">
+                            <include-menu name="CompoundWidgetsMenu" 
location="component://example/widget/example/ExampleCompoundWidgets.xml" />
+                        </decorator-section>
+                        <decorator-section name="body">
+                            <section>
+                                <widgets>
+                                    <container style="clear" />
+                                    <label>Demo For Compound Screen 
Widget</label>
+                                    <include-form 
location="component://example/widget/example/ExampleCompoundWidgets.xml" 
name="CompoundWidgetsForm1"/>
+                                </widgets>
+                            </section>
+                        </decorator-section>
+                    </decorator-screen>
+                </widgets>
+            </section>
+        </screen>
+        
+        <screen name="CompoundWidgets2">
+            <section>
+                <actions>
+                    <set field="headerItem" value="ExampleCompoundWidgets" />
+                    <set field="tabButtonItem" value="Example2"/>
+                </actions>
+                <widgets>
+                    <decorator-screen name="main-decorator" 
location="${parameters.mainDecoratorLocation}">
+                        <decorator-section name="pre-body">
+                            <include-menu name="CompoundWidgetsMenu" 
location="component://example/widget/example/ExampleCompoundWidgets.xml" />
+                        </decorator-section>
+                        <decorator-section name="body">
+                            <section>
+                                <widgets>
+                                    <container style="clear" />
+                                    <label>Demo For Compound Screen 
Widget</label>
+                                    <include-form 
location="component://example/widget/example/ExampleCompoundWidgets.xml" 
name="CompoundWidgetsForm2"/>
+                                </widgets>
+                            </section>
+                        </decorator-section>
+                    </decorator-screen>
+                </widgets>
+            </section>
+        </screen>
+    </screens>
+
+    <forms 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="CompoundWidgetsForm1">
+            <field name="exampleName" 
title="${uiLabelMap.FormFieldTitle_exampleName} 1" required-field="true"><text 
/></field>
+        </form>
+        
+        <form name="CompoundWidgetsForm2">
+            <field name="exampleName" 
title="${uiLabelMap.FormFieldTitle_exampleName} 2" required-field="true"><text 
/></field>
+        </form>
+    </forms>
+
+    <simple-methods xmlns="http://ofbiz.apache.org/Simple-Method"; 
xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method 
http://ofbiz.apache.org/dtds/simple-methods.xsd";>
+        <simple-method method-name="CompoundWidgetsFunc">
+            <log message="CompoundWidgetsFunc runs" level="info"/>
+        </simple-method>
+    </simple-methods>
+
+</compound-widgets>

Propchange: 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: 
ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: ofbiz/trunk/specialpurpose/example/widget/example/ExampleMenus.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/example/widget/example/ExampleMenus.xml?rev=1738958&r1=1738957&r2=1738958&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/example/widget/example/ExampleMenus.xml 
(original)
+++ ofbiz/trunk/specialpurpose/example/widget/example/ExampleMenus.xml Wed Apr 
13 15:38:16 2016
@@ -48,6 +48,9 @@ under the License.
         <menu-item name="ExampleCompleteFop" 
title="${uiLabelMap.ContentFopFonts}">
                 <link target="fonts.pdf"/>
         </menu-item>
+        <menu-item name="ExampleCompoundWidgets" 
title="${uiLabelMap.ExampleCompoundWidgets}">
+                <link target="CompoundWidgets1"/>
+        </menu-item>
     </menu>
 
     <menu name="EditExample" extends="CommonTabBarMenu" 
extends-resource="component://common/widget/CommonMenus.xml">


Reply via email to