changeset 1595:e53d773e6992

Display inserted W/Q values in WQSimpleArrayPanel. flys-client/trunk@3908 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 03 Feb 2012 15:27:46 +0000
parents ddf43791244c
children 0685a4969e93
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java
diffstat 6 files changed, 168 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/ChangeLog	Fri Feb 03 15:27:46 2012 +0000
@@ -1,3 +1,21 @@
+2012-02-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/server/DataFactory.java: Read
+	  double values inserted for doublearray data types.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
+	  Create new instances of DoubleArrayData if the data type is "doublearray".
+
+	* src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java:
+	  Do no longer subclass DefaultData but implement the whole stuff we need
+	  for a Data class.
+
+	* src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java:
+	  Added a method getValues() that returns the raw int values as array.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java:
+	  Display the W/Q input values in createOld().
+
 2012-02-03	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java	Fri Feb 03 15:27:46 2012 +0000
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
@@ -22,7 +23,7 @@
 import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
-import de.intevation.flys.client.shared.model.IntegerArrayData;
+import de.intevation.flys.client.shared.model.DoubleArrayData;
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
 import de.intevation.flys.client.client.FLYSConstants;
 
@@ -71,7 +72,7 @@
     @Override
     public Canvas createOld(DataList dataList) {
         IntegerOptionsData modeData   = findOptionsData(dataList);
-        IntegerArrayData   valuesData = findValuesData(dataList);
+        DoubleArrayData    valuesData = findValuesData(dataList);
 
         DataItem[] modeItems   = modeData.getItems();
         DataItem[] valuesItems = valuesData.getItems();
@@ -87,8 +88,7 @@
         mode.setHeight(20);
         mode.setWidth(150);
 
-        Label values = new Label(valuesItems[0].getLabel());
-        values.setHeight(20);
+        Canvas values = createOldValues(modeData, valuesData);
         values.setWidth(150);
 
         valueContainer.addMember(mode);
@@ -152,14 +152,35 @@
     }
 
 
-    protected IntegerArrayData findValuesData(DataList dataList) {
-        IntegerArrayData data = null;
+    protected Canvas createOldValues(
+        IntegerOptionsData modeData,
+        DoubleArrayData valuesData
+    ) {
+        NumberFormat nf = NumberFormat.getDecimalFormat();
+
+        DataItem[] items = modeData.getItems();
+        String     unit  = items[0].getStringValue().equals("0") ? "cm" : "q³/s";
+
+        VLayout layout = new VLayout();
+
+        for (double val: valuesData.getValues()) {
+            Label tmp = new Label(nf.format(val) + " " + unit);
+            tmp.setHeight(20);
+            layout.addMember(tmp);
+        }
+
+        return layout;
+    }
+
+
+    protected DoubleArrayData findValuesData(DataList dataList) {
+        DoubleArrayData data = null;
 
         for (int i = 0, n = dataList.size(); i < n; i++) {
             Data tmp = dataList.get(i);
 
-            if (tmp instanceof IntegerArrayData) {
-                return (IntegerArrayData) tmp;
+            if (tmp instanceof DoubleArrayData) {
+                return (DoubleArrayData) tmp;
             }
         }
 
@@ -217,7 +238,7 @@
 
 
     protected Canvas createValuesForm(DataList dataList) {
-        IntegerArrayData data = findValuesData(dataList);
+        DoubleArrayData data = findValuesData(dataList);
 
         if (data == null) {
             return new Label("NO VALUES GIVEN!");
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Fri Feb 03 15:27:46 2012 +0000
@@ -23,6 +23,7 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.DefaultOutputMode;
+import de.intevation.flys.client.shared.model.DoubleArrayData;
 import de.intevation.flys.client.shared.model.DoubleRangeData;
 import de.intevation.flys.client.shared.model.IntegerArrayData;
 import de.intevation.flys.client.shared.model.IntegerRangeData;
@@ -182,6 +183,9 @@
 
                 list.add(new IntegerOptionsData(name, label, opts));
             }
+            else if (type.equals("doublearray")) {
+                list.add(new DoubleArrayData(name, label, null));
+            }
             else {
                 logger.warn("Unrecognized Dynamic data type.");
                 NodeList   choices   = ClientProtocolUtils.getItemNodes(d);
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Fri Feb 03 15:27:46 2012 +0000
@@ -188,7 +188,7 @@
             }
         }
 
-        return new IntegerArrayData(name, name, integers);
+        return new IntegerArrayData(name, items[0].getLabel(), integers);
     }
 
 
@@ -202,7 +202,22 @@
      * @return an instance of DoubleArrayData.
      */
     protected static Data createDoubleArrayData(Element ele, String name) {
-        return new DoubleArrayData(name, name, extractDataItems(ele));
+        DataItem[] items    = extractDataItems(ele);
+        String     rawValue = items[0].getStringValue();
+
+        String[] values  = rawValue.split(";");
+        double[] doubles = new double[values.length];
+
+        for (int i = 0; i < values.length; i++) {
+            try {
+                doubles[i] = Double.valueOf(values[i]);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Error while parsing DoubleArrayData: " + nfe);
+            }
+        }
+
+        return new DoubleArrayData(name, items[0].getLabel(), doubles);
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java	Fri Feb 03 15:27:46 2012 +0000
@@ -4,18 +4,103 @@
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class DoubleArrayData extends DefaultData {
+public class DoubleArrayData implements Data {
 
     public static final String TYPE = "doublearray";
 
 
+    protected String label;
+    protected String description;
+
+    protected double[] values;
+
+
     public DoubleArrayData() {
-        super();
     }
 
 
-    public DoubleArrayData(String name, String description, DataItem[] items) {
-        super(name, description, TYPE, items);
+    public DoubleArrayData(String label, String description, double[] values) {
+        this.label       = label;
+        this.description = description;
+        this.values      = values;
+    }
+
+
+    /**
+     * Returns the label of the item.
+     *
+     * @return the label.
+     */
+    public String getLabel() {
+        return label;
+    }
+
+
+    /**
+     * Returns the description of the item.
+     *
+     * @return the description.
+     */
+    public String getDescription() {
+        return description;
+    }
+
+
+    /**
+     * Returns the type of the item.
+     *
+     * @return the type.
+     */
+    public String getType() {
+        return TYPE;
+    }
+
+
+    /**
+     * Returns a DataItem which value is a string that consists of the double
+     * values separated by a ';'.
+     *
+     * @return the DataItem.
+     */
+    public DataItem[] getItems() {
+        if (values == null || values.length == 0) {
+            return new DataItem[0];
+        }
+
+        StringBuilder sb    = new StringBuilder();
+        boolean       first = true;
+
+        for (double value: values) {
+            if (first) {
+                sb.append(String.valueOf(value));
+            }
+            else {
+                sb.append(";" + String.valueOf(value));
+            }
+        }
+
+        String  value = sb.toString();
+        DataItem item = new DefaultDataItem(value, value, value);
+
+        return new DataItem[] { item };
+    }
+
+
+    /**
+     * Returns the values as array.
+     *
+     * @return the values as array.
+     */
+    public double[] getValues() {
+        return values;
+    }
+
+
+    /**
+     * @return always null.
+     */
+    public DataItem getDefault() {
+        return null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java	Fri Feb 03 15:04:12 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java	Fri Feb 03 15:27:46 2012 +0000
@@ -84,6 +84,16 @@
 
 
     /**
+     * Returns the values as array.
+     *
+     * @return the values as array.
+     */
+    public int[] getValues() {
+        return values;
+    }
+
+
+    /**
      * @return always null.
      */
     public DataItem getDefault() {

http://dive4elements.wald.intevation.org