diff flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 519:77234b1d009c

ISSUE-90 & ISSUE-40 (part II/II) Former selected values are preselected after back jumps. flys-client/trunk@1998 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 24 May 2011 16:22:34 +0000
parents be842e36ce1c
children ec85bab86e7b
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Tue May 24 11:22:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Tue May 24 16:22:34 2011 +0000
@@ -168,7 +168,6 @@
     public Canvas create(DataList data) {
         initDefaults(data);
 
-
         Canvas  widget = createWidget(data);
         Canvas  submit = getNextButton();
         Label   label  = new Label(MESSAGE.wqTitle());
@@ -182,6 +181,8 @@
         layout.addMember(widget);
         layout.addMember(submit);
 
+        initUserDefaults(data);
+
         return layout;
     }
 
@@ -420,6 +421,135 @@
     }
 
 
+    /**
+     * Initializes the form items with former inserted user data.
+     *
+     * @param list The DataList that contains the user data.
+     */
+    protected void initUserDefaults(DataList list) {
+        List<Data> allData = list.getAll();
+
+        Data     m        = getData(allData, "wq_mode");
+        DataItem modeItem = m != null ? m.getDefault() : null;
+        String   theMode  = modeItem != null
+            ? modeItem.getStringValue()
+            : null;
+
+        Data     s            = getData(allData, "wq_selection");
+        DataItem sI           = s != null ? s.getDefault() : null;
+        String   theSelection = sI != null ? sI.getStringValue() : null;
+
+        if (theMode == null || theMode.length() == 0) {
+            return;
+        }
+
+        initUserSingleValues(list, theMode);
+        initUserRangeValues(list, theMode);
+
+        modes.setValue(FIELD_WQ, theMode);
+
+        if (theSelection != null || theSelection.length() > 0) {
+            modes.setValue(FIELD_MODE, theSelection);
+            updatePanels(theMode, theSelection);
+        }
+    }
+
+
+    /**
+     * Initializes the single values of W or Q from DataList.
+     *
+     * @param list The DataList that contains the 'wq_single' object.
+     * @param theMode The W or Q mode.
+     */
+    protected void initUserSingleValues(DataList list, String theMode) {
+        List<Data> allData = list.getAll();
+
+        Data     s = getData(allData, "wq_single");
+        DataItem i = s != null ? s.getDefault() : null;
+
+        if (i != null) {
+            String   value = i.getStringValue();
+            String[] split = value.split(" ");
+
+            int num = split != null ? split.length : 0;
+
+            double[] values = new double[num];
+
+            for (int j = 0; j < num; j++) {
+                try {
+                    values[j] = Double.valueOf(split[j]);
+                }
+                catch (NumberFormatException nfe) {
+                    // nothing to do
+                }
+            }
+
+            if (theMode.equals("W")) {
+                setSingleW(values);
+            }
+            else {
+                setSingleQ(values);
+            }
+        }
+    }
+
+
+    /**
+     * Initializes the range values of W or Q from DataList.
+     *
+     * @param list The DataList that contains the 'wq_single' object.
+     * @param theMode The W or Q mode.
+     */
+    protected void initUserRangeValues(DataList list, String theMode) {
+        List<Data> allData = list.getAll();
+
+        // init range mode values
+        Data f = getData(allData, "wq_from");
+        Data t = getData(allData, "wq_to");
+        Data s = getData(allData, "wq_step");
+
+        if (f != null && t != null && s != null) {
+            DataItem dF = f.getDefault();
+            DataItem dT = t.getDefault();
+            DataItem dS = s.getDefault();
+
+            String fS = dF != null ? dF.getStringValue() : null;
+            String tS = dT != null ? dT.getStringValue() : null;
+            String sS = dS != null ? dS.getStringValue() : null;
+
+            try {
+                double from = Double.valueOf(fS);
+                double to   = Double.valueOf(tS);
+                double step = Double.valueOf(sS);
+
+                if (theMode.equals("W")) {
+                    setWRangeValues(from, to, step);
+                }
+                else {
+                    setQRangeValues(from, to, step);
+                }
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+    }
+
+
+    protected void setQRangeValues(double f, double t, double s) {
+        setFromQ(f);
+        setToQ(t);
+        setStepQ(s);
+    }
+
+
+    protected void setWRangeValues(double f, double t, double s) {
+        setFromW(f);
+        setToW(t);
+        setStepW(s);
+    }
+
+
     protected String createWString(DataItem from, DataItem to, DataItem step) {
         StringBuilder sb = new StringBuilder();
         sb.append(from.getLabel());
@@ -473,11 +603,13 @@
         container.setMembersMargin(30);
         createWQInputTable();
         createWQInputPanel();
+
         // the initial panel is the Single-W panel.
-        double[] values = getSingleW();
-        wArrayPanel = new DoubleArrayPanel(
-            MESSAGE.unitWSingle(), values, this);
-        container.addMember(wArrayPanel);
+        double[] values = getSingleQ();
+        qArrayPanel = new DoubleArrayPanel(
+            MESSAGE.unitQSingle(), values, this);
+        container.addMember(qArrayPanel);
+
         helperContainer.addChild(wqTable);
         layout.addMember(modeForm);
         layout.addMember(container);
@@ -524,7 +656,7 @@
         modes.setNumCols(1);
 
         LinkedHashMap initial = new LinkedHashMap();
-        initial.put(FIELD_WQ, FIELD_WQ_W);
+        initial.put(FIELD_WQ, FIELD_WQ_Q);
         initial.put(FIELD_MODE, FIELD_MODE_SINGLE);
         modes.setValues(initial);
 
@@ -800,7 +932,6 @@
 
     protected void updatePanels(String wqMode, String inputMode) {
         container.removeMembers(container.getMembers());
-        GWT.log("updating Panel and Table");
         if (wqMode.equals(FIELD_WQ_W)) {
             if (inputMode.equals(FIELD_MODE_SINGLE)) {
                 // Single W mode
@@ -1146,7 +1277,10 @@
                     }
                     tableData = wqi;
                     addWQInfo(wqi);
-                    updatePanels(FIELD_WQ_W, FIELD_MODE_SINGLE);
+
+                    String wq = (String) modes.getValue(FIELD_WQ);
+                    String sr = (String) modes.getValue(FIELD_MODE);
+                    updatePanels(wq, sr);
                 }
             }
         );

http://dive4elements.wald.intevation.org