svn commit: r639458 - in /ofbiz/trunk/framework: webtools/src/org/ofbiz/webtools/artifactinfo/ webtools/webapp/webtools/artifactinfo/ widget/src/org/ofbiz/widget/form/

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

svn commit: r639458 - in /ofbiz/trunk/framework: webtools/src/org/ofbiz/webtools/artifactinfo/ webtools/webapp/webtools/artifactinfo/ widget/src/org/ofbiz/widget/form/

jacopoc
Author: jacopoc
Date: Thu Mar 20 14:07:46 2008
New Revision: 639458

URL: http://svn.apache.org/viewvc?rev=639458&view=rev
Log:
Implemented artifact information about entities used by forms.

Modified:
    ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
    ofbiz/trunk/framework/webtools/webapp/webtools/artifactinfo/ArtifactInfo.ftl
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java

Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java?rev=639458&r1=639457&r2=639458&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java (original)
+++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java Thu Mar 20 14:07:46 2008
@@ -25,7 +25,10 @@
 
 import javolution.util.FastSet;
 
+import org.ofbiz.base.util.Debug;
 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.xml.sax.SAXException;
 
@@ -33,7 +36,8 @@
  *
  */
 public class FormWidgetArtifactInfo extends ArtifactInfoBase {
-    
+    public static final String module = FormWidgetArtifactInfo.class.getName();
+
     protected ModelForm modelForm;
     
     protected String formName;
@@ -59,8 +63,54 @@
     }
     
     /** note this is mean to be called after the object is created and added to the ArtifactInfoFactory.allFormInfos in ArtifactInfoFactory.getFormWidgetArtifactInfo */
-    public void populateAll() {
+    public void populateAll() throws GeneralException {
         // TODO: populate entitiesUsedInThisForm, servicesUsedInThisForm, formThisFormExtends (and reverse in aif.allFormInfosExtendingForm)
+        this.populateUsedEntities();
+        //this.populateUsedServices();
+    }
+    protected void populateUsedEntities() throws GeneralException {
+        // populate entitiesUsedInThisForm and for each the reverse-associate cache in the aif
+        Set<String> allEntityNameSet = this.modelForm.getAllEntityNamesUsed();
+        populateEntitiesFromNameSet(allEntityNameSet);
+    }
+    protected void populateEntitiesFromNameSet(Set<String> allEntityNameSet) throws GeneralException {
+        for (String entityName: allEntityNameSet) {
+            if (entityName.contains("${")) {
+                continue;
+            }
+            if (!aif.getEntityModelReader().getEntityNames().contains(entityName)) {
+                Debug.logWarning("Entity [" + entityName + "] reference in form [" + this.formName + "] in resource [" + this.formLocation + "] does not exist!", module);
+                continue;
+            }
+            
+            // the forward reference
+            this.entitiesUsedInThisForm.add(aif.getEntityArtifactInfo(entityName));
+            // the reverse reference
+            UtilMisc.addToSetInMap(this, aif.allFormInfosReferringToEntityName, entityName);
+        }
+    }
+    protected void populateUsedServices() throws GeneralException {
+        // populate servicesUsedInThisForm and for each the reverse-associate cache in the aif
+        Set<String> allServiceNameSet = null;//TODO JACOPOthis.modelScreen.getAllServiceNamesUsed();
+        populateServicesFromNameSet(allServiceNameSet);
+    }
+    protected void populateServicesFromNameSet(Set<String> allServiceNameSet) throws GeneralException {
+        for (String serviceName: allServiceNameSet) {
+            if (serviceName.contains("${")) {
+                continue;
+            }
+            try {
+                ModelService modelService = aif.getModelService(serviceName);
+            } catch(GeneralException e) {
+                Debug.logWarning("Service [" + serviceName + "] reference in form [" + this.formName + "] in resource [" + this.formLocation + "] does not exist!", module);
+                continue;
+            }
+            
+            // the forward reference
+            this.servicesUsedInThisForm.add(aif.getServiceArtifactInfo(serviceName));
+            // the reverse reference
+            UtilMisc.addToSetInMap(this, aif.allFormInfosReferringToServiceName, serviceName);
+        }
     }
     
     public String getDisplayName() {

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/artifactinfo/ArtifactInfo.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/artifactinfo/ArtifactInfo.ftl?rev=639458&r1=639457&r2=639458&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/artifactinfo/ArtifactInfo.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/artifactinfo/ArtifactInfo.ftl Thu Mar 20 14:07:46 2008
@@ -149,7 +149,30 @@
         </#list>
         
     <#elseif artifactInfo.getType() == "form"/>
-        <#-- TODO: add these once defined! -->
+        <h2>Form Extended by This Form</h2>
+        <#if artifactInfo.getFormThisFormExtends()?exists>
+            <@displayFormWidgetArtifactInfo formWidgetArtifactInfo=artifactInfo.getFormThisFormExtends/>
+        </#if>
+
+        <h2>Entities Used in This Form</h2>
+        <#list artifactInfo.getEntitiesUsedInForm()?if_exists as entityArtifactInfo>
+            <@displayEntityArtifactInfo entityArtifactInfo=entityArtifactInfo/>
+        </#list>
+    
+        <h2>Services Used in This Form</h2>
+        <#list artifactInfo.getServicesUsedInForm()?if_exists as serviceArtifactInfo>
+            <@displayServiceArtifactInfo serviceArtifactInfo=serviceArtifactInfo/>
+        </#list>
+
+        <h2>Screens Including This Form</h2>
+        <#list artifactInfo.getScreensIncludingThisForm()?if_exists as screenWidgetArtifactInfo>
+            <@displayScreenWidgetArtifactInfo screenWidgetArtifactInfo=screenWidgetArtifactInfo/>
+        </#list>
+
+        <h2>Forms Extending This Form</h2>
+        <#list artifactInfo.getFormsExtendingThisForm()?if_exists as formWidgetArtifactInfo>
+            <@displayFormWidgetArtifactInfo formWidgetArtifactInfo=formWidgetArtifactInfo/>
+        </#list>
     
     <#elseif artifactInfo.getType() == "screen"/>
         <h2>Entities Used in This Screen</h2>
@@ -171,6 +194,7 @@
         <#list artifactInfo.getScreensIncludedInScreen()?if_exists as screenWidgetArtifactInfo>
             <@displayScreenWidgetArtifactInfo screenWidgetArtifactInfo=screenWidgetArtifactInfo/>
         </#list>
+
         <h2>Screens Including This Screen</h2>
         <#list artifactInfo.getScreensIncludingThisScreen()?if_exists as screenWidgetArtifactInfo>
             <@displayScreenWidgetArtifactInfo screenWidgetArtifactInfo=screenWidgetArtifactInfo/>

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=639458&r1=639457&r2=639458&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Thu Mar 20 14:07:46 2008
@@ -35,6 +35,7 @@
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
+import javolution.util.FastSet;
 
 import bsh.EvalError;
 import bsh.Interpreter;
@@ -73,6 +74,8 @@
     protected DispatchContext dispatchContext;
 
     protected String formLocation;
+    protected String parentFormName;
+    protected String parentFormLocation;
     protected String type;
     protected FlexibleStringExpander target;
     protected String targetType;
@@ -120,8 +123,8 @@
     protected boolean clientAutocompleteFields = true;
 
     protected List altTargets = new LinkedList();
-    protected List autoFieldsServices = new LinkedList();
-    protected List autoFieldsEntities = new LinkedList();
+    protected List<AutoFieldsService> autoFieldsServices = new LinkedList();
+    protected List<AutoFieldsEntity> autoFieldsEntities = new LinkedList();
     protected List sortOrderFields = new LinkedList();
 
     /** This List will contain one copy of each field for each field name in the order
@@ -133,7 +136,7 @@
      * necessary to use the Map. The Map is used when loading the form definition to keep the
      * list clean and implement the override features for field definitions.
      */
-    protected List fieldList = new LinkedList();
+    protected List<ModelFormField> fieldList = new LinkedList();
 
     /** This Map is keyed with the field name and has a ModelFormField for the value; fields
      * with conditions will not be put in this Map so field definition overrides for fields
@@ -174,8 +177,8 @@
     public static String DEFAULT_PAG_NEXT_STYLE = "nav-next";
     public static String DEFAULT_PAG_LAST_STYLE = "nav-last";
     
-    protected List actions;
-    protected List rowActions;
+    protected List<ModelFormAction> actions;
+    protected List<ModelFormAction> rowActions;
     protected FlexibleStringExpander rowCountExdr;
     protected List multiSubmitFields = FastList.newInstance();
     protected int rowCount = 0;
@@ -208,6 +211,8 @@
             if (parentResource.length() > 0) {
                 try {
                     parent = FormFactory.getFormFromLocation(parentResource, parentForm, entityModelReader, dispatchContext);
+                    this.parentFormName = parentForm;
+                    this.parentFormLocation = parentResource;
                 } catch (Exception e) {
                     Debug.logError(e, "Failed to load parent form definition '" + parentForm + "' at resource '" + parentResource + "'", module);
                 }
@@ -227,6 +232,9 @@
                 }
                 if (parent == null) {
                     Debug.logError("Failed to find parent form definition '" + parentForm + "' in same document.", module);
+                } else {
+                    this.parentFormName = parentForm;
+                    this.parentFormLocation = this.formLocation;
                 }
             } else {
                 Debug.logError("Recursive form definition found for '" + formElement.getAttribute("name") + ".'", module);
@@ -2657,5 +2665,51 @@
         public void renderString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) {
             formStringRenderer.renderBanner(buffer, context, this);
         }
+    }
+
+    public Set<String> getAllEntityNamesUsed() {
+        Set<String> allEntityNamesUsed = FastSet.newInstance();
+        for (AutoFieldsEntity autoFieldsEntity: this.autoFieldsEntities) {
+            allEntityNamesUsed.add(autoFieldsEntity.entityName);
+        }
+        if (this.actions != null) {
+            for (ModelFormAction modelFormAction: this.actions) {
+                if (modelFormAction instanceof ModelFormAction.EntityOne) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
+                } else if (modelFormAction instanceof ModelFormAction.EntityAnd) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
+                } else if (modelFormAction instanceof ModelFormAction.EntityCondition) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
+                }
+
+            }
+        }
+        if (this.rowActions != null) {
+            for (ModelFormAction modelFormAction: this.rowActions) {
+                if (modelFormAction instanceof ModelFormAction.EntityOne) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityOne)modelFormAction).finder.getEntityName());
+                } else if (modelFormAction instanceof ModelFormAction.EntityAnd) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityAnd)modelFormAction).finder.getEntityName());
+                } else if (modelFormAction instanceof ModelFormAction.EntityCondition) {
+                    allEntityNamesUsed.add(((ModelFormAction.EntityCondition)modelFormAction).finder.getEntityName());
+                }
+            }
+        }
+        for (ModelFormField modelFormField: this.fieldList) {
+            if (UtilValidate.isNotEmpty(modelFormField.getEntityName())) {
+                allEntityNamesUsed.add(modelFormField.getEntityName());
+            }
+            if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) {
+                
+            }
+            if (modelFormField.getFieldInfo() instanceof ModelFormField.FieldInfoWithOptions) {
+                for (ModelFormField.OptionSource optionSource: ((ModelFormField.FieldInfoWithOptions)modelFormField.getFieldInfo()).optionSources) {
+                    if (optionSource instanceof ModelFormField.EntityOptions) {
+                        allEntityNamesUsed.add(((ModelFormField.EntityOptions)optionSource).entityName);
+                    }
+                }
+            }
+        }
+        return allEntityNamesUsed;
     }
 }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=639458&r1=639457&r2=639458&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Thu Mar 20 14:07:46 2008
@@ -1453,7 +1453,7 @@
         }
 
         protected FlexibleStringExpander noCurrentSelectedKey = null;
-        protected List optionSources = new LinkedList();
+        protected List<OptionSource> optionSources = new LinkedList();
 
         public FieldInfoWithOptions(int fieldSource, int fieldType, ModelFormField modelFormField) {
             super(fieldSource, fieldType, modelFormField);