diff flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.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/WQInputPanel.java	Fri Mar 18 12:01:55 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Fri Mar 18 13:45:34 2011 +0000
@@ -348,6 +348,35 @@
      * @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 (!isRangeMode()) {
+            Canvas member = container.getMember(0);
+            if (member instanceof DoubleArrayPanel) {
+                DoubleArrayPanel form = (DoubleArrayPanel) member;
+                if (isWMode()) {
+                    saveSingleWValues(form);
+                }
+                else {
+                    saveSingleQValues(form);
+                }
+            }
+        }
+        else {
+            Canvas member = container.getMember(0);
+            if (member instanceof DoubleRangePanel) {
+                DoubleRangePanel form = (DoubleRangePanel) member;
+
+                if (isWMode()) {
+                    saveRangeWValues(form);
+                }
+                else {
+                    saveRangeQValues(form);
+                }
+            }
+        }
+
         return new Data[] {
             getDataMode(),
             getDataFrom(),
@@ -600,42 +629,98 @@
         if (wqMode.equals(FIELD_WQ_W)) {
             if (inputMode.equals(FIELD_MODE_SINGLE)) {
                 DoubleArrayPanel p = (DoubleArrayPanel) form;
-
-                if (p.validateForm(item)) {
-                    setSingleW(p.getInputValues(item));
-                }
+                saveSingleWValue(p, item);
             }
             else {
                 DoubleRangePanel p = (DoubleRangePanel) form;
-
-                if (p.validateForm(item)) {
-                    setFromW(p.getFrom());
-                    setToW(p.getTo());
-                    setStepW(p.getStep());
-                }
+                saveRangeWValue(p, item);
             }
         }
         else {
             if (inputMode.equals(FIELD_MODE_SINGLE)) {
                 DoubleArrayPanel p = (DoubleArrayPanel) form;
-
-                if (p.validateForm(item)) {
-                    setSingleQ(p.getInputValues(item));
-                }
+                saveSingleQValue(p, item);
             }
             else {
                 DoubleRangePanel p = (DoubleRangePanel) form;
+                saveRangeQValue(p, item);
+            }
+        }
+    }
 
-                if (p.validateForm(item)) {
-                    setFromQ(p.getFrom());
-                    setToQ(p.getTo());
-                    setStepQ(p.getStep());
-                }
+
+    protected void saveSingleWValues(DoubleArrayPanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) {
+                saveSingleWValue(p, item);
             }
         }
     }
 
 
+    protected void saveSingleQValues(DoubleArrayPanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) {
+                saveSingleQValue(p, item);
+            }
+        }
+    }
+
+
+    protected void saveSingleWValue(DoubleArrayPanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setSingleW(p.getInputValues(item));
+        }
+    }
+
+
+    protected void saveSingleQValue(DoubleArrayPanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setSingleQ(p.getInputValues(item));
+        }
+    }
+
+
+    protected void saveRangeWValues(DoubleRangePanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            saveRangeWValue(p, item);
+        }
+    }
+
+
+    protected void saveRangeQValues(DoubleRangePanel p) {
+        FormItem[] formItems = p.getFields();
+
+        for (FormItem item: formItems) {
+            saveRangeQValue(p, item);
+        }
+    }
+
+
+    protected void saveRangeWValue(DoubleRangePanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setFromW(p.getFrom());
+            setToW(p.getTo());
+            setStepW(p.getStep());
+        }
+    }
+
+
+    protected void saveRangeQValue(DoubleRangePanel p, FormItem item) {
+        if (p.validateForm(item)) {
+            setFromQ(p.getFrom());
+            setToQ(p.getTo());
+            setStepQ(p.getStep());
+        }
+    }
+
+
     protected double[] getSingleQ() {
         return valuesQ;
     }

http://dive4elements.wald.intevation.org