diff flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.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 e4f0bef52689
children 5274b9317e40
line wrap: on
line diff
--- 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);
         }
 

http://dive4elements.wald.intevation.org