changeset 2929:0ef4753e5515

Improved manual wsp input validation. flys-client/trunk@4830 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 28 Jun 2012 15:44:10 +0000 (2012-06-28)
parents f0c7c52203c0
children e8eca6eeeec0
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java
diffstat 3 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Jun 28 15:33:08 2012 +0000
+++ b/flys-client/ChangeLog	Thu Jun 28 15:44:10 2012 +0000
@@ -1,5 +1,12 @@
 2012-06-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java:
+	  Improved validation.
+
+	* src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java
+	  (isDouble): New, shortcut.
+
+2012-06-28	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java:
 	  Added basic validation
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java	Thu Jun 28 15:33:08 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java	Thu Jun 28 15:44:10 2012 +0000
@@ -282,10 +282,7 @@
      * fire a RedrawRequest and destroy.
      */
     protected void okClicked() {
-        // TODO proper validation (might use DynamicForm)
         if (valueInputPanel.getValue() == null) {
-            // not valid...
-            //TODO
             return;
         }
         GWT.log(valueInputPanel.getValue().toString());
@@ -365,10 +362,7 @@
 
     /** Return false if x or y attribute is missing. */
     protected boolean isDialogValid() {
-        boolean valid = true;
-        // TODO implement
-        // 
-        return valid;
+        return (DoubleValidator.isDouble(valueInputPanel.getValue()));
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java	Thu Jun 28 15:33:08 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java	Thu Jun 28 15:44:10 2012 +0000
@@ -17,6 +17,32 @@
     /** The interface that provides i18n messages. */
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
 
+
+    /** Statically determine doubility of String value. */
+    public static boolean isDouble(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+
+        boolean valid = true;
+        String v = obj.toString();
+
+        NumberFormat f = NumberFormat.getDecimalFormat();
+
+        try {
+            if (v == null) {
+                throw new NumberFormatException("empty");
+            }
+
+            double value = f.parse(v);
+        }
+        catch (NumberFormatException nfe) {
+            valid = false;
+        }
+        return valid;
+    
+    }
+
     /**
      *
      */

http://dive4elements.wald.intevation.org