[PATCH] issue1549: Add live-validation to wsplgen to-field

Wald Commits scm-commit at wald.intevation.org
Tue Feb 11 12:35:29 CET 2014


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1392118636 -3600
# Node ID 1d6b957d8953da796b8e0eb008043d544175893d
# Parent  8abc861609599a8d3af7b5cb71e10ca694f329f1
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.

diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.java
--- 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();
diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants.properties
--- 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
diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_de.properties
--- 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
diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYSConstants_en.properties
--- 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
diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java
--- 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
     {
diff -r 8abc86160959 -r 1d6b957d8953 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java
--- 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;


More information about the Dive4elements-commits mailing list