svn commit: r639342 - in /ofbiz/trunk/framework: webtools/src/org/ofbiz/webtools/artifactinfo/ widget/src/org/ofbiz/widget/screen/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r639342 - in /ofbiz/trunk/framework: webtools/src/org/ofbiz/webtools/artifactinfo/ widget/src/org/ofbiz/widget/screen/

jacopoc
Author: jacopoc
Date: Thu Mar 20 09:17:48 2008
New Revision: 639342

URL: http://svn.apache.org/viewvc?rev=639342&view=rev
Log:
Implemented artifact information about forms included in screens.

Modified:
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java

Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java?rev=639342&r1=639341&r2=639342&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java Thu Mar 20 09:17:48 2008
@@ -243,6 +243,9 @@
         return this.getDispatchContext().getModelService(serviceName);
     }
     
+    public ModelForm getModelForm(String formNameAndLocation) throws ParserConfigurationException, SAXException, IOException {
+        return getModelForm(formNameAndLocation.substring(0, formNameAndLocation.indexOf("#")), formNameAndLocation.substring(formNameAndLocation.indexOf("#")));
+    }
     public ModelForm getModelForm(String formName, String formLocation) throws ParserConfigurationException, SAXException, IOException {
         return FormFactory.getFormFromLocation(formLocation, formName, this.entityModelReader, this.dispatchContext);
     }
@@ -290,6 +293,9 @@
         return curInfo;
     }
     
+    public FormWidgetArtifactInfo getFormWidgetArtifactInfo(String formNameAndLocation) throws GeneralException {
+        return getFormWidgetArtifactInfo(formNameAndLocation.substring(0, formNameAndLocation.indexOf("#")), formNameAndLocation.substring(formNameAndLocation.indexOf("#")));
+    }
     public FormWidgetArtifactInfo getFormWidgetArtifactInfo(String formName, String formLocation) throws GeneralException {
         FormWidgetArtifactInfo curInfo = this.allFormInfos.get(formLocation + "#" + formName);
         if (curInfo == null) {

Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java?rev=639342&r1=639341&r2=639342&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ScreenWidgetArtifactInfo.java Thu Mar 20 09:17:48 2008
@@ -29,6 +29,7 @@
 import org.ofbiz.base.util.GeneralException;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.widget.form.ModelForm;
 import org.ofbiz.widget.screen.ModelScreen;
 import org.xml.sax.SAXException;
 
@@ -45,6 +46,7 @@
     
     Set<EntityArtifactInfo> entitiesUsedInThisScreen = FastSet.newInstance();
     Set<ServiceArtifactInfo> servicesUsedInThisScreen = FastSet.newInstance();
+    Set<FormWidgetArtifactInfo> formsIncludedInThisScreen = FastSet.newInstance();
     
     public ScreenWidgetArtifactInfo(String screenName, String screenLocation, ArtifactInfoFactory aif) throws GeneralException {
         super(aif);
@@ -67,6 +69,7 @@
     public void populateAll() throws GeneralException {
         this.populateUsedEntities();
         this.populateUsedServices();
+        this.populateIncludedForms();
     }
     protected void populateUsedServices() throws GeneralException {
         // populate servicesUsedInThisScreen and for each the reverse-associate cache in the aif
@@ -112,6 +115,30 @@
             UtilMisc.addToSetInMap(this, aif.allScreenInfosReferringToEntityName, entityName);
         }
     }
+    protected void populateIncludedForms() throws GeneralException {
+        // populate servicesUsedInThisScreen and for each the reverse-associate cache in the aif
+        Set<String> allFormNameSet = this.modelScreen.getAllFormNamesIncluded();
+        populateFormsFromNameSet(allFormNameSet);
+    }
+    protected void populateFormsFromNameSet(Set<String> allFormNameSet) throws GeneralException {
+        for (String formName: allFormNameSet) {
+            if (formName.contains("${")) {
+                continue;
+            }
+
+            try {
+                ModelForm modelForm = aif.getModelForm(formName);
+            } catch(Exception e) {
+                Debug.logWarning("Form [" + formName + "] reference in screen [" + this.screenName + "] in resource [" + this.screenLocation + "] does not exist!", module);
+                continue;
+            }
+            
+            // the forward reference
+            this.formsIncludedInThisScreen.add(aif.getFormWidgetArtifactInfo(formName));
+            // the reverse reference
+            UtilMisc.addToSetInMap(this, aif.allScreenInfosReferringToEntityName, formName);
+        }
+    }
 
     public String getDisplayName() {
         return this.getUniqueId();
@@ -151,8 +178,7 @@
     }
     
     public Set<FormWidgetArtifactInfo> getFormsIncludedInScreen() {
-        // TODO: implement this
-        return FastSet.newInstance();
+        return this.formsIncludedInThisScreen;
     }
     
     public Set<ScreenWidgetArtifactInfo> getScreensIncludedInScreen() {

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java?rev=639342&r1=639341&r2=639342&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Thu Mar 20 09:17:48 2008
@@ -20,6 +20,7 @@
 
 import java.io.Serializable;
 import java.io.Writer;
+import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
 
@@ -116,6 +117,58 @@
             for (ModelScreenWidget widget: currentSection.failWidgets) {
                 if (widget instanceof ModelScreenWidget.Section) {
                     findEntityNamesUsedInSection((ModelScreenWidget.Section)widget, allEntityNamesUsed);
+                }
+            }
+        }
+    }
+    public Set<String> getAllFormNamesIncluded() {
+        Set<String> allFormNamesIncluded = FastSet.newInstance();
+        findFormNamesIncludedInWidget(this.section, allFormNamesIncluded);
+        return allFormNamesIncluded;
+    }
+    protected static void findFormNamesIncludedInWidget(ModelScreenWidget currentWidget, Set<String> allFormNamesIncluded) {
+        if (currentWidget instanceof ModelScreenWidget.Form) {
+            ModelScreenWidget.Form form = (ModelScreenWidget.Form)currentWidget;
+            allFormNamesIncluded.add(form.locationExdr.getOriginal() + "#" + form.nameExdr.getOriginal());
+        } else if (currentWidget instanceof ModelScreenWidget.Section) {
+            ModelScreenWidget.Section section = (ModelScreenWidget.Section)currentWidget;
+            if (section.subWidgets != null) {
+                for (ModelScreenWidget widget: section.subWidgets) {
+                    findFormNamesIncludedInWidget(widget, allFormNamesIncluded);
+                }
+            }
+            if (section.failWidgets != null) {
+                for (ModelScreenWidget widget: section.failWidgets) {
+                    findFormNamesIncludedInWidget(widget, allFormNamesIncluded);
+                }
+            }
+        } else if (currentWidget instanceof ModelScreenWidget.DecoratorSection) {
+            ModelScreenWidget.DecoratorSection decoratorSection = (ModelScreenWidget.DecoratorSection)currentWidget;
+            if (decoratorSection.subWidgets != null) {
+                for (ModelScreenWidget widget: decoratorSection.subWidgets) {
+                    findFormNamesIncludedInWidget(widget, allFormNamesIncluded);
+                }
+            }
+        } else if (currentWidget instanceof ModelScreenWidget.DecoratorScreen) {
+            ModelScreenWidget.DecoratorScreen decoratorScreen = (ModelScreenWidget.DecoratorScreen)currentWidget;
+            if (decoratorScreen.sectionMap != null) {
+                Collection<ModelScreenWidget.DecoratorSection> sections = decoratorScreen.sectionMap.values();
+                for (ModelScreenWidget section: sections) {
+                    findFormNamesIncludedInWidget(section, allFormNamesIncluded);
+                }
+            }
+        } else if (currentWidget instanceof ModelScreenWidget.Container) {
+            ModelScreenWidget.Container container = (ModelScreenWidget.Container)currentWidget;
+            if (container.subWidgets != null) {
+                for (ModelScreenWidget widget: container.subWidgets) {
+                    findFormNamesIncludedInWidget(widget, allFormNamesIncluded);
+                }
+            }
+        } else if (currentWidget instanceof ModelScreenWidget.Screenlet) {
+            ModelScreenWidget.Screenlet screenlet = (ModelScreenWidget.Screenlet)currentWidget;
+            if (screenlet.subWidgets != null) {
+                for (ModelScreenWidget widget: screenlet.subWidgets) {
+                    findFormNamesIncludedInWidget(widget, allFormNamesIncluded);
                 }
             }
         }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=639342&r1=639341&r2=639342&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Thu Mar 20 09:17:48 2008
@@ -289,7 +289,7 @@
     public static class Container extends ModelScreenWidget {
         protected FlexibleStringExpander idExdr;
         protected FlexibleStringExpander styleExdr;
-        protected List subWidgets;
+        protected List<ModelScreenWidget> subWidgets;
         
         public Container(ModelScreen modelScreen, Element containerElement) {
             super(modelScreen, containerElement);
@@ -551,7 +551,7 @@
     public static class DecoratorScreen extends ModelScreenWidget {
         protected FlexibleStringExpander nameExdr;
         protected FlexibleStringExpander locationExdr;
-        protected Map sectionMap = new HashMap();
+        protected Map<String, DecoratorSection> sectionMap = new HashMap();
         
         public DecoratorScreen(ModelScreen modelScreen, Element decoratorScreenElement) {
             super(modelScreen, decoratorScreenElement);
@@ -636,7 +636,7 @@
     }
 
     public static class DecoratorSection extends ModelScreenWidget {
-        protected List subWidgets;
+        protected List<ModelScreenWidget> subWidgets;
         
         public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) {
             super(modelScreen, decoratorSectionElement);