diff flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java @ 59:a3d235c63195

Save the data explicitly in the LocationDistancePanel and WQInputPanel before returning the user input to avoid a nullpointer exception. flys-client/trunk@1519 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 Mar 2011 13:45:34 +0000
parents d018995fbee7
children 4784ca718476
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Fri Mar 18 12:01:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Fri Mar 18 13:45:34 2011 +0000
@@ -223,6 +223,24 @@
      * @return the selected/inserted data.
      */
     public Data[] getData() {
+        // XXX If we have entered a value and click right afterwards on the
+        // 'next' button, the BlurEvent is not fired, and the values are not
+        // saved. So, we gonna save those values explicitly.
+        if (isLocationMode()) {
+            Canvas member = container.getMember(0);
+            if (member instanceof DoubleArrayPanel) {
+                DoubleArrayPanel form = (DoubleArrayPanel) member;
+                saveLocationValues(form);
+            }
+        }
+        else {
+            Canvas member = container.getMember(0);
+            if (member instanceof DoubleRangePanel) {
+                DoubleRangePanel form = (DoubleRangePanel) member;
+                saveDistanceValues(form);
+            }
+        }
+
         return new Data[] { getDataFrom(), getDataTo(), getDataStep() };
     }
 
@@ -390,23 +408,75 @@
         if (field.equals(DoubleArrayPanel.FIELD_NAME)) {
             DoubleArrayPanel p = (DoubleArrayPanel) event.getForm();
 
-            if (p.validateForm(item)) {
-                setLocationValues(p.getInputValues(item));
-            }
+            saveLocationValue(p, item);
         }
         else {
             DoubleRangePanel p = (DoubleRangePanel) event.getForm();
 
-            if (p.validateForm(item)) {
-                setFrom(p.getFrom());
-                setTo(p.getTo());
-                setStep(p.getStep());
+            saveDistanceValue(p, item);
+        }
+    }
+
+
+    /**
+     * Validates and stores all values entered in the location mode.
+     *
+     * @param p The DoubleArrayPanel.
+     */
+    protected void saveLocationValues(DoubleArrayPanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) {
+                saveLocationValue(p, item);
             }
         }
     }
 
 
     /**
+     * Validates and stores all values entered in the distance mode.
+     *
+     * @param p The DoubleRangePanel.
+     */
+    protected void saveDistanceValues(DoubleRangePanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            saveDistanceValue(p, item);
+        }
+    }
+
+
+    /**
+     * Validates and stores a value entered in the location mode.
+     *
+     * @param p The DoubleArrayPanel.
+     * @param item The item that needs to be validated.
+     */
+    protected void saveLocationValue(DoubleArrayPanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setLocationValues(p.getInputValues(item));
+        }
+    }
+
+
+    /**
+     * Validates and stores value entered in the distance mode.
+     *
+     * @param p The DoubleRangePanel.
+     * @param item The item that needs to be validated.
+     */
+    protected void saveDistanceValue(DoubleRangePanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setFrom(p.getFrom());
+            setTo(p.getTo());
+            setStep(p.getStep());
+        }
+    }
+
+
+    /**
      * This method creates the panel that contains the checkboxes to switch
      * between the input mode 'location' and 'distance'.
      *

http://dive4elements.wald.intevation.org