changeset 7748:316a9eeb0836

Hopefully a cleaner fix for flys/issue1549 using the FloatRangeValidator from SmartGWT to verify that the 'to' field stays positive.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 21 Feb 2014 15:28:08 +0100
parents cfa7e2164f87
children 819528f6fabb
files 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 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java
diffstat 3 files changed, 11 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java	Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java	Fri Feb 21 15:28:08 2014 +0100
@@ -97,7 +97,6 @@
         distancePanel  = new DoubleRangePanel(
             labelFrom(), labelTo(), labelStep(),
             0d, 0d, 0d, 250, this, labelOrientation);
-        distancePanel.setNegativeToAllowed(false);
     }
 
 
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java	Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java	Fri Feb 21 15:28:08 2014 +0100
@@ -45,9 +45,6 @@
      * 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;
@@ -57,6 +54,10 @@
     public DoubleRangePanel() {
     }
 
+    public FloatItem getToItem() {
+        return toItem;
+    }
+
 
     /**
      * Creates a new form with a single input field that displays an array of
@@ -156,11 +157,6 @@
         stepItem.setValue(f.format(steps));
     }
 
-    public void setNegativeToAllowed(boolean isAllowed) {
-        negativeToAllowed = isAllowed;
-    }
-
-
     public boolean validateForm() {
         try {
             return
@@ -197,14 +193,12 @@
         @SuppressWarnings("rawtypes")
         Map errors     = getErrors();
 
-        Double d = 0d;
-
         try {
             if (v == null) {
                 throw new NumberFormatException("empty");
             }
 
-            d = f.parse(v);
+            f.parse(v);
 
             errors.remove(item.getFieldName());
         }
@@ -216,17 +210,6 @@
             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;
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java	Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java	Fri Feb 21 15:28:08 2014 +0100
@@ -8,7 +8,7 @@
 
 package org.dive4elements.river.client.client.ui;
 
-import java.util.List;
+import com.smartgwt.client.widgets.form.validator.FloatRangeValidator;
 
 public class WaterlevelGroundPanel extends DistancePanel {
 
@@ -21,6 +21,11 @@
 
     public WaterlevelGroundPanel() {
         super("left");
+
+        FloatRangeValidator frv = new FloatRangeValidator();
+        frv.setMin(0f);
+        frv.setMax(Float.MAX_VALUE);
+        distancePanel.getToItem().setValidators(frv);
     }
 
 
@@ -125,16 +130,5 @@
         // We don't need a helper panel here. But we have to override this
         // method to avoid the table creation in the parent class.
     }
-
-    @Override
-    protected void validateTo(List<String> errors) {
-        double to = distancePanel.getTo();
-
-        if (to < 0d) {
-            distancePanel.setTo(max);
-            errors.add(MSG.negative_values_not_allowed_for_to());
-        }
-        super.validateTo(errors);
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org