changeset 2456:60ab1054069d

Issue 630. Added input helper panel to wq selection. flys-client/trunk@4147 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 15 Mar 2012 15:02:29 +0000
parents 0b7535e2e9aa
children 37b4287f932c dc18457b1cef
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java
diffstat 2 files changed, 159 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Mar 14 15:34:02 2012 +0000
+++ b/flys-client/ChangeLog	Thu Mar 15 15:02:29 2012 +0000
@@ -1,3 +1,10 @@
+2012-03-15  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue 630.
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java:
+	  Added input helper panel to wq selection.
+
 2012-03-14  Raimund Renkert <raimund.renkert@intevation.de>
 
 	Issue 508.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Wed Mar 14 15:34:02 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Thu Mar 15 15:02:29 2012 +0000
@@ -9,6 +9,7 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.NumberFormat;
+import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.TitleOrientation;
 import com.smartgwt.client.types.VerticalAlignment;
@@ -23,6 +24,8 @@
 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.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;
@@ -30,8 +33,17 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.WQDataItem;
+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 de.intevation.flys.client.client.FLYSConstants;
+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;
 
 
 /**
@@ -56,6 +68,17 @@
 
     public static final int ROW_HEIGHT = 20;
 
+    /** The constant field name for choosing w or q mode.*/
+    public static final String FIELD_WQ = "wq";
+
+    /** The constant field name for choosing single values or range.*/
+    public static final String FIELD_MODE = "mode";
+
+    /** The constant field value for range input mode.*/
+    public static final String FIELD_MODE_RANGE = "range";
+
+    protected WQInfoServiceAsync wqInfoService =
+        GWT.create(WQInfoService.class);
 
     /** The message class that provides i18n strings.*/
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
@@ -72,16 +95,25 @@
     /** The RadioGroupItem that determines the w/q input mode.*/
     protected DynamicForm modes;
 
+    protected QDTable qdTable;
+
+    protected WTable wTable;
+
+    protected TabSet tabs;
 
 
     public WQAdaptedInputPanel() {
         wqranges = new HashMap<String, DoubleArrayPanel>();
         qranges  = new HashMap<String, double[]>();
         wranges  = new HashMap<String, double[]>();
+        qdTable  = new QDTable();
+        wTable   = new WTable();
     }
 
 
     public Canvas create(DataList data) {
+        initHelperPanel();
+
         Canvas submit = getNextButton();
         Canvas widget = createWidget(data);
         Label  label  = new Label(MSG.wqadaptedTitle());
@@ -96,10 +128,33 @@
         layout.addMember(widget);
         layout.addMember(submit);
 
+
         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);
+        qdTable.hideIconFields();
+
+        tabs.addTab(wTab, 0);
+        tabs.addTab(qTab, 1);
+
+        helperContainer.addMember(tabs);
+
+        fetchWQData();
+    }
+
+
     public Canvas createOld(DataList dataList) {
         List<Data> all = dataList.getAll();
         Data    wqData = getData(all, "wq_values");
@@ -418,9 +473,6 @@
                 double[] mmQ = wq.getQRange();
                 double[] mmW = wq.getWRange();
 
-                GWT.log(title + " Q: " + mmQ[0] + " - " + mmQ[1]);
-                GWT.log(title + " W: " + mmW[0] + " - " + mmW[1]);
-
                 qranges.put(title, mmQ);
                 wranges.put(title, mmW);
             }
@@ -466,11 +518,24 @@
         modes = new DynamicForm();
         modes.setFields(wq);
         modes.setWidth(200);
+        wq.addChangeHandler(new ChangeHandler() {
+            public void onChange(ChangeEvent e) {
+                DynamicForm form = e.getForm();
+
+                if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) {
+                    tabs.selectTab(0);
+                }
+                else {
+                    tabs.selectTab(1);
+                }
+            }
+        });
+
 
         LinkedHashMap initial = new LinkedHashMap();
         initial.put(FIELD_WQ_MODE, FIELD_WQ_Q);
         modes.setValues(initial);
-
+        tabs.selectTab(1);
         return modes;
     }
 
@@ -565,5 +630,88 @@
         DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm();
         dap.validateForm(event.getItem());
     }
+
+
+    protected void fetchWQData() {
+        Config config    = Config.getInstance();
+        String locale    = config.getLocale ();
+
+        ArtifactDescription adescr = artifact.getArtifactDescription();
+        DataList[] data = adescr.getOldData();
+
+        double[]  mm = getMinMaxKM(data);
+        String river = getRiverName(data);
+
+        wqInfoService.getWQInfo(locale, river, mm[0], mm[0],
+            new AsyncCallback<WQInfoObject[]>() {
+                public void onFailure(Throwable caught) {
+                    GWT.log("Could not recieve wq informations.");
+                    SC.warn(caught.getMessage());
+                }
+
+                public void onSuccess(WQInfoObject[] wqi) {
+                    int num = wqi != null ? wqi.length :0;
+                    GWT.log("Recieved " + num + " wq informations.");
+
+                    if (num == 0) {
+                        return;
+                    }
+
+                    addWQInfo(wqi);
+
+                }
+            }
+        );
+    }
+
+
+    protected void addWQInfo (WQInfoObject[] wqi) {
+        for(WQInfoObject wi: wqi) {
+            WQInfoRecord rec = new WQInfoRecord(wi);
+
+            if (wi.getType().equals("W")) {
+                wTable.addData(rec);
+            }
+            else {
+                qdTable.addData(rec);
+            }
+        }
+    }
+
+
+    /**
+     * Determines the min and max kilometer value selected in a former state. A
+     * bit silly, but we need to run over each value of the "old data" to find
+     * such values because it is not available here.
+     *
+     * @param data The DataList which contains the whole data inserted for the
+     * current artifact.
+     *
+     * @return a double array with [min, max].
+     */
+    protected double[] getMinMaxKM(DataList[] data) {
+        ArtifactDescription adesc = artifact.getArtifactDescription();
+        return adesc.getKMRange();
+    }
+
+
+    /**
+     * Returns the name of the selected river.
+     *
+     * @param data The DataList with all data.
+     *
+     * @return the name of the current river.
+     */
+    protected String getRiverName(DataList[] data) {
+        ArtifactDescription adesc = artifact.getArtifactDescription();
+        return adesc.getRiver();
+    }
+
+
+    protected void updatePanels(boolean isQ) {
+
+    }
+
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org