changeset 7745:1d6b957d8953

issue1549: Add live-validation to wsplgen to-field. Unfortunately, controlling the displayed message proved difficult due to mixed error/validation-handling code. It shows wrong format message for now.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 11 Feb 2014 12:37:16 +0100 (2014-02-11)
parents 8abc86160959
children 56001dce01dd
files gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java
diffstat 6 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java	Tue Feb 11 12:37:16 2014 +0100
@@ -228,6 +228,8 @@
 
     String wrongFormat();
 
+    String toShouldNotBeNegative();
+
     String atLeastOneValue();
 
     String missingInput();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties	Tue Feb 11 12:37:16 2014 +0100
@@ -129,6 +129,7 @@
 unitDiffInM = Diff [m]:
 unitLocation = km
 wrongFormat = Wrong format
+toShouldNotBeNegative = Field 'to' has to contain a positive value.
 atLeastOneValue = You need to insert at least one value.
 missingInput = You need to enter a value.
 too_many_values = Only one value allowed
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties	Tue Feb 11 12:37:16 2014 +0100
@@ -129,6 +129,7 @@
 unitDiffInM = Diff [m]:
 unitLocation = km
 wrongFormat = Falsches Format
+toShouldNotBeNegative = Feld 'bis' muss einen positiven Wert enthalten.
 atLeastOneValue = Sie m\u00fcssen mindestens einen Wert eingeben.
 missingInput = Sie m\u00fcssen einen Wert eingeben.
 too_many_values = Nur ein Eingabewert erlaubt
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties	Tue Feb 11 12:37:16 2014 +0100
@@ -130,6 +130,7 @@
 unitDiffInM = Diff [m]:
 unitLocation = km
 wrongFormat = Wrong format
+toShouldNotBeNegative = Field 'to' has to contain a positive value.
 atLeastOneValue = You need to insert at least one value.
 missingInput = You need to enter a value.
 too_many_values = Only one value allowed
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java	Tue Feb 11 12:37:16 2014 +0100
@@ -97,6 +97,7 @@
         distancePanel  = new DoubleRangePanel(
             labelFrom(), labelTo(), labelStep(),
             0d, 0d, 0d, 250, this, labelOrientation);
+        distancePanel.setNegativeToAllowed(false);
     }
 
 
@@ -423,6 +424,7 @@
     }
 
 
+    /** Gets the double from default in data, null if none. */
     protected double getDefaultValue(Data data)
     throws NumberFormatException
     {
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java	Fri Feb 07 15:48:43 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java	Tue Feb 11 12:37:16 2014 +0100
@@ -45,6 +45,9 @@
      * distance.*/
     public static final String FIELD_WIDTH = "step";
 
+    /** Whether or not negative 'to' values are allowed. */
+    protected boolean negativeToAllowed = true;
+
     /** The textboxes */
     protected FloatItem fromItem;
     protected FloatItem toItem;
@@ -153,6 +156,10 @@
         stepItem.setValue(f.format(steps));
     }
 
+    public void setNegativeToAllowed(boolean isAllowed) {
+        negativeToAllowed = isAllowed;
+    }
+
 
     public boolean validateForm() {
         try {
@@ -171,6 +178,9 @@
      * there are values that doesn't represent a valid float, an error is
      * displayed.
      *
+     * Also if negativeToAllowed is false, an error is registered if
+     * the 'to' field contains a negative value.
+     *
      * @param item The FormItem.
      */
     @SuppressWarnings("unchecked")
@@ -187,12 +197,14 @@
         @SuppressWarnings("rawtypes")
         Map errors     = getErrors();
 
+        Double d = 0d;
+
         try {
             if (v == null) {
                 throw new NumberFormatException("empty");
             }
 
-            f.parse(v);
+            d = f.parse(v);
 
             errors.remove(item.getFieldName());
         }
@@ -204,6 +216,17 @@
             valid = false;
         }
 
+        if (negativeToAllowed == false
+            && item.getFieldName().equals(FIELD_TO) && d < 0d) {
+            errors.put(item.getFieldName(), MESSAGES.toShouldNotBeNegative());
+
+            item.setValue("");
+
+            item.focusInItem();
+
+            valid = false;
+        }
+
         setErrors(errors, true);
 
         return valid;

http://dive4elements.wald.intevation.org