changeset 2428:f405eb46762e

Refactored the wq input data fields. flys-client/trunk@4066 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 16 Feb 2012 12:39:11 +0000
parents 29e28bb404ec
children c837669643ac
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java
diffstat 3 files changed, 110 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Feb 16 12:00:47 2012 +0000
+++ b/flys-client/ChangeLog	Thu Feb 16 12:39:11 2012 +0000
@@ -1,3 +1,12 @@
+2012-02-16  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Refactored the wq input data fields.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java:
+	  Refactored the wq input data fields. The data fields wq_mode, wq_free
+	  and wq_selection are now of type 'boolean'.
+
 2012-02-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Thu Feb 16 12:00:47 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Thu Feb 16 12:39:11 2012 +0000
@@ -499,7 +499,11 @@
 
     protected Data getWQMode() {
         String wqMode = modes.getValueAsString(FIELD_WQ_MODE);
-        DataItem item = new DefaultDataItem("wq_mode", "wq_mode", wqMode);
+        String value = "false";
+        if (wqMode.equals("Q")) {
+            value = "true";
+        }
+        DataItem item = new DefaultDataItem("wq_mode", "wq_mode", value);
         Data mode = new DefaultData(
             "wq_mode", null, null, new DataItem[] { item });
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Feb 16 12:00:47 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu Feb 16 12:39:11 2012 +0000
@@ -72,7 +72,7 @@
     public static final String FIELD_WQ_Q = "Q";
 
     /** The constant field value for Q input mode.*/
-    public static final String FIELD_WQ_Q_GAUGE = "Q_GAUGE";
+    public static final String FIELD_WQ_Q_FREE = "QFREE";
 
     /** The constant field name for choosing single values or range.*/
     public static final String FIELD_MODE = "mode";
@@ -285,7 +285,7 @@
 
         DataItem[] mode = dMode.getItems();
         String strMode  = mode[0].getStringValue();
-        boolean wMode   = strMode.equals(FIELD_WQ_W);
+        boolean isQMode   = Boolean.valueOf(strMode);
 
         DataItem[] free = dFree.getItems();
         String  strFree = free[0].getStringValue();
@@ -300,14 +300,14 @@
         VLayout vLabel = null;
 
         DataItem[] selItem = dSelection.getItems();
-        String     sel     = selItem != null
-            ? selItem[0].getStringValue()
-            : "";
+        boolean    isRange = selItem != null
+            ? Boolean.valueOf(selItem[0].getStringValue())
+            : false;
 
-        if (sel.equals("single")) {
+        if (!isRange) {
             DataItem[] single = dSingle.getItems();
 
-            vLabel = wMode
+            vLabel = !isQMode
                 ? createWString(single[0])
                 : createQString(single[0]);
         }
@@ -316,7 +316,7 @@
             DataItem[] to   = dTo.getItems();
             DataItem[] step = dStep.getItems();
 
-            vLabel = wMode
+            vLabel = !isQMode
                 ? createWString(from[0], to[0], step[0])
                 : createQString(from[0], to[0], step[0]);
         }
@@ -324,7 +324,7 @@
         VLayout selectedLayout = new VLayout();
         String  wqMode         = null;
 
-        if (wMode) {
+        if (!isQMode) {
             wqMode = MESSAGE.wqW();
         }
         else {
@@ -406,42 +406,39 @@
 
         Data     m        = getData(allData, "wq_mode");
         DataItem modeItem = m != null ? m.getDefault() : null;
-        String   theMode  = modeItem != null
-            ? modeItem.getStringValue()
-            : "";
+        boolean isQ  = modeItem != null
+            ? Boolean.valueOf(modeItem.getStringValue())
+            : false;
 
         Data     f        = getData(allData, "wq_free");
         DataItem freeItem = f != null ? f.getDefault() : null;
-        String   theFree  = freeItem != null
-            ? freeItem.getStringValue()
-            : null;
+        boolean  isFree   = freeItem != null
+            ? Boolean.valueOf(freeItem.getStringValue())
+            : false;
 
         Data     s            = getData(allData, "wq_selection");
         DataItem sI           = s != null ? s.getDefault() : null;
-        String   theSelection = sI != null ? sI.getStringValue() : null;
+        boolean   isRange      = sI != null
+            ? Boolean.valueOf(sI.getStringValue())
+            : false;
 
-        if (theMode == null || theMode.length() == 0) {
-            return;
+        initUserSingleValues(list, isQ);
+        initUserRangeValues(list, isQ);
+
+        if (isQ) {
+            modes.setValue(FIELD_WQ, isQ);
+        }
+        else {
+            modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q_FREE : FIELD_WQ_Q);
         }
 
-        boolean isW     = theMode.equals(FIELD_WQ_W);
-        boolean isFree  = Boolean.valueOf(theFree);
-        boolean isWFree = theMode.equals(FIELD_WQ_W_FREE);
-
-        initUserSingleValues(list, theMode);
-        initUserRangeValues(list, theMode);
-
-        if (isW || isWFree) {
-            modes.setValue(FIELD_WQ, theMode);
+        if(isRange) {
+            modes.setValue(FIELD_MODE, FIELD_MODE_RANGE);
         }
         else {
-            modes.setValue(FIELD_WQ, isFree ? FIELD_WQ_Q : FIELD_WQ_Q_GAUGE);
+            modes.setValue(FIELD_MODE, FIELD_MODE_SINGLE);
         }
-
-        if (theSelection != null || theSelection.length() > 0) {
-            modes.setValue(FIELD_MODE, theSelection);
-            updatePanels(theMode, theSelection);
-        }
+        updatePanels(isQ, isFree, isRange);
     }
 
 
@@ -451,11 +448,13 @@
      * @param list The DataList that contains the 'wq_single' object.
      * @param theMode The W or Q mode.
      */
-    protected void initUserSingleValues(DataList list, String theMode) {
+    protected void initUserSingleValues(DataList list, boolean isQ) {
         List<Data> allData = list.getAll();
 
+
         Data     s = getData(allData, "wq_single");
         DataItem i = s != null ? s.getDefault() : null;
+        GWT.log("init values: " + i.getStringValue());
 
         if (i != null) {
             String   value = i.getStringValue();
@@ -474,7 +473,7 @@
                 }
             }
 
-            if (theMode.equals("W")) {
+            if (!isQ) {
                 setSingleW(values);
             }
             else {
@@ -490,7 +489,7 @@
      * @param list The DataList that contains the 'wq_single' object.
      * @param theMode The W or Q mode.
      */
-    protected void initUserRangeValues(DataList list, String theMode) {
+    protected void initUserRangeValues(DataList list, boolean isQ) {
         List<Data> allData = list.getAll();
 
         // init range mode values
@@ -512,7 +511,7 @@
                 double to   = Double.valueOf(tS);
                 double step = Double.valueOf(sS);
 
-                if (theMode.equals("W")) {
+                if (!isQ) {
                     setWRangeValues(from, to, step);
                 }
                 else {
@@ -659,8 +658,8 @@
         LinkedHashMap wqValues = new LinkedHashMap();
         wqValues.put(FIELD_WQ_W, MESSAGE.wqW());
         wqValues.put(FIELD_WQ_W_FREE, MESSAGE.wqWFree());
-        wqValues.put(FIELD_WQ_Q, MESSAGE.wqQ());
-        wqValues.put(FIELD_WQ_Q_GAUGE, MESSAGE.wqQGauge());
+        wqValues.put(FIELD_WQ_Q_FREE, MESSAGE.wqQ());
+        wqValues.put(FIELD_WQ_Q, MESSAGE.wqQGauge());
 
         LinkedHashMap modeValues = new LinkedHashMap();
         modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle());
@@ -678,7 +677,7 @@
         modes.setNumCols(1);
 
         LinkedHashMap initial = new LinkedHashMap();
-        initial.put(FIELD_WQ, FIELD_WQ_Q_GAUGE);
+        initial.put(FIELD_WQ, FIELD_WQ_Q);
         initial.put(FIELD_MODE, FIELD_MODE_SINGLE);
         modes.setValues(initial);
 
@@ -884,7 +883,7 @@
 
         return new Data[] {
                 getDataMode(),
-                getQMode(),
+                getFree(),
                 getDataSelectionMode(),
                 getDataSingle(),
                 new DefaultData(
@@ -914,7 +913,7 @@
 
         return new Data[] {
                 getDataMode(),
-                getQMode(),
+                getFree(),
                 getDataSelectionMode(),
                 getDataFrom(),
                 getDataTo(),
@@ -936,17 +935,17 @@
         String wqMode = modes.getValueAsString(FIELD_WQ);
 
         String value = null;
-        if (wqMode.equals(FIELD_WQ_Q) || wqMode.equals(FIELD_WQ_Q_GAUGE)) {
-            GWT.log("getData: FIELD_WQ_Q || FIELD_WQ_Q_GAUGE");
-            value = FIELD_WQ_Q;
+        if (wqMode.equals(FIELD_WQ_Q_FREE) || wqMode.equals(FIELD_WQ_Q)) {
+            GWT.log("getData: FIELD_WQ_Q || FIELD_WQ_Q_FREE");
+            value = "true";
         }
-        else if (wqMode.equals(FIELD_WQ_W_FREE)) {
+/*        else if (wqMode.equals(FIELD_WQ_W_FREE)) {
             GWT.log("getData: FIELD_WQ_W_FREE");
             value = FIELD_WQ_W_FREE;
-        }
+        }*/
         else {
             GWT.log("getData: FIELD_WQ_W");
-            value = FIELD_WQ_W;
+            value = "false";
         }
 
         DataItem item = new DefaultDataItem("wq_mode", "wq_mode", value);
@@ -962,9 +961,16 @@
      *
      * @return the Data object for the 'wq_free' attribute.
      */
-    protected Data getQMode() {
-        String value = isQFree() ? "true" : "false";
-
+    protected Data getFree() {
+        String value = "";
+        GWT.log("--------mode: " + isWMode());
+        if(!isWMode()) {
+            value = isQFree() ? "true" : "false";
+        }
+        else {
+            value = isWFree() ? "true" : "false";
+        }
+        GWT.log("--------free? " + value);
         DataItem item = new DefaultDataItem("wq_free", "wq_free", value);
         return new DefaultData(
             "wq_free", null, null, new DataItem[] { item });
@@ -978,8 +984,15 @@
      */
     protected Data getDataSelectionMode() {
         String wqSelection = modes.getValueAsString(FIELD_MODE);
+
+        String isRange = "true";
+        if (wqSelection.equals(FIELD_MODE_SINGLE)) {
+            isRange = "false";
+        }
+
+        GWT.log("selection mode: " + isRange);
         DataItem item = new DefaultDataItem(
-            "wq_selection", "wq_selection", wqSelection);
+            "wq_selection", "wq_selection", isRange);
 
         return new DefaultData(
             "wq_selection", null, null, new DataItem[] { item });
@@ -1194,17 +1207,18 @@
      */
     public boolean isWMode() {
         String wq = modes.getValueAsString(FIELD_WQ);
-        return wq.equals(FIELD_WQ_W);
+        return wq.contains("W");
     }
 
 
     public boolean isQFree() {
         String wqMode = modes.getValueAsString(FIELD_WQ);
-        return wqMode.equals(FIELD_WQ_Q);
+        return wqMode.equals(FIELD_WQ_Q_FREE);
     }
 
     protected boolean isWFree() {
         String wqMode = modes.getValueAsString(FIELD_WQ);
+        GWT.log("#########wqmode: " + wqMode + " " + FIELD_WQ_W_FREE);
         return wqMode.equals(FIELD_WQ_W_FREE);
     }
 
@@ -1219,34 +1233,42 @@
         DynamicForm form = event.getForm();
         FormItem    item = event.getItem();
 
-        String wqMode    = null;
-        String inputMode = null;
+        boolean isQ     = false;
+        boolean isFree  = false;
+        boolean isRange = false;
 
         if (item.getFieldName().equals(FIELD_MODE)) {
-            wqMode    = form.getValueAsString(FIELD_WQ);
-            inputMode = (String) event.getValue();
+            String wq = form.getValueAsString(FIELD_WQ);
+            GWT.log("mode change: " + wq);
+            isQ     = wq.contains("Q");
+            isFree  = wq.contains("FREE");
+            isRange = ((String) event.getValue()).equals(FIELD_MODE_RANGE);
         }
         else {
-            wqMode    = (String) event.getValue();
-            inputMode = form.getValueAsString(FIELD_MODE);
+            String wq = ((String) event.getValue());
+            GWT.log("else: " + wq);
+            isQ       = wq.contains("Q");
+            isFree    = wq.contains("FREE");
+            isRange   =
+                form.getValueAsString(FIELD_MODE).equals(FIELD_MODE_RANGE);
         }
 
-        if (wqMode.equals("Q")) {
+        if (!isQ) {
             qdTable.hideIconFields();
         }
         else {
             qdTable.showIconFields();
         }
 
-        updatePanels(wqMode, inputMode);
+        updatePanels(isQ, isFree, isRange);
     }
 
 
-    protected void updatePanels(String wqMode, String inputMode) {
+    protected void updatePanels(boolean isQ, boolean isFree, boolean isRange) {
         container.removeMembers(container.getMembers());
 
-        if (wqMode.equals(FIELD_WQ_W) || wqMode.equals(FIELD_WQ_W_FREE)) {
-            if (inputMode.equals(FIELD_MODE_SINGLE)) {
+        if (!isQ) {
+            if (!isRange) {
                 // Single W mode
                 double[] values = getSingleW();
 
@@ -1271,8 +1293,8 @@
 
             tabs.selectTab(0);
         }
-        else if (wqMode.equals(FIELD_WQ_Q)) {
-            if (inputMode.equals(FIELD_MODE_SINGLE)) {
+        else if (isQ && isFree) {
+            if (!isRange) {
                 // Single Q mode
                 double[] values = getSingleQFree();
 
@@ -1297,7 +1319,7 @@
             tabs.selectTab(1);
         }
         else {
-            if (inputMode.equals(FIELD_MODE_SINGLE)) {
+            if (!isRange) {
                 // Single Q mode
                 double[] values = getSingleQ();
 
@@ -1655,7 +1677,12 @@
 
                     String wq = (String) modes.getValue(FIELD_WQ);
                     String sr = (String) modes.getValue(FIELD_MODE);
-                    updatePanels(wq, sr);
+                    GWT.log("sending: " + wq + ", " + sr);
+                    boolean isQ = wq.contains("Q");
+                    boolean isFree = wq.contains("FREE");
+                    boolean isRange = sr.equals(FIELD_MODE_RANGE);
+
+                    updatePanels(isQ, isFree, isRange);
                 }
             }
         );

http://dive4elements.wald.intevation.org