changeset 563:469528551b78

Introduced an input validation for the location panels. flys-client/trunk@2104 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 14 Jun 2011 10:42:34 +0000
parents 9f16ac843dda
children 55a90afaf513
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java
diffstat 7 files changed, 92 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jun 14 10:42:34 2011 +0000
@@ -1,3 +1,20 @@
+2011-06-14  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java:
+	  Added a method to validate the form field. If a value is not a valid
+	  double value, it returns false.
+
+	* src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java:
+	  The values entered in the text field are validated regarding to the
+	  river's range.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java: Added
+	  error messages displayed if we were not able to read min/max values from
+	  DESCRIBE document.
+
 2011-06-09  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Jun 14 10:42:34 2011 +0000
@@ -190,6 +190,8 @@
 
     // ERRORS
 
+    String error_read_minmax_values();
+
     String error_validate_range();
 
     String error_validate_lower_range();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Jun 14 10:42:34 2011 +0000
@@ -91,6 +91,7 @@
 wst = WST
 chart_themepanel_header_themes = Theme
 
+error_read_minmax_values = Error while reading min/max values for the location input.
 error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2.
 error_validate_lower_range = The lower value $1 needs to be bigger than $2.
 error_validate_upper_range = The upper value $1 needs to be smaller than $2.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Jun 14 10:42:34 2011 +0000
@@ -91,6 +91,7 @@
 wst = WST
 chart_themepanel_header_themes = Thema
 
+error_read_minmax_values = Fehler beim Lesen der min/max Werte. Es kann keine Validierung der eingegebenen Strecke durchgef\u00fchrt werden.
 error_validate_range = Der untere Wert $1 muss kleiner als $3 und gr\u00f6\u00dfer als $2 sein.
 error_validate_lower_range = Der untere Wert $1 muss gr\u00f6\u00dfer sein als $2.
 error_validate_upper_range = Der obere Wert $1 muss kleiner sein als $2.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Jun 14 10:42:34 2011 +0000
@@ -91,6 +91,7 @@
 wst = WST
 chart_themepanel_header_themes = Theme
 
+error_read_minmax_values = Error while reading min/max values for the location input.
 error_validate_range = The value $1 needs to be smaller than $3 and bigger than $2.
 error_validate_lower_range = The lower value $1 needs to be bigger than $2.
 error_validate_upper_range = The upper value $1 needs to be smaller than $2.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Tue Jun 14 10:42:34 2011 +0000
@@ -119,6 +119,11 @@
     }
 
 
+    protected boolean validateForm() {
+        return validateForm(ti);
+    }
+
+
     /**
      * This method validates the entered text in the location input field. If
      * there are values that doesn't represent a valid location, an error is
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Thu Jun 09 14:06:10 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Tue Jun 14 10:42:34 2011 +0000
@@ -1,10 +1,13 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
@@ -57,6 +60,12 @@
     /** A container that will contain the location or the distance panel.*/
     protected HLayout container;
 
+    /** The minimal value that the user is allowed to enter.*/
+    protected double min;
+
+    /** The maximal value that the user is allowed to enter.*/
+    protected double max;
+
     /** The values entered in the location mode.*/
     protected double[] values;
 
@@ -185,6 +194,20 @@
             return;
         }
 
+        DataItem[] items = data.getItems();
+        DataItem   iMin  = getDataItem(items, "min");
+        DataItem   iMax  = getDataItem(items, "max");
+
+        try {
+            min = Double.parseDouble(iMin.getStringValue());
+            max = Double.parseDouble(iMax.getStringValue());
+        }
+        catch (NumberFormatException nfe) {
+            SC.warn(MESSAGES.error_read_minmax_values());
+            min = -Double.MAX_VALUE;
+            max = Double.MAX_VALUE;
+        }
+
         DataItem def   = data.getDefault();
         String   value = def.getStringValue();
 
@@ -239,6 +262,48 @@
     }
 
 
+    @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+        NumberFormat nf     = NumberFormat.getDecimalFormat();
+
+        saveLocationValues(locationPanel);
+
+        if (!locationPanel.validateForm()) {
+            errors.add(MESSAGES.wrongFormat());
+            return errors;
+        }
+
+        double[] values = getLocationValues();
+        double[] good   = new double[values.length];
+        int      idx    = 0;
+
+        for (double value: values) {
+            if (value < min || value > max) {
+                String tmp = MESSAGES.error_validate_range();
+                tmp = tmp.replace("$1", nf.format(value));
+                tmp = tmp.replace("$2", nf.format(min));
+                tmp = tmp.replace("$3", nf.format(max));
+                errors.add(tmp);
+            }
+            else {
+                good[idx++] = value;
+            }
+        }
+
+        double[] justGood = new double[idx];
+        for (int i = 0; i < justGood.length; i++) {
+            justGood[i] = good[i];
+        }
+
+        if (!errors.isEmpty()) {
+            locationPanel.setValues(justGood);
+        }
+
+        return errors;
+    }
+
+
     /**
      * This method returns the selected data.
      *

http://dive4elements.wald.intevation.org