changeset 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 (2011-05-24)
parents bac8e6ea277d
children 9e2b151770bd
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java
diffstat 5 files changed, 256 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue May 24 11:22:05 2011 +0000
+++ b/flys-client/ChangeLog	Tue May 24 16:22:34 2011 +0000
@@ -1,3 +1,15 @@
+2011-05-24  Ingo Weinzierl <ingo@intevation.de>
+
+	  ISSUE-91
+	  ISSUE-40 (part II/II)
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java,
+	  src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java:
+	  Read default values in those panels and fill the form items with that
+	  data.
+	  
 2011-05-24  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Tue May 24 11:22:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Tue May 24 16:22:34 2011 +0000
@@ -126,12 +126,21 @@
 
             LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
 
-            boolean firstItem = true;
+            boolean  defaultSet = false;
+            boolean  first      = true;
+
+            DataItem def      = d.getDefault();
+            String   defValue = def != null ? def.getStringValue() : null;
+
+            if (defValue != null && defValue.length() > 0) {
+                initial.put(d.getLabel(), def.getStringValue());
+                defaultSet = true;
+            }
 
             for (DataItem item: d.getItems()) {
-                if (firstItem) {
+                if (!defaultSet && first) {
                     initial.put(d.getLabel(), item.getStringValue());
-                    firstItem = false;
+                    first = false;
                 }
 
                 it.put(item.getStringValue(), item.getLabel());
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Tue May 24 11:22:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Tue May 24 16:22:34 2011 +0000
@@ -3,6 +3,7 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.widgets.Canvas;
@@ -91,12 +92,12 @@
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
 
-        initDefaults(data);
-
         Label label   = new Label(MESSAGES.location ());
         Canvas widget = createWidget(data);
         Canvas submit = getNextButton();
 
+        initDefaults(data);
+
         createLocationTable();
 
         widget.setHeight(50);
@@ -179,6 +180,22 @@
      * @param list The DataList container that stores the Data objects.
      */
     protected void initDefaults(DataList list) {
+        Data data = list.get(0);
+
+        if (data == null) {
+            return;
+        }
+
+        DataItem def   = data.getDefault();
+        String   value = def.getStringValue();
+
+        try {
+            double d = Double.parseDouble(value);
+            setLocationValues(new double[] { d } );
+        }
+        catch (NumberFormatException nfe) {
+            // could not parse, dont know what to do else
+        }
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Tue May 24 11:22:05 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Tue May 24 16:22:34 2011 +0000
@@ -183,10 +183,81 @@
         layout.setHeight(25 + listHeight);
         layout.setWidth(350);
 
+        initUserDefaults(dataList);
+
         return layout;
     }
 
 
+    protected void initUserDefaults(DataList dataList) {
+
+        initUserWQValues(dataList);
+        initUserWQMode(dataList);
+    }
+
+
+    protected void initUserWQMode(DataList dataList) {
+        List<Data> allData = dataList.getAll();
+
+        Data     dDef  = getData(allData, "wq_mode");
+        DataItem def   = dDef != null ? dDef.getDefault() : null;
+        String   value = def != null ? def.getStringValue() : null;
+
+        if (value != null && value.equals(FIELD_WQ_Q)) {
+            modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q);
+        }
+        else {
+            modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W);
+        }
+    }
+
+
+    protected void initUserWQValues(DataList dataList) {
+        List<Data> allData = dataList.getAll();
+
+        Data     dDef  = getData(allData, "wq_values");
+        DataItem def   = dDef != null ? dDef.getDefault() : null;
+        String   value = def != null ? def.getStringValue() : null;
+
+        if (value == null || value.length() == 0) {
+            return;
+        }
+
+        String[] lines = value.split(GAUGE_SEPARATOR);
+
+        if (lines == null || lines.length == 0) {
+            return;
+        }
+
+        for (String line: lines) {
+            String[] cols  = line.split(GAUGE_PART_SEPARATOR);
+            String   title = createLineTitle(line);
+
+            if (cols == null || cols.length < 3) {
+                continue;
+            }
+
+            String[] strValues = cols[2].split(VALUE_SEPARATOR);
+            double[] values    = new double[strValues.length];
+
+            int idx = 0;
+
+            for (String strValue: strValues) {
+                try {
+                    values[idx++] = Double.valueOf(strValue);
+                }
+                catch (NumberFormatException nfe) {
+                    // do nothing
+                }
+            }
+
+            String           key = cols[0] + GAUGE_PART_SEPARATOR + cols[1];
+            DoubleArrayPanel dap = wqranges.get(key);
+            dap.setValues(values);
+        }
+    }
+
+
     protected Canvas createList(DataList dataList) {
         VLayout layout = new VLayout();
 
@@ -199,7 +270,6 @@
                 createLineTitle(title), null, this, TitleOrientation.LEFT);
 
             wqranges.put(title, dap);
-
             layout.addMember(dap);
         }
 
--- 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