changeset 580:42512fce9b1b

#140, #122: Splitted the WQD table in the WQInputPanel into two tables: a table for QD values and a table for W values - only the QD table is selectable. flys-client/trunk@2164 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 20 Jun 2011 10:32:54 +0000
parents f1b977657880
children 210339fd1a34
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/QDTable.java flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/WTable.java
diffstat 6 files changed, 270 insertions(+), 217 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Jun 17 13:46:28 2011 +0000
+++ b/flys-client/ChangeLog	Mon Jun 20 10:32:54 2011 +0000
@@ -1,3 +1,30 @@
+2011-06-20  Ingo Weinzierl <ingo@intevation.de>
+
+	  flys/issue140 (WINFO: WQ-Tabelle in Tabs aufsplitten)
+	  flys/issue122 (W-INFO: Wasserspiegellagenberechnung / Auswahlunterstützung Abfluss (W-Werte sind nicht auswählbar))
+
+	* src/main/java/de/intevation/flys/client/client/ui/wq/QDTable.java:
+	  New. This table is used to show Q and D values for the WQInputPanel. The
+	  first two rows are selectable icons.
+
+	* src/main/java/de/intevation/flys/client/client/ui/wq/WTable.java: New.
+	  This table is used to show W values for the WQInputPanel. The rows in
+	  this table are not selectable.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java:
+	  Added methods to set the lower and upper value directly.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java:
+	  Added a method to add a further double value to the current list.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java:
+	  Removed the old WQD tables and replaced them with a QDTable and a
+	  WTable. The WQD values are sorted into the two tables when they are
+	  initialized. The values in the WTable are not selectable. The QDTable
+	  has two selectable columns. Based on the current mode (single values or
+	  range mode), the selected values are filled into the array panel or into
+	  the range panel.
+
 2011-06-17  Ingo Weinzierl <ingo@intevation.de>
 
 	  flys/issue140 PART 1 (WINFO: WQ-Tabelle in Tabs aufsplitten)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Fri Jun 17 13:46:28 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java	Mon Jun 20 10:32:54 2011 +0000
@@ -119,6 +119,22 @@
     }
 
 
+    /**
+     * This method appends a double value to the current list of values.
+     *
+     * @param value A new value.
+     */
+    public void addValue(double value) {
+        NumberFormat f = NumberFormat.getDecimalFormat();
+
+        String current = ti.getValueAsString();
+
+        current += " " + f.format(value);
+
+        ti.setValue(current);
+    }
+
+
     protected boolean validateForm() {
         return validateForm(ti);
     }
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java	Fri Jun 17 13:46:28 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java	Mon Jun 20 10:32:54 2011 +0000
@@ -218,5 +218,37 @@
 
         return getDouble(v);
     }
+
+
+    /**
+     * Sets the value of the field with name <i>fieldname</i>.
+     *
+     * @param value The new value.
+     * @param fieldname The name of the field.
+     */
+    public void setDoubleValue(double value, String fieldname) {
+        NumberFormat f = NumberFormat.getDecimalFormat();
+        setValue(fieldname, f.format(value));
+    }
+
+
+    /**
+     * Sets a new start value.
+     *
+     * @param value The new start value.
+     */
+    public void setFrom(double value) {
+        setDoubleValue(value, FIELD_FROM);
+    }
+
+
+    /**
+     * Sets a new end value.
+     *
+     * @param value The new end value.
+     */
+    public void setTo(double value) {
+        setDoubleValue(value, FIELD_TO);
+    }
 }
 // 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/WQInputPanel.java	Fri Jun 17 13:46:28 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Mon Jun 20 10:32:54 2011 +0000
@@ -22,11 +22,10 @@
 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
 import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
 import com.smartgwt.client.widgets.grid.events.CellClickHandler;
 import com.smartgwt.client.widgets.grid.events.CellClickEvent;
+import com.smartgwt.client.widgets.tab.TabSet;
+import com.smartgwt.client.widgets.tab.Tab;
 
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
@@ -36,14 +35,14 @@
 import de.intevation.flys.client.shared.model.WQInfoObject;
 import de.intevation.flys.client.shared.model.WQInfoRecord;
 import de.intevation.flys.client.shared.model.ArtifactDescription;
-import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.types.SelectionStyle;
 
-import de.intevation.flys.client.client.services.WQInfoService;
-import de.intevation.flys.client.client.services.WQInfoServiceAsync;
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.FLYSImages;
 import de.intevation.flys.client.client.Config;
+import de.intevation.flys.client.client.services.WQInfoService;
+import de.intevation.flys.client.client.services.WQInfoServiceAsync;
+import de.intevation.flys.client.client.ui.wq.WTable;
+import de.intevation.flys.client.client.ui.wq.QDTable;
 
 
 /**
@@ -146,23 +145,58 @@
     /** The input panel for q range*/
     protected DoubleRangePanel qRangePanel;
 
-    /** The WQ Data*/
-    protected WQInfoObject[] tableData;
+    protected QDTable qdTable;
 
-    /** The WQ Input Table*/
-    protected ListGrid wqTable;
+    protected WTable wTable;
 
-    /** The WQ input table for ranges.*/
-    protected ListGrid wqRangeTable;
+    protected TabSet tabs;
 
     /**
      * Creates a new WQInputPanel instance.
      */
     public WQInputPanel() {
-        wqTable      = new ListGrid();
-        wqRangeTable = new ListGrid();
-        wqTable.setShowHeaderContextMenu(false);
-        wqRangeTable.setShowHeaderContextMenu(false);
+        qdTable      = new QDTable();
+        wTable       = new WTable();
+
+        initTableListeners();
+    }
+
+
+    /**
+     * Initializes the listeners of the WQD tables.
+     */
+    protected void initTableListeners() {
+        CellClickHandler handler = new CellClickHandler() {
+            public void onCellClick(CellClickEvent e) {
+
+                if (isWMode()) {
+                    return;
+                }
+
+                int    idx = e.getColNum();
+                Record r   = e.getRecord ();
+                double val = r.getAttributeAsDouble("value");
+
+                if (idx == 0) {
+                    if (isRangeMode()) {
+                        qRangePanel.setFrom(val);
+                    }
+                    else {
+                        qArrayPanel.addValue(val);
+                    }
+                }
+                else if (idx == 1) {
+                    if (isRangeMode()) {
+                        qRangePanel.setTo(val);
+                    }
+                    else {
+                        qArrayPanel.addValue(val);
+                    }
+                }
+            }
+        };
+
+        qdTable.addCellClickHandler(handler);
     }
 
 
@@ -189,12 +223,34 @@
         layout.addMember(widget);
         layout.addMember(submit);
 
+        initHelperPanel();
         initUserDefaults(data);
 
         return layout;
     }
 
 
+    protected void initHelperPanel() {
+        tabs = new TabSet();
+        tabs.setWidth100();
+        tabs.setHeight100();
+
+        // TODO i18n
+        Tab wTab = new Tab("W");
+        Tab qTab = new Tab("Q / D");
+
+        wTab.setPane(wTable);
+        qTab.setPane(qdTable);
+
+        tabs.addTab(wTab, 0);
+        tabs.addTab(qTab, 1);
+
+        helperContainer.addChild(tabs);
+
+        fetchWQData();
+    }
+
+
     public Canvas createOld(DataList dataList) {
         List<Data> items = dataList.getAll();
 
@@ -252,147 +308,6 @@
     }
 
 
-    protected void createWQInputPanel() {
-        wqTable.setWidth100();
-        wqTable.setShowRecordComponents(true);
-        wqTable.setShowRecordComponentsByCell(true);
-        wqTable.setHeight100();
-        wqTable.setEmptyMessage(MESSAGE.empty_table());
-
-        wqRangeTable.setWidth100();
-        wqRangeTable.setShowRecordComponents(true);
-        wqRangeTable.setShowRecordComponentsByCell(true);
-        wqRangeTable.setHeight100();
-        wqRangeTable.setEmptyMessage(MESSAGE.empty_table());
-
-        ListGridField addWQ = new ListGridField("", "");
-        addWQ.setType(ListGridFieldType.ICON);
-        addWQ.setWidth(30);
-
-        CellClickHandler cch = new CellClickHandler() {
-            public void onCellClick(CellClickEvent e) {
-                if (e.getColNum() == 0 && e.getRecord().getEnabled ()) {
-                    Record r = e.getRecord ();
-                    double val = r.getAttributeAsDouble("value");
-                    if(isWMode() && !isRangeMode()) {
-                        double[] in = wArrayPanel.getInputValues();
-                        int size = 0;
-                        if (in == null) {
-                            double[] vals = new double[1];
-                            vals[0] = val;
-                            wArrayPanel.setValues(vals);
-                            setSingleW(vals);
-                        }
-                        else {
-                            double[] vals = new double[in.length+1];
-                            for(int i = 0; i < in.length; i++) {
-                                vals[i] = in[i];
-                            }
-                            vals[in.length] = val;
-                            wArrayPanel.setValues(vals);
-                            setSingleW(vals);
-                        }
-                    }
-                    else if (!isWMode() && !isRangeMode()) {
-                        double[] in = qArrayPanel.getInputValues();
-                        int size = 0;
-                        if (in == null) {
-                            double[] vals = new double[1];
-                            vals[0] = val;
-                            qArrayPanel.setValues(vals);
-                            setSingleQ(vals);
-                        }
-                        else {
-                            double[] vals = new double[in.length+1];
-                            for(int i = 0; i < in.length; i++) {
-                                vals[i] = in[i];
-                            }
-                            vals[in.length] = val;
-                            qArrayPanel.setValues(vals);
-                            setSingleQ(vals);
-                        }
-                    }
-                }
-            }
-        };
-
-        CellClickHandler cchRange = new CellClickHandler() {
-            public void onCellClick(CellClickEvent e) {
-                if (e.getColNum() == 0 && e.getRecord().getEnabled ()) {
-                    Record r = e.getRecord ();
-                    double val = r.getAttributeAsDouble("value");
-                    if(isWMode() && isRangeMode()) {
-                        wRangePanel.setValues(
-                            val,
-                            wRangePanel.getTo(),
-                            wRangePanel. getStep());
-                    }
-                    else if (!isWMode() && isRangeMode()) {
-                        qRangePanel.setValues(
-                            val,
-                            qRangePanel.getTo(),
-                            qRangePanel.getStep());
-                    }
-                }
-                if (e.getColNum() == 1 && e.getRecord().getEnabled()) {
-                    Record r = e.getRecord ();
-                    double val = r.getAttributeAsDouble("value");
-                    if (isWMode() && isRangeMode()) {
-                         wRangePanel.setValues(
-                             wRangePanel.getFrom(),
-                             val,
-                             wRangePanel.getStep());
-                    }
-                    else if(!isWMode() && isRangeMode()) {
-                        qRangePanel.setValues(
-                            qRangePanel.getFrom(),
-                            val,
-                            qRangePanel.getStep());
-                    }
-                }
-            }
-        };
-        wqTable.addCellClickHandler(cch);
-        wqRangeTable.addCellClickHandler(cchRange);
-        addWQ.setCellIcon (IMAGES.markerGreen().getURL());
-
-        ListGridField addWQMin = new ListGridField("", "");
-        addWQMin.setType(ListGridFieldType.ICON);
-        addWQMin.setWidth(30);
-        ListGridField addWQMax = new ListGridField("", "");
-        addWQMax.setType(ListGridFieldType.ICON);
-        addWQMax.setWidth(30);
-
-        wqRangeTable.addCellClickHandler(cch);
-        addWQMin.setCellIcon(IMAGES.markerGreen().getURL());
-        addWQMax.setCellIcon(IMAGES.markerRed().getURL());
-
-        ListGridField name = new ListGridField("name", MESSAGE.name());
-        name.setType(ListGridFieldType.TEXT);
-        name.setWidth("*");
-        ListGridField type = new ListGridField("type", MESSAGE.type());
-        type.setType(ListGridFieldType.TEXT);
-        type.setWidth("50");
-        ListGridField value = new ListGridField("value", MESSAGE.wq_value());
-        value.setType(ListGridFieldType.TEXT);
-        type.setWidth("50");
-
-        ListGridField name_r = new ListGridField("name", MESSAGE.name());
-        name_r.setType(ListGridFieldType.TEXT);
-        name_r.setWidth("*");
-        ListGridField type_r = new ListGridField("type", MESSAGE.type());
-        type_r.setType(ListGridFieldType.TEXT);
-        type_r.setWidth("50");
-        ListGridField value_r = new ListGridField("value", MESSAGE.wq_value());
-        value_r.setType(ListGridFieldType.TEXT);
-        type_r.setWidth("50");
-
-        wqTable.setSelectionType(SelectionStyle.SINGLE);
-        wqRangeTable.setSelectionType(SelectionStyle.SINGLE);
-        wqTable.setFields(addWQ, name, type, value);
-        wqRangeTable.setFields(addWQMin, addWQMax, name_r, type_r, value_r);
-    }
-
     /**
      * This method reads the default values defined in the DataItems of the Data
      * objects in <i>list</i>.
@@ -609,8 +524,6 @@
         Canvas modeForm = createModePanel();
 
         container.setMembersMargin(30);
-        createWQInputTable();
-        createWQInputPanel();
 
         // the initial panel is the Single-W panel.
         double[] values = getSingleQ();
@@ -618,7 +531,6 @@
             MESSAGE.unitQSingle(), values, this);
         container.addMember(qArrayPanel);
 
-        helperContainer.addChild(wqTable);
         layout.addMember(modeForm);
         layout.addMember(container);
 
@@ -1079,6 +991,7 @@
 
     protected void updatePanels(String wqMode, String inputMode) {
         container.removeMembers(container.getMembers());
+
         if (wqMode.equals(FIELD_WQ_W)) {
             if (inputMode.equals(FIELD_MODE_SINGLE)) {
                 // Single W mode
@@ -1088,18 +1001,6 @@
                     MESSAGE.unitWSingle(), values, this);
 
                 container.addMember(wArrayPanel);
-                helperContainer.addChild(wqTable);
-                int size = wqTable.getRecords().length;
-                for(int i = 0; i < size; i++) {
-                    ListGridRecord r = wqTable.getRecord(i);
-                    String type = r.getAttributeAsString("type");
-                    if (type.equals("W")) {
-                        wqTable.getRecord(i).setEnabled(true);
-                    }
-                    else if(type.equals("D") || type.equals("Q")) {
-                        wqTable.getRecord(i).setEnabled(false);
-                    }
-                }
             }
             else {
                 // Range W mode
@@ -1113,19 +1014,9 @@
                     250,
                     this);
                 container.addMember(wRangePanel);
-                helperContainer.addChild(wqRangeTable);
-                int size = wqRangeTable.getRecords().length;
-                for(int i = 0; i < size; i++) {
-                    ListGridRecord r = wqRangeTable.getRecord(i);
-                    String type = r.getAttributeAsString("type");
-                    if (type.equals("W")) {
-                        wqRangeTable.getRecord(i).setEnabled(true);
-                    }
-                    else if(type.equals("D") || type.equals("Q")) {
-                        wqRangeTable.getRecord(i).setEnabled(false);
-                    }
-                }
             }
+
+            tabs.selectTab(0);
         }
         else {
             if (inputMode.equals(FIELD_MODE_SINGLE)) {
@@ -1135,19 +1026,6 @@
                 qArrayPanel = new DoubleArrayPanel(
                     MESSAGE.unitQSingle(), values, this);
                 container.addMember(qArrayPanel);
-                helperContainer.addChild(wqTable);
-                int size = wqTable.getRecords().length;
-                for(int i = 0; i < size; i++) {
-                    ListGridRecord r = wqTable.getRecord(i);
-                    String type = r.getAttributeAsString("type");
-                    if (type.equals("W")) {
-                        wqTable.getRecord(i).setEnabled(false);
-                    }
-                    else if(type.equals("D") || type.equals("Q")) {
-                        wqTable.getRecord(i).setEnabled(true);
-                    }
-            }
-
             }
             else {
                 // Range Q mode
@@ -1161,19 +1039,9 @@
                     250,
                     this);
                 container.addMember(qRangePanel);
-                helperContainer.addChild(wqRangeTable);
-                int size = wqRangeTable.getRecords().length;
-                for(int i = 0; i < size; i++) {
-                    ListGridRecord r = wqRangeTable.getRecord(i);
-                    String type = r.getAttributeAsString("type");
-                    if (type.equals("W")) {
-                        wqRangeTable.getRecord(i).setEnabled(false);
-                    }
-                    else if(type.equals("D") || type.equals("Q")) {
-                        wqRangeTable.getRecord(i).setEnabled(true);
-                    }
-                }
             }
+
+            tabs.selectTab(1);
         }
     }
 
@@ -1441,7 +1309,7 @@
     }
 
 
-    protected void createWQInputTable() {
+    protected void fetchWQData() {
         Config config    = Config.getInstance();
         String url       = config.getServerUrl();
         String locale    = config.getLocale ();
@@ -1466,7 +1334,7 @@
                     if (num == 0) {
                         return;
                     }
-                    tableData = wqi;
+
                     addWQInfo(wqi);
 
                     String wq = (String) modes.getValue(FIELD_WQ);
@@ -1479,13 +1347,16 @@
 
 
     protected void addWQInfo (WQInfoObject[] wqi) {
-        int i = 0;
         for(WQInfoObject wi: wqi) {
-            WQInfoRecord rec = new WQInfoRecord (wi);
-            wqTable.addData(rec);
-            wqRangeTable.addData(rec);
+            WQInfoRecord rec = new WQInfoRecord(wi);
+
+            if (wi.getType().equals("W")) {
+                wTable.addData(rec);
+            }
+            else {
+                qdTable.addData(rec);
+            }
         }
-        return;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/QDTable.java	Mon Jun 20 10:32:54 2011 +0000
@@ -0,0 +1,61 @@
+package de.intevation.flys.client.client.ui.wq;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.SelectionStyle;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+
+import de.intevation.flys.client.client.FLYSConstants;
+import de.intevation.flys.client.client.FLYSImages;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class QDTable extends ListGrid {
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class);
+
+    /** The interface that provides the image resources. */
+    private FLYSImages IMAGES = GWT.create(FLYSImages.class);
+
+
+    public QDTable() {
+        setWidth100();
+        setHeight100();
+        setSelectionType(SelectionStyle.SINGLE);
+        setSelectionType(SelectionStyle.SINGLE);
+        setShowHeaderContextMenu(false);
+        setShowRecordComponents(true);
+        setShowRecordComponentsByCell(true);
+        setEmptyMessage(MESSAGE.empty_table());
+
+        ListGridField addMax = new ListGridField("", "");
+        addMax.setType(ListGridFieldType.ICON);
+        addMax.setWidth(30);
+        addMax.setCellIcon(IMAGES.markerRed().getURL());
+
+        ListGridField addMin = new ListGridField("", "");
+        addMin.setType(ListGridFieldType.ICON);
+        addMin.setWidth(30);
+        addMin.setCellIcon(IMAGES.markerGreen().getURL());
+
+        ListGridField name = new ListGridField("name", MESSAGE.name());
+        name.setType(ListGridFieldType.TEXT);
+        name.setWidth("*");
+
+        ListGridField type = new ListGridField("type", MESSAGE.type());
+        type.setType(ListGridFieldType.TEXT);
+        type.setWidth("50");
+
+        ListGridField value = new ListGridField("value", MESSAGE.wq_value());
+        value.setType(ListGridFieldType.TEXT);
+        type.setWidth("50");
+
+        setFields(addMin, addMax, name, type, value);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/wq/WTable.java	Mon Jun 20 10:32:54 2011 +0000
@@ -0,0 +1,46 @@
+package de.intevation.flys.client.client.ui.wq;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.types.SelectionStyle;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+
+import de.intevation.flys.client.client.FLYSConstants;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class WTable extends ListGrid {
+
+    /** The message class that provides i18n strings.*/
+    protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class);
+
+
+    public WTable() {
+        setWidth100();
+        setHeight100();
+        setSelectionType(SelectionStyle.NONE);
+        setSelectionType(SelectionStyle.NONE);
+        setShowHeaderContextMenu(false);
+        setShowRecordComponents(true);
+        setShowRecordComponentsByCell(true);
+        setEmptyMessage(MESSAGE.empty_table());
+
+        ListGridField name = new ListGridField("name", MESSAGE.name());
+        name.setType(ListGridFieldType.TEXT);
+        name.setWidth("*");
+
+        ListGridField type = new ListGridField("type", MESSAGE.type());
+        type.setType(ListGridFieldType.TEXT);
+        type.setWidth("50");
+
+        ListGridField value = new ListGridField("value", MESSAGE.wq_value());
+        value.setType(ListGridFieldType.TEXT);
+        type.setWidth("50");
+
+        setFields(name, type, value);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org