svn commit: r1220927 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/form/ModelForm.java

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

svn commit: r1220927 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/form/ModelForm.java

erwan
Author: erwan
Date: Mon Dec 19 20:16:01 2011
New Revision: 1220927

URL: http://svn.apache.org/viewvc?rev=1220927&view=rev
Log:
OFBIZ-4487 - enable definition for position on sortfield - patch from Youssef Khaye and Olivier Heintz

Modified:
    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=1220927&r1=1220926&r2=1220927&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Mon Dec 19 20:16:01 2011
@@ -356,6 +356,7 @@ under the License.
     <xs:element name="sort-field">
         <xs:complexType>
             <xs:attributeGroup ref="attlist.sort-field"/>
+            <xs:attribute name="position" type="xs:positiveInteger"/>
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.sort-field">

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=1220927&r1=1220926&r2=1220927&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 Mon Dec 19 20:16:01 2011
@@ -132,7 +132,7 @@ public class ModelForm extends ModelWidg
     protected List<AltTarget> altTargets = FastList.newInstance();
     protected List<AutoFieldsService> autoFieldsServices = FastList.newInstance();
     protected List<AutoFieldsEntity> autoFieldsEntities = FastList.newInstance();
-    protected List<String> sortOrderFields = FastList.newInstance();
+    protected List<SortField> sortOrderFields = FastList.newInstance();
     protected List<AltRowStyle> altRowStyles = FastList.newInstance();
 
     /** This List will contain one copy of each field for each field name in the order
@@ -538,7 +538,8 @@ public class ModelForm extends ModelWidg
                 String tagName = sortFieldElement.getTagName();
                 if (tagName.equals("sort-field")) {
                     String fieldName = sortFieldElement.getAttribute("name");
-                    this.sortOrderFields.add(fieldName);
+                    String position = sortFieldElement.getAttribute("position");
+                    this.sortOrderFields.add(new SortField(fieldName, position));
                     this.fieldGroupMap.put(fieldName, lastFieldGroup);
                 } else if (tagName.equals("banner")) {
                     Banner thisBanner = new Banner(sortFieldElement, this);
@@ -559,7 +560,8 @@ public class ModelForm extends ModelWidg
         // reorder fields according to sort order
         if (sortOrderFields.size() > 0) {
             List<ModelFormField> sortedFields = FastList.newInstance();
-            for (String fieldName: this.sortOrderFields) {
+            for (SortField sortField: this.sortOrderFields) {
+                String fieldName = sortField.getFieldName();
                 if (UtilValidate.isEmpty(fieldName)) {
                     continue;
                 }
@@ -570,6 +572,9 @@ public class ModelForm extends ModelWidg
                     ModelFormField modelFormField = fieldIter.next();
                     if (fieldName.equals(modelFormField.getName())) {
                         // matched the name; remove from the original last and add to the sorted list
+                        if (UtilValidate.isNotEmpty(sortField.getPosition())) {
+                            modelFormField.setPosition(sortField.getPosition());
+                        }
                         fieldIter.remove();
                         sortedFields.add(modelFormField);
                     }
@@ -2894,6 +2899,35 @@ public class ModelForm extends ModelWidg
         }
     }
 
+    public static class SortField {
+        protected String fieldName;
+        protected Integer position = null;
+
+        public SortField(String name, String position) {
+            this.fieldName = name;
+            if (UtilValidate.isNotEmpty(position)){
+                Integer posParam = null;
+                try {
+                    posParam = Integer.valueOf(position);
+                }
+                catch(Exception e) {/* just ignore the exception*/}
+                this.position = posParam;
+            }
+        }
+
+        public SortField(String name) {
+            this(name, null);
+        }
+
+        public String getFieldName() {
+            return this.fieldName;
+        }
+
+        public Integer getPosition() {
+            return this.position;
+        }
+    }
+
     public static interface FieldGroupBase {}
 
     public static class FieldGroup implements FieldGroupBase {
@@ -2923,7 +2957,7 @@ public class ModelForm extends ModelWidg
                 }
 
                 for (Element sortFieldElement: UtilXml.childElementList(sortOrderElement, "sort-field")) {
-                    modelForm.sortOrderFields.add(sortFieldElement.getAttribute("name"));
+                    modelForm.sortOrderFields.add(new SortField(sortFieldElement.getAttribute("name"),sortFieldElement.getAttribute("position")));
                     modelForm.fieldGroupMap.put(sortFieldElement.getAttribute("name"), this);
                 }
             } else {