diff flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1504:02a9104c0451

Implemented the validators more object oriented. flys-client/trunk@3634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 09 Jan 2012 17:29:56 +0000
parents
children 339f8aa641b5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java	Mon Jan 09 17:29:56 2012 +0000
@@ -0,0 +1,44 @@
+package de.intevation.flys.client.client.utils;
+
+import java.util.Map;
+
+import com.google.gwt.i18n.client.NumberFormat;
+
+import com.smartgwt.client.widgets.form.fields.FormItem;
+
+/**
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class DoubleValidator extends Validator {
+
+    /**
+     *
+     */
+    @Override
+    protected boolean validate(FormItem item, Map errors) {
+        boolean valid = true;
+
+        String v = (String) item.getValue();
+
+        NumberFormat f = NumberFormat.getDecimalFormat();
+
+        try {
+            if (v == null) {
+                throw new NumberFormatException("empty");
+            }
+
+            double value = f.parse(v);
+
+            errors.remove(item.getFieldName());
+        }
+        catch (NumberFormatException nfe) {
+            errors.put(item.getFieldName(), MSG.wrongFormat());
+
+            item.focusInItem();
+
+            valid = false;
+        }
+        return valid;
+    }
+}
+

http://dive4elements.wald.intevation.org