changeset 1593:ff9d71469b7c

Adjusted to be able to feed data to reference curves. flys-client/trunk@3902 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 03 Feb 2012 13:57:27 +0000
parents f34bbb5fb6d2
children ddf43791244c
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleRangeData.java
diffstat 5 files changed, 178 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Feb 03 11:15:09 2012 +0000
+++ b/flys-client/ChangeLog	Fri Feb 03 13:57:27 2012 +0000
@@ -1,3 +1,19 @@
+2012-02-03  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Improvements in relation to reference curves.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
+	  Parse min/max values.
+
+	* src/main/java/de/intevation/flys/client/shared/model/DoubleRangeData.java:
+	  New.
+
+	* src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java:
+	  Refactored to use data item name as given (take first).
+
+	* src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java:
+	  Exploit former refacorisation.
+
 2012-02-03  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java	Fri Feb 03 11:15:09 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPanel.java	Fri Feb 03 13:57:27 2012 +0000
@@ -38,8 +38,6 @@
 
 /**
  * This UIProvider serves as base for UI Providers to enter a single location (km).
- *
- * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public abstract class LocationPanel
 extends               AbstractUIProvider
@@ -56,11 +54,12 @@
     /** The values entered in the location mode. */
     protected double[] values;
 
+    /** Name of the data item that keeps this location(s). */
+    protected String dataItemName;
+
     /** The input panel for locations. */
     protected DoubleArrayPanel locationPanel;
 
-    /** Name of the data item that keeps locations. */
-    protected String DATA_ITEM_NAME = "ld_locations";
 
     /**
      * Creates a new LocationDistancePanel instance.
@@ -80,6 +79,8 @@
      */
     @Override
     public Canvas create(DataList data) {
+        findDataItemName(data);
+
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
 
@@ -100,14 +101,25 @@
     }
 
 
+    public void findDataItemName(DataList list) {
+        this.dataItemName = list.getAll().get(0).getLabel();
+    }
+
+
+    public String getDataItemName() {
+        return this.dataItemName;
+    }
+
 
     /**
      * This method creates a Canvas element showing the old Data objects in the
      * DataList <i>data</i>.
      */
     public Canvas createOld(DataList dataList) {
+        findDataItemName(dataList);
+
         List<Data> items = dataList.getAll();
-        Data dLocation = getData(items, DATA_ITEM_NAME);
+        Data dLocation = getData(items, getDataItemName());
         DataItem[] loc = dLocation.getItems();
 
         HLayout layout = new HLayout();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Fri Feb 03 11:15:09 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Fri Feb 03 13:57:27 2012 +0000
@@ -52,9 +52,6 @@
     /** The table data. */
     protected DistanceInfoObject[] tableData;
 
-    /** Name of the data item that keeps locations. */
-    protected String DATA_ITEM_NAME = "ld_locations";
-
     /** The input helper (usually right side, table to click on, values are
      * then entered in the texfield. */
     protected LocationPicker picker;
@@ -78,6 +75,8 @@
      */
     @Override
     public Canvas create(DataList data) {
+        findDataItemName(data);
+
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
 
@@ -109,7 +108,6 @@
     protected void initDefaults(DataList list) {
         Data data = list.get(0);
 
-        /*
         // Compatibility with MinMax- DataItems:
         RangeData rangeData = null;
 
@@ -126,9 +124,6 @@
             max = Double.parseDouble(rangeData.getDefaultUpper().toString());
             // catch ..?
         }
-        */
-
-        if (false) {}
         else {
             DataItem[] items = data.getItems();
             DataItem   iMin  = getDataItem(items, "min");
@@ -145,22 +140,24 @@
             }
         }
 
-        DataItem def   = data.getDefault();
-        String   value = def.getStringValue();
+        DataItem def = data.getDefault();
+        if (def != null) {
+            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
+            try {
+                double d = Double.parseDouble(value);
+                setLocationValues(new double[] { d } );
+            }
+            catch (NumberFormatException nfe) {
+                // could not parse, dont know what to do else
+            }
         }
     }
 
 
     protected Canvas createWidget(DataList data) {
         VLayout layout = new VLayout();
-        inputLayout      = new HLayout();
+        inputLayout    = new HLayout();
 
         // The initial view will display the location input mode.
         locationPanel = new DoubleArrayPanel(
@@ -187,27 +184,6 @@
 
 
     /**
-     * This method grabs the Data with name <i>name</i> from the list and
-     * returns it.
-     *
-     * @param items A list of Data.
-     * @param name The name of the Data that we are searching for.
-     *
-     * @return the Data with the name <i>name</i>.
-     */
-    @Override
-    protected Data getData(List<Data> data, String name) {
-        for (Data d: data) {
-            if (name.equals(d.getLabel())) {
-                return d;
-            }
-        }
-
-        return null;
-    }
-
-
-    /**
      * This method returns the selected data.
      *
      * @return the selected/inserted data.
@@ -218,7 +194,7 @@
         Data[] data = new Data[values.length+1];
 
         for (int i = 0; i < values.length; i++) {
-            data[i] = createDataArray(DATA_ITEM_NAME,
+            data[i] = createDataArray(getDataItemName(),
                 Double.valueOf(values[i]).toString());
         }
         data[values.length] = createDataArray("ld_mode", "locations");
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Fri Feb 03 11:15:09 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Fri Feb 03 13:57:27 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.DoubleRangeData;
 import de.intevation.flys.client.shared.model.IntegerArrayData;
 import de.intevation.flys.client.shared.model.IntegerRangeData;
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
@@ -187,6 +188,15 @@
                 DataItem[] dataItems = extractCurrentDataItems(choices);
                 DataItem   def       = extractDefaultDataItem(d);
 
+                String min = ClientProtocolUtils.getMinNode(d);
+                String max = ClientProtocolUtils.getMaxNode(d);
+                if (min != null && max != null) {
+                    list.add(new DoubleRangeData(
+                        name, label,
+                        Double.valueOf(min), Double.valueOf(max),
+                        Double.valueOf(min), Double.valueOf(max)));
+                }
+
                 list.add(new DefaultData(name, label, null, dataItems, def));
             }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleRangeData.java	Fri Feb 03 13:57:27 2012 +0000
@@ -0,0 +1,121 @@
+package de.intevation.flys.client.shared.model;
+
+
+public class DoubleRangeData implements RangeData {
+
+    public static final String TYPE = "doublerange";
+
+
+    protected String label;
+    protected String description;
+
+    protected double lower;
+    protected double upper;
+
+    protected Double defLower;
+    protected Double defUpper;
+
+
+    public DoubleRangeData() {
+    }
+
+
+    public DoubleRangeData(String label, String desc, double lower, double upper) {
+        this(label, desc, lower, upper, null, null);
+    }
+
+
+    public DoubleRangeData(
+        String  label,
+        String  desc,
+        double     lower,
+        double     upper,
+        Double defLower,
+        Double defUpper
+    ) {
+        this.label       = label;
+        this.description = desc;
+        this.lower       = lower;
+        this.upper       = upper;
+        this.defLower    = defLower;
+        this.defUpper    = defUpper;
+    }
+
+
+    /**
+     * 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 "doublerange";
+    }
+
+
+    /**
+     * Returns a DataItem which value is a string that consists of the min and
+     * max value separated by a ';'.
+     *
+     * @return the DataItem.
+     */
+    public DataItem[] getItems() {
+        String theMin = String.valueOf(lower);
+        String theMax = String.valueOf(upper);
+
+        String label = theMin + " - " + theMax;
+        String value = theMin + ";" + theMax;
+
+        DataItem item  = new DefaultDataItem(label, label, value);
+
+        return new DataItem[] { item };
+    }
+
+
+    /**
+     * @return always null.
+     */
+    public DataItem getDefault() {
+        return null;
+    }
+
+
+    public Object getLower() {
+        return lower;
+    }
+
+
+    public Object getUpper() {
+        return upper;
+    }
+
+
+    public Object getDefaultLower() {
+        return defLower;
+    }
+
+
+    public Object getDefaultUpper() {
+        return defUpper;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org