changeset 47:45ae03d9ca2b

Implemented the getData() method of the WQInputPanel. flys-client/trunk@1495 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Mar 2011 10:54:41 +0000 (2011-03-17)
parents 0d4795b4f284
children 6e191588a295
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java
diffstat 2 files changed, 168 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Mar 17 10:28:03 2011 +0000
+++ b/flys-client/ChangeLog	Thu Mar 17 10:54:41 2011 +0000
@@ -1,3 +1,9 @@
+2011-03-17  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java:
+	  Implemented some methods to retrieve the data that have been entered by
+	  the user. The getData() method retrieves data now!
+
 2011-03-17  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Mar 17 10:28:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Mar 17 10:54:41 2011 +0000
@@ -17,6 +17,9 @@
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Data;
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DefaultData;
+import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.client.FLYSMessages;
 
 
@@ -191,9 +194,166 @@
      * @return the selected/inserted data.
      */
     public Data[] getData() {
-        // TODO Implement me
+        return new Data[] {
+            getDataMode(),
+            getDataFrom(),
+            getDataTo(),
+            getDataStep() };
+    }
 
-        return null;
+
+    /**
+     * Returns the Data object for the 'mode' attribute.
+     *
+     * @return the Data object for the 'mode' attribute.
+     */
+    protected Data getDataMode() {
+        String wqMode = modes.getValueAsString(FIELD_WQ);
+        DataItem item = new DefaultDataItem("wq_mode", "wq_mode", wqMode);
+        return new DefaultData(
+            "wq_mode", null, null, new DataItem[] { item }, null);
+    }
+
+
+    /**
+     * Returns the Data object for the 'from' attribute.
+     *
+     * @return the Data object for the 'from' attribute.
+     */
+    protected Data getDataFrom() {
+        String value  = Double.valueOf(getFinalFrom()).toString();
+        DataItem item = new DefaultDataItem("wq_from", "wq_from", value);
+        return new DefaultData(
+            "wq_from", null, null, new DataItem[] { item }, null);
+    }
+
+
+    /**
+     * Returns the Data object for the 'to' attribute.
+     *
+     * @return the Data object for the 'to' attribute.
+     */
+    protected Data getDataTo() {
+        String value  = Double.valueOf(getFinalTo()).toString();
+        DataItem item = new DefaultDataItem("wq_to", "wq_to", value);
+        return new DefaultData(
+            "wq_to", null, null, new DataItem[] { item }, null);
+    }
+
+
+    /**
+     * Returns the Data object for the 'step' attribute.
+     *
+     * @return the Data object for the 'step' attribute.
+     */
+    protected Data getDataStep() {
+        String value  = Double.valueOf(getFinalStep()).toString();
+        DataItem item = new DefaultDataItem("wq_step","wq_step", value);
+        return new DefaultData(
+            "wq_step", null, null, new DataItem[] { item }, null);
+    }
+
+
+    /**
+     * Returns the value of 'from' depending on the selected input mode.
+     *
+     * @return the value of 'from' depending on the selected input mode.
+     */
+    protected double getFinalFrom() {
+        boolean wMode     = isWMode();
+        boolean rangeMode = isRangeMode();
+
+        if (rangeMode) {
+            return wMode ? getFromW() : getFromQ();
+
+        }
+        else {
+            double[] values = wMode ? getSingleW() : getSingleQ();
+            double   value  = Double.MAX_VALUE;
+
+            for (double v: values) {
+                value = value < v ? value : v;
+            }
+
+            return value;
+        }
+    }
+
+
+    /**
+     * Returns the value of 'to' depending on the selected input mode.
+     *
+     * @return the value of 'to' depending on the selected input mode.
+     */
+    protected double getFinalTo() {
+        boolean wMode     = isWMode();
+        boolean rangeMode = isRangeMode();
+
+        if (rangeMode) {
+            return wMode ? getToW() : getToQ();
+
+        }
+        else {
+            double[] values = wMode ? getSingleW() : getSingleQ();
+            double   value  = Double.MIN_VALUE;
+
+            for (double v: values) {
+                value = value > v ? value : v;
+            }
+
+            return value;
+        }
+    }
+
+
+    /**
+     * Returns the value of 'step' depending on the selected input mode.
+     *
+     * @return the value of 'step' depending on the selected input mode.
+     */
+    protected double getFinalStep() {
+        boolean wMode     = isWMode();
+        boolean rangeMode = isRangeMode();
+
+        if (rangeMode) {
+            // we have no field to enter the 'step' attribute in the
+            // range mode
+            return 0.0;
+        }
+        else {
+            if (wMode) {
+                return getStepW();
+            }
+            else {
+                // we have no field to enter the 'step' attribute in the
+                // range mode
+                return getStepQ();
+            }
+        }
+    }
+
+
+    /**
+     * Determines the range/single mode.
+     *
+     * @return true if the range mode is activated.
+     */
+    public boolean isRangeMode() {
+        String rMode = modes.getValueAsString(FIELD_MODE);
+
+        return rMode.equals(FIELD_MODE_RANGE) ? true : false;
+    }
+
+
+    /**
+     * Determines the w/q mode.
+     *
+     * @return true, if the W mode is activated.
+     */
+    public boolean isWMode() {
+        String wq = modes.getValueAsString(FIELD_WQ);
+
+        return wq.equals(FIELD_WQ_W) ? true : false;
     }
 
 

http://dive4elements.wald.intevation.org