changeset 246:ccba1a0b743e

The WQAdaptedInputPanel displays input fields for each gauge and returns the correct w/q values now. flys-client/trunk@1831 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 05 May 2011 08:09:03 +0000
parents 1e73d5a4859c
children 4a684d29404f
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java
diffstat 7 files changed, 168 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/ChangeLog	Thu May 05 08:09:03 2011 +0000
@@ -1,3 +1,21 @@
+2011-05-05  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java: Added
+	  new i18n displayed in the WQAdaptedInputPanel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java:
+	  The list of input fields for each intersected gauge is created now. The
+	  correct w/q values will be returned after the submit button has been
+	  clicked.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java:
+	  The orientation of the field label might be adjusted using a new
+	  constructor parameter. Furthermore, there is a new method (which has no
+	  parameters) that returns the double values inserted in this panel.
+
 2011-05-04  Raimund Renkert <rrenkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/WQInfoServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu May 05 08:09:03 2011 +0000
@@ -88,6 +88,8 @@
 
     String wqTitle();
 
+    String wqadaptedTitle();
+
     String wqW();
 
     String wqQ();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu May 05 08:09:03 2011 +0000
@@ -39,6 +39,7 @@
 riverside = Riverside
 
 wqTitle = Input for W/Q Data
+wqadaptedTitle = Input for W/Q Data
 wqW = W at Gauge [cm]
 wqQ = Q [m³/s]
 wqSingle = Single values
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu May 05 08:09:03 2011 +0000
@@ -39,6 +39,7 @@
 riverside = Flussseite
 
 wqTitle = Eingabe für W/Q Daten
+wqadaptedTitle = Eingabe für W/Q Daten
 wqW = W am Pegel [cm]
 wqQ = Q [m³/s]
 wqSingle = Einzelwerte
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu May 05 08:09:03 2011 +0000
@@ -39,6 +39,7 @@
 riverside = Riverside
 
 wqTitle = Input for W/Q Data
+wqadaptedTitle = Input for W/Q Data
 wqW = W at Gauge [cm]
 wqQ = Q [m³/s]
 wqSingle = Single values
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Thu May 05 08:09:03 2011 +0000
@@ -26,6 +26,15 @@
     public static final String FIELD_NAME = "doublearray";
 
 
+    public DoubleArrayPanel(
+        String title,
+        double[] values,
+        BlurHandler handler)
+    {
+        this(title, values, handler, TitleOrientation.RIGHT);
+    }
+
+
     /**
      * Creates a new form with a single input field that displays an array of
      * double values.
@@ -38,7 +47,8 @@
     public DoubleArrayPanel(
         String title,
         double[] values,
-        BlurHandler handler)
+        BlurHandler handler,
+        TitleOrientation titleOrientation)
     {
         ti                 = new TextItem(FIELD_NAME);
         StaticTextItem sti = new StaticTextItem("staticarray");
@@ -49,8 +59,14 @@
 
         ti.addBlurHandler(handler);
 
-        setFields(ti, sti);
-        setTitleOrientation(TitleOrientation.RIGHT);
+        if (titleOrientation == TitleOrientation.RIGHT) {
+            setFields(ti, sti);
+        }
+        else {
+            setFields(sti, ti);
+        }
+
+        setTitleOrientation(titleOrientation);
         setNumCols(2);
 
         if (values == null) {
@@ -187,5 +203,15 @@
 
         return values;
     }
+
+
+    /**
+     * Returns the double values of this panel.
+     *
+     * @return the double values of this panel.
+     */
+    public double[] getInputValues() {
+        return getInputValues(ti);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Wed May 04 14:54:38 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Thu May 05 08:09:03 2011 +0000
@@ -1,7 +1,13 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import com.google.gwt.core.client.GWT;
 
+import com.smartgwt.client.types.TitleOrientation;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
@@ -16,6 +22,8 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 
+import de.intevation.flys.client.client.FLYSConstants;
+
 
 /**
  * This UIProvider creates a widget to enter W or Q data for discharge
@@ -27,17 +35,34 @@
 extends      AbstractUIProvider
 implements   ChangeHandler, BlurHandler
 {
+    public static final String FIELD_WQ_MODE = "wq_mode";
+
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    /** Stores the input panels related to their keys.*/
+    protected Map<String, DoubleArrayPanel> wqranges;
+
+
+
     public WQAdaptedInputPanel() {
+        wqranges = new HashMap<String, DoubleArrayPanel>();
     }
 
 
     public Canvas create(DataList data) {
-        GWT.log("HELLO INGO");
         Canvas submit = getNextButton();
+        Canvas widget = createWidget(data);
+        Label  label  = new Label(MSG.wqadaptedTitle());
+
+        label.setHeight(25);
 
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
 
+        layout.addMember(label);
+        layout.addMember(widget);
         layout.addMember(submit);
 
         return layout;
@@ -50,19 +75,103 @@
     }
 
 
+    protected Canvas createWidget(DataList dataList) {
+        VLayout layout = new VLayout();
+
+        List<Data> data = dataList.getAll();
+
+        for (Data d: data) {
+            String name = d.getLabel();
+
+            if (name.equals(FIELD_WQ_MODE)) {
+                continue;
+            }
+
+            DataItem[] items = d.getItems();
+
+            for (DataItem item: items) {
+                String title = item.getLabel();
+
+                DoubleArrayPanel dap = new DoubleArrayPanel(
+                    createLineTitle(title), null, this, TitleOrientation.LEFT);
+
+                wqranges.put(title, dap);
+
+                layout.addMember(dap);
+            }
+        }
+
+        return layout;
+    }
+
+
+    public String createLineTitle(String key) {
+        String[] splitted = key.split(";");
+
+        return splitted[0] + " - " + splitted[1];
+    }
+
+
     public Data[] getData() {
-        DataItem item = new DefaultDataItem("wq_mode", "wq_mode", "bla");
+        Data mode   = getWQMode();
+        Data values = getWQValues();
 
+        return new Data[] { mode, values };
+    }
+
+
+    protected Data getWQMode() {
+        // TODO Search for the correct value!
+        DataItem item = new DefaultDataItem("wq_mode", "wq_mode", "q");
         Data mode = new DefaultData(
             "wq_mode", null, null, new DataItem[] { item });
 
+        return mode;
+    }
+
+
+    protected Data getWQValues() {
+        String wqvalue = null;
+
+        Iterator<String> iter = wqranges.keySet().iterator();
+        while (iter.hasNext()) {
+            String           key = iter.next();
+            DoubleArrayPanel dap = wqranges.get(key);
+
+            double[] values = dap.getInputValues();
+            if (wqvalue == null) {
+                wqvalue = createValueString(key, values);
+            }
+            else {
+                wqvalue += ":" + createValueString(key, values);
+            }
+        }
+
         DataItem valueItem = new DefaultDataItem(
-            "wq_values", "wq_values",
-            "0.0;70.2;9.6");
+            "wq_values", "wq_values", wqvalue);
         Data values = new DefaultData(
             "wq_values", null, null, new DataItem[] { valueItem });
 
-        return new Data[] { mode, values };
+        return values;
+    }
+
+
+    protected String createValueString(String key, double[] values) {
+        StringBuilder sb = new StringBuilder();
+
+        boolean first = true;
+
+        for (double value: values) {
+            if (!first) {
+                sb.append(",");
+            }
+
+            sb.append(Double.toString(value));
+
+            first = false;
+        }
+
+        return key + ";" + sb.toString();
     }
 
 
@@ -72,7 +181,8 @@
 
 
     public void onBlur(BlurEvent event) {
-        // TODO IMPLEMENT ME
+        DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm();
+        dap.validateForm(event.getItem());
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org