changeset 248:ed90309ec608

Added table for WQ inputs. flys-client/trunk@1834 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 05 May 2011 09:51:51 +0000
parents 4a684d29404f
children 6c7133eb8c4c
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java
diffstat 6 files changed, 243 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/ChangeLog	Thu May 05 09:51:51 2011 +0000
@@ -1,3 +1,15 @@
+2011-05-05  Raimund Renkert <rrenkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java:
+	  Added table for WQ inputs. TODO: Implement the selection and set the
+	  values.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants.java,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties:
+	  New i18n strings for the WQ input table.
+
 2011-05-05  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu May 05 09:51:51 2011 +0000
@@ -136,6 +136,12 @@
 
     String waterlevel_export();
 
+    String name();
+
+    String type();
+
+    String wq_value();
+
     String discharge_longitudinal_section();
 
     // ERRORS
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu May 05 09:51:51 2011 +0000
@@ -37,6 +37,9 @@
 from = From
 to = To
 riverside = Riverside
+name = Name
+type = Type
+wq_value = W/Q/D
 
 wqTitle = Input for W/Q Data
 wqadaptedTitle = Input for W/Q Data
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu May 05 09:51:51 2011 +0000
@@ -37,6 +37,9 @@
 from = von
 to = bis
 riverside = Flussseite
+name = Name
+type = Typ
+wq_value = W/Q/D
 
 wqTitle = Eingabe für W/Q Daten
 wqadaptedTitle = Eingabe für W/Q Daten
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu May 05 09:51:51 2011 +0000
@@ -37,6 +37,9 @@
 from = From
 to = To
 riverside = Riverside
+name = Name
+type = Type
+wq_value = W/Q/D
 
 wqTitle = Input for W/Q Data
 wqadaptedTitle = Input for W/Q Data
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu May 05 09:33:15 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java	Thu May 05 09:51:51 2011 +0000
@@ -4,6 +4,9 @@
 import java.util.List;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import com.smartgwt.client.data.Record;
 
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
@@ -16,13 +19,26 @@
 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.events.CellClickHandler;
+import com.smartgwt.client.widgets.grid.events.CellClickEvent;
 
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
 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.WQInfoObject;
+import de.intevation.flys.client.shared.model.WQInfoRecord;
+import de.intevation.flys.client.shared.model.ArtifactDescription;
+import com.smartgwt.client.types.ListGridFieldType;
+
+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;
 
 
 /**
@@ -35,8 +51,14 @@
 implements   ChangeHandler, BlurHandler
 {
     /** The message class that provides i18n strings.*/
-    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+    protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class);
 
+    /** The interface that provides the image resources. */
+    private FLYSImages IMAGES = GWT.create(FLYSImages.class);
+
+    /** The DistanceInfoService used to retrieve locations about rivers.*/
+    protected WQInfoServiceAsync wqInfoService =
+        GWT.create(WQInfoService.class);
 
     /** The constant field name for choosing w or q mode.*/
     public static final String FIELD_WQ = "wq";
@@ -61,7 +83,7 @@
 
 
     /** The container that manages the w and q panels.*/
-    protected VLayout container;
+    protected HLayout container;
 
     /** The RadioGroupItem that determines the w/q input mode.*/
     protected DynamicForm modes;
@@ -102,11 +124,21 @@
     /** The values entered in the single Q mode.*/
     protected double[] valuesQ;
 
+    /** The WQ Data*/
+    protected WQInfoObject[] tableData;
+
+    /** The WQ Input Table*/
+    protected ListGrid wqTable;
+
+    /** The WQ input table for ranges.*/
+    protected ListGrid wqRangeTable;
 
     /**
      * Creates a new WQInputPanel instance.
      */
     public WQInputPanel() {
+        wqTable      = new ListGrid();
+        wqRangeTable = new ListGrid();
     }
 
 
@@ -120,12 +152,12 @@
     public Canvas create(DataList data) {
         initDefaults(data);
 
+
         Canvas  widget = createWidget(data);
         Canvas  submit = getNextButton();
-        Label   label  = new Label(MSG.wqTitle());
+        Label   label  = new Label(MESSAGE.wqTitle());
 
         label.setHeight(25);
-        widget.setHeight(65);
 
         VLayout layout = new VLayout();
         layout.setMembersMargin(10);
@@ -195,6 +227,78 @@
     }
 
 
+    protected void createWQInputPanel() {
+        wqTable.setWidth(450);
+        wqTable.setShowRecordComponents(true);
+        wqTable.setShowRecordComponentsByCell(true);
+        wqTable.setHeight(300);
+
+        wqRangeTable.setWidth(450);
+        wqRangeTable.setShowRecordComponents(true);
+        wqRangeTable.setShowRecordComponentsByCell(true);
+        wqRangeTable.setHeight(300);
+
+        ListGridField addWQ = new ListGridField("", "");
+        addWQ.setType(ListGridFieldType.ICON);
+        addWQ.setWidth(30);
+        wqTable.addCellClickHandler(new CellClickHandler() {
+            public void onCellClick(CellClickEvent e) {
+                if (e.getColNum() == 0 && e.getRecord().getEnabled ()) {
+                    Record r = e.getRecord ();
+                    double val = r.getAttributeAsDouble("value");
+//                    setValue(val);
+                }
+            }
+        });
+        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(new CellClickHandler() {
+            public void onCellClick(CellClickEvent e) {
+                if (e.getColNum() == 0 && e.getRecord().getEnabled ()) {
+                    Record r = e.getRecord ();
+                    double val = r.getAttributeAsDouble("value");
+//                    setValue(val);
+                }
+                else if (e.getColNum() == 1 && e.getRecord().getEnabled()) {
+
+                }
+            }
+        });
+        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.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>.
@@ -234,11 +338,11 @@
     protected String createWString(DataItem from, DataItem to, DataItem step) {
         StringBuilder sb = new StringBuilder();
         sb.append(from.getLabel());
-        sb.append(" " + MSG.unitWFrom() + " ");
+        sb.append(" " + MESSAGE.unitWFrom() + " ");
         sb.append(to.getLabel());
-        sb.append(" " + MSG.unitWTo() + " ");
+        sb.append(" " + MESSAGE.unitWTo() + " ");
         sb.append(step.getLabel());
-        sb.append(" " + MSG.unitWStep());
+        sb.append(" " + MESSAGE.unitWStep());
 
         return sb.toString();
     }
@@ -252,11 +356,11 @@
     protected String createQString(DataItem from, DataItem to, DataItem step) {
         StringBuilder sb = new StringBuilder();
         sb.append(from.getLabel());
-        sb.append(" " + MSG.unitQFrom() + " ");
+        sb.append(" " + MESSAGE.unitQFrom() + " ");
         sb.append(to.getLabel());
-        sb.append(" " + MSG.unitQTo() + " ");
+        sb.append(" " + MESSAGE.unitQTo() + " ");
         sb.append(step.getLabel());
-        sb.append(" " + MSG.unitQStep());
+        sb.append(" " + MESSAGE.unitQStep());
 
         return sb.toString();
     }
@@ -278,19 +382,21 @@
      */
     protected Canvas createWidget(DataList data) {
         VLayout layout  = new VLayout();
-        container       = new VLayout();
+        container       = new HLayout();
         Canvas modeForm = createModePanel();
 
+        container.setMembersMargin(30);
+        createWQInputTable();
+        createWQInputPanel();
         // the initial panel is the Single-W panel.
         double[] values = getSingleW();
         container.addMember(new DoubleArrayPanel(
-            MSG.unitWSingle(), values, this));
+            MESSAGE.unitWSingle(), values, this));
 
+        container.addMember(wqTable);
         layout.addMember(modeForm);
         layout.addMember(container);
 
-        // TODO add a table on the right to select Q values
-
         return layout;
     }
 
@@ -314,12 +420,12 @@
         mode.setWidth(WIDTH_LEFT);
 
         LinkedHashMap wqValues = new LinkedHashMap();
-        wqValues.put(FIELD_WQ_W, MSG.wqW());
-        wqValues.put(FIELD_WQ_Q, MSG.wqQ());
+        wqValues.put(FIELD_WQ_W, MESSAGE.wqW());
+        wqValues.put(FIELD_WQ_Q, MESSAGE.wqQ());
 
         LinkedHashMap modeValues = new LinkedHashMap();
-        modeValues.put(FIELD_MODE_SINGLE, MSG.wqSingle());
-        modeValues.put(FIELD_MODE_RANGE, MSG.wqRange());
+        modeValues.put(FIELD_MODE_SINGLE, MESSAGE.wqSingle());
+        modeValues.put(FIELD_MODE_RANGE, MESSAGE.wqRange());
 
         wq.setValueMap(wqValues);
         mode.setValueMap(modeValues);
@@ -613,7 +719,10 @@
                 double[] values = getSingleW();
 
                 newPanel = new DoubleArrayPanel(
-                    MSG.unitWSingle(), values, this);
+                    MESSAGE.unitWSingle(), values, this);
+
+                container.addMember(newPanel);
+                container.addMember(wqTable);
             }
             else {
                 // Range W mode
@@ -622,10 +731,12 @@
                 double step = getStepW();
 
                 newPanel = new DoubleRangePanel(
-                    MSG.unitWFrom(), MSG.unitWTo(), MSG.unitWStep(),
+                    MESSAGE.unitWFrom(), MESSAGE.unitWTo(), MESSAGE.unitWStep(),
                     from, to, step,
                     250,
                     this);
+                container.addMember(newPanel);
+                container.addMember(wqRangeTable);
             }
         }
         else {
@@ -634,7 +745,9 @@
                 double[] values = getSingleQ();
 
                 newPanel = new DoubleArrayPanel(
-                    MSG.unitQSingle(), values, this);
+                    MESSAGE.unitQSingle(), values, this);
+                container.addMember(newPanel);
+                container.addMember(wqTable);
             }
             else {
                 // Range Q mode
@@ -643,14 +756,15 @@
                 double step = getStepQ();
 
                 newPanel = new DoubleRangePanel(
-                    MSG.unitQFrom(), MSG.unitQTo(), MSG.unitQStep(),
+                    MESSAGE.unitQFrom(), MESSAGE.unitQTo(), MESSAGE.unitQStep(),
                     from, to, step,
                     250,
                     this);
+                container.addMember(newPanel);
+                container.addMember(wqRangeTable);
             }
         }
 
-        container.addMember(newPanel);
     }
 
 
@@ -840,5 +954,84 @@
     protected void setStepW(double stepW) {
         this.stepW = stepW;
     }
+
+
+    protected void createWQInputTable() {
+        Config config    = Config.getInstance();
+        String url       = config.getServerUrl();
+        String locale    = config.getLocale ();
+        String river     = "";
+        String value_min = "";
+        String value_max = "";
+
+        ArtifactDescription adescr = artifact.getArtifactDescription();
+        DataList[] data = adescr.getOldData();
+
+        //TODO: get the information about old data.
+        if (data != null && data.length > 0) {
+            for (int i = 0; i < data.length; i++) {
+                DataList dl = data[i];
+                if (dl.getState().equals("state.winfo.river")) {
+                    for (int j = 0; j < dl.size(); j++) {
+                        Data d = dl.get(j);
+                        DataItem[] di = d.getItems();
+                        if (di != null && di.length == 1) {
+                           river = d.getItems()[0].getStringValue();
+                        }
+                    }
+                }
+                else if (dl.getState().equals("state.winfo.location_distance")){
+                    for (int j = 0; j < dl.size(); j++) {
+                        Data d = dl.get(j);
+                        DataItem[] di = d.getItems();
+                        if (di != null && di.length >= 1 && j == 0) {
+                            value_max = d.getItems()[0].getStringValue();
+                        }
+                        else if (di != null &&
+                                 di.length >= 1 &&
+                                 j == dl.size() - 1) {
+                            value_min = d.getItems()[0].getStringValue();
+                        }
+                    }
+                }
+            }
+        }
+
+        double from = Double.valueOf(value_min);
+        double to = Double.valueOf(value_max);
+        wqInfoService.getWQInfo(url, locale, river, from, to,
+            new AsyncCallback<WQInfoObject[]>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not recieve wq informations.");
+                    GWT.log(caught.getMessage());
+                }
+
+                public void onSuccess(WQInfoObject[] wqi) {
+                    int num = wqi != null ? wqi.length :0;
+                    GWT.log("Recieved " + num + " wq informations.");
+
+                    if (num == 0) {
+                        return;
+                    }
+                    tableData = wqi;
+                    addWQInfo(wqi);
+                }
+            }
+        );
+    }
+
+
+    protected void addWQInfo (WQInfoObject[] wqi) {
+        int i = 0;
+        for(WQInfoObject wi: wqi) {
+            WQInfoRecord rec = new WQInfoRecord (wi);
+            wqTable.addData(rec);
+            wqRangeTable.addData(rec);
+        }
+        return;
+    }
 }
+
+
+
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org