changeset 1524:487c3ff7e838

Improved the code of IntegerRangePanel: it now returns the inserted values as IntegerRangeData object. flys-client/trunk@3709 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 Jan 2012 15:04:30 +0000 (2012-01-18)
parents 07b532f9e057
children 27a2a065a963
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/RangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/TimerangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java
diffstat 6 files changed, 120 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jan 18 09:19:36 2012 +0000
+++ b/flys-client/ChangeLog	Wed Jan 18 15:04:30 2012 +0000
@@ -1,3 +1,27 @@
+2012-01-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java:
+	  Modified getItems(): it will now return a single DataItem which value
+	  consists of the min and max value seperated by a ';'.
+
+	* src/main/java/de/intevation/flys/client/client/ui/TimerangePanel.java:
+	  Removed, because there is no time relevant code here. All code has moved
+	  to IntegerRangePanel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java:
+	  Added new methods getLowerAsInt() and getUpperAsInt() and setMaxLower()
+	  and setMaxUpper() from TimerangePanel. Furthermore, the still missing
+	  getData() method has been implemented. It returns a single
+	  IntegerRangeData object.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Create new instances of IntegerRangePanel if the ui provider is set to
+	  'intrange'.
+
+	* src/main/java/de/intevation/flys/client/client/ui/RangePanel.java: The
+	  range panel stores the data name now and has new methods that return the
+	  lower and upper value.
+
 2012-01-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/RangePanel.java: New.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java	Wed Jan 18 09:19:36 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/IntegerRangePanel.java	Wed Jan 18 15:04:30 2012 +0000
@@ -5,7 +5,9 @@
 import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator;
 import com.smartgwt.client.widgets.form.validator.Validator;
 
+import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataList;
+import de.intevation.flys.client.shared.model.IntegerRangeData;
 
 
 public class IntegerRangePanel extends RangePanel {
@@ -15,6 +17,15 @@
 
 
     @Override
+    protected Data[] getData() {
+        Integer lo = getLowerAsInt();
+        Integer up = getUpperAsInt();
+
+        return new Data[] { new IntegerRangeData(getDataName(), null, lo, up) };
+    }
+
+
+    @Override
     protected FormItem newFormItem(String name) {
         IntegerItem item = new IntegerItem(name, "");
         item.setShowTitle(false);
@@ -25,6 +36,9 @@
 
     @Override
     protected Validator[] createLowerValidators(DataList dataList) {
+        setMaxLower(dataList);
+        setMaxUpper(dataList);
+
         Validator validator = newRangeValidator();
 
         if (validator != null) {
@@ -37,6 +51,9 @@
 
     @Override
     protected Validator[] createUpperValidators(DataList dataList) {
+        setMaxLower(dataList);
+        setMaxUpper(dataList);
+
         Validator validator = newRangeValidator();
 
         if (validator != null) {
@@ -47,6 +64,38 @@
     }
 
 
+    public Integer getLowerAsInt() {
+        String raw = getLower();
+
+        if (raw != null && raw.length() > 0) {
+            try {
+                return Integer.valueOf(raw);
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+
+        return null;
+    }
+
+
+    public Integer getUpperAsInt() {
+        String raw = getUpper();
+
+        if (raw != null && raw.length() > 0) {
+            try {
+                return Integer.valueOf(raw);
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+
+        return null;
+    }
+
+
     protected Validator newRangeValidator() {
         Integer maxLower = getMaxLower();
         Integer maxUpper = getMaxUpper();
@@ -68,6 +117,12 @@
     }
 
 
+    protected void setMaxLower(DataList dataList) {
+        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
+        setMaxLower(range.getLower());
+    }
+
+
     public void setMaxLower(Integer maxLower) {
         this.maxLower = maxLower;
     }
@@ -78,6 +133,12 @@
     }
 
 
+    protected void setMaxUpper(DataList dataList) {
+        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
+        setMaxUpper(range.getUpper());
+    }
+
+
     public void setMaxUpper(Integer maxUpper) {
         this.maxUpper = maxUpper;
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangePanel.java	Wed Jan 18 09:19:36 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangePanel.java	Wed Jan 18 15:04:30 2012 +0000
@@ -34,9 +34,13 @@
     protected DynamicForm lowerForm;
     protected DynamicForm upperForm;
 
+    protected String dataName;
+
 
     @Override
     public Canvas create(DataList data) {
+        setDataName(data);
+
         VLayout root = new VLayout();
 
         root.addMember(createLabel(data));
@@ -76,6 +80,28 @@
     }
 
 
+    protected void setDataName(DataList dataList) {
+        Data data = dataList.get(0);
+
+        this.dataName = data.getLabel();
+    }
+
+
+    public String getDataName() {
+        return dataName;
+    }
+
+
+    public String getLower() {
+        return lowerForm.getValueAsString(FIELD_LOWER);
+    }
+
+
+    public String getUpper() {
+        return upperForm.getValueAsString(FIELD_UPPER);
+    }
+
+
     protected Canvas createLabel(DataList dataList) {
         Label label = new Label(dataList.getLabel());
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/TimerangePanel.java	Wed Jan 18 09:19:36 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-package de.intevation.flys.client.client.ui;
-
-import com.smartgwt.client.types.FieldType;
-import com.smartgwt.client.widgets.form.validator.Validator;
-
-import de.intevation.flys.client.shared.model.Data;
-import de.intevation.flys.client.shared.model.IntegerRangeData;
-import de.intevation.flys.client.shared.model.DataList;
-
-
-public class TimerangePanel extends IntegerRangePanel {
-
-
-    @Override
-    protected Validator[] createLowerValidators(DataList dataList) {
-        setMaxLower(dataList);
-        setMaxUpper(dataList);
-
-        return super.createLowerValidators(dataList);
-    }
-
-
-    @Override
-    protected Validator[] createUpperValidators(DataList dataList) {
-        setMaxUpper(dataList);
-        setMaxLower(dataList);
-
-        return super.createUpperValidators(dataList);
-    }
-
-
-    protected void setMaxLower(DataList dataList) {
-        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
-        setMaxLower(range.getLower());
-    }
-
-
-    protected void setMaxUpper(DataList dataList) {
-        IntegerRangeData range = (IntegerRangeData) dataList.get(0);
-        setMaxUpper(range.getUpper());
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Jan 18 09:19:36 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Jan 18 15:04:30 2012 +0000
@@ -63,7 +63,7 @@
             return new DigitizePanel();
         }
         else if (uiProvider.equals("timerange")) {
-            return new TimerangePanel();
+            return new IntegerRangePanel();
         }
         else {
             return new SelectProvider();
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java	Wed Jan 18 09:19:36 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java	Wed Jan 18 15:04:30 2012 +0000
@@ -53,18 +53,20 @@
 
 
     /**
-     * Returns the DataItems provided by this Data object.
+     * Returns a DataItem which value is a string that consists of the min and
+     * max value separated by a ';'.
      *
-     * @return the DataItems.
+     * @return the DataItem.
      */
     public DataItem[] getItems() {
         String theMin = String.valueOf(lower);
-        DataItem min  = new DefaultDataItem(theMin, theMin, theMin);
-
         String theMax = String.valueOf(upper);
-        DataItem max  = new DefaultDataItem(theMax, theMax, theMax);
 
-        return new DataItem[] { min, max };
+        String value = theMin + ";" + theMax;
+
+        DataItem item  = new DefaultDataItem(value, value, value);
+
+        return new DataItem[] { item };
     }
 
 

http://dive4elements.wald.intevation.org