changeset 5773:cdc47534a970

issue1133: Improved multi-gauge W/Q input.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 19 Apr 2013 11:47:27 +0200
parents c0d0b9fd1aa8
children 496c8c9d4913
files flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java
diffstat 1 files changed, 134 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Fri Apr 19 09:22:44 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java	Fri Apr 19 11:47:27 2013 +0200
@@ -98,20 +98,23 @@
     /** List of doubleArrayPanels shown. */
     protected ArrayList<DoubleArrayPanel> doubleArrayPanels;
 
-    /** Stores the min/max values for each q range.*/
+    /** [startkm,endkm] per gauge in selected range. */
+    protected double[][] gaugeRanges;
+
+    /** Stores the min/max values for each q range (gauge). */
     protected Map<String, double[]> qranges;
 
-    /** Stores the min/max values for each w range. */
+    /** Stores the min/max values for each w range (gauge). */
     protected Map<String, double[]> wranges;
 
     /** The RadioGroupItem that determines the w/q input mode. */
     protected DynamicForm modes;
 
-    /** Table holding Q and D values. */
-    protected QDTable qdTable;
+    /** List of wTables in inputhelper section. */
+    protected List<WTable> wTables;
 
-    /** Table holding W values. */
-    protected WTable wTable;
+    /** List of QDTables in inputhelper section. */
+    protected List<QDTable> qdTables;
 
     /** Tabs in inputhelper area. */
     protected TabSet tabs;
@@ -125,14 +128,14 @@
         doubleArrayPanels = new ArrayList<DoubleArrayPanel>();
         qranges  = new HashMap<String, double[]>();
         wranges  = new HashMap<String, double[]>();
-        qdTable  = new QDTable();
-        wTable   = new WTable();
-        initTableListeners();
+        wTables  = new ArrayList<WTable>();
+        qdTables = new ArrayList<QDTable>();
     }
 
 
     @Override
     public Canvas create(DataList data) {
+        readGaugeRanges(data);
         initHelperPanel();
 
         Canvas submit = getNextButton();
@@ -149,6 +152,10 @@
         layout.addMember(widget);
         layout.addMember(submit);
 
+        fetchWQData();
+
+        initTableListeners();
+
         return layout;
     }
 
@@ -160,19 +167,30 @@
         tabs.setWidth100();
         tabs.setHeight100();
 
-        Tab wTab = new Tab(MESSAGE.wq_table_w());
-        Tab qTab = new Tab(MESSAGE.wq_table_q());
+        // For each gauge, add two tabs with helper tables.
 
-        qdTable.showSelect();
-        wTab.setPane(wTable);
-        qTab.setPane(qdTable);
+        for (int i = 0; i< gaugeRanges.length; i++) {
+            // Later the tabs title will get adjusted to include gauges name.
+            // TODO the tabs title becomes rather long through that (i18n).
+            Tab wTab = new Tab(MESSAGE.wq_table_w());
+            Tab qTab = new Tab(MESSAGE.wq_table_q());
 
-        tabs.addTab(wTab, 0);
-        tabs.addTab(qTab, 1);
+            QDTable qdTable = new QDTable();
+            WTable  wTable  = new WTable();
+
+            wTables.add(wTable);
+            qdTables.add(qdTable);
+
+            qdTable.showSelect();
+            //wTable.showSelect();
+            wTab.setPane(wTable);
+            qTab.setPane(qdTable);
+
+            tabs.addTab(wTab, i*2+0);
+            tabs.addTab(qTab, i*2+1);
+        }
 
         helperContainer.addMember(tabs);
-
-        fetchWQData();
     }
 
 
@@ -181,32 +199,44 @@
      */
     // TODO dupe from WQInputPanel
     protected void initTableListeners() {
-        CellClickHandler handler = new CellClickHandler() {
-            @Override
-            public void onCellClick(CellClickEvent e) {
-                if (isWMode() || qdTable.isLocked()) {
-                    return;
-                }
-
-                int    idx = e.getColNum();
-                Record r   = e.getRecord();
-                double val = r.getAttributeAsDouble("value");
+        int i = 0;
+        for (QDTable qdTable: qdTables) {
+            // Register listener such that values are filled in on click.
+            final QDTable table = qdTable;
+            final int fi = i;
+            CellClickHandler handler = new CellClickHandler() {
+                @Override
+                public void onCellClick(CellClickEvent e) {
+                    if (isWMode() || table.isLocked()) {
+                        return;
+                    }
 
-                if (itemWithFocus != null) {
-                    itemWithFocus.setValues(new double[]{val});
-                    // TODO 1133, show different data for each doublearraypanel
-                    int i = doubleArrayPanels.indexOf(itemWithFocus);
-                    if (i == doubleArrayPanels.size()-1) {
-                        doubleArrayPanels.get(0).focusInItem(1);
+                    int    idx = e.getColNum();
+                    Record r   = e.getRecord();
+                    double val = r.getAttributeAsDouble("value");
+
+                    doubleArrayPanels.get(fi).setValues(new double[]{val});
+                    // Focus next.
+                    if (fi != doubleArrayPanels.size()-1) {
+                        doubleArrayPanels.get(fi+1).focusInItem(1);
                     }
-                    else {
-                        doubleArrayPanels.get(i+1).focusInItem(1);
-                    }
+
+                    /*if (itemWithFocus != null) {
+                        itemWithFocus.setValues(new double[]{val});
+                        int i = doubleArrayPanels.indexOf(itemWithFocus);
+                        if (i == doubleArrayPanels.size()-1) {
+                            doubleArrayPanels.get(0).focusInItem(1);
+                        }
+                        else {
+                            doubleArrayPanels.get(i+1).focusInItem(1);
+                        }
+                    }*/
                 }
-            }
-        };
+            };
 
-        qdTable.addCellClickHandler(handler);
+            qdTable.addCellClickHandler(handler);
+            i++;
+        }
     }
 
 
@@ -294,6 +324,7 @@
     }
 
 
+    /** Create non-input helper part of the UI. */
     protected Canvas createWidget(DataList dataList) {
         VLayout layout = new VLayout();
 
@@ -468,15 +499,40 @@
         }
     }
 
+    /** Populate Gauge Ranges array. */
+    private void readGaugeRanges(DataList dataList) {
+        DataItem[] items = getWQItems(dataList);
+        gaugeRanges = new double[items.length][2];
+    
+        int i = 0;
+
+        for (DataItem item: items) {
+            String[] startEndKm = item.getLabel().split(";");
+
+            gaugeRanges[i][0] = Double.parseDouble(startEndKm[0]);
+            gaugeRanges[i][1] = Double.parseDouble(startEndKm[1]);
+            i++;
+        }
+    }
+
 
     protected Canvas createList(DataList dataList) {
         VLayout layout = new VLayout();
 
         DataItem[] items = getWQItems(dataList);
 
+        int i = 0;
+
         for (DataItem item: items) {
-            String title = item.getLabel();
+            String title = item.getLabel(); // of form: 70.5;112.0
             String label = item.getStringValue();
+
+            // Rename W and Q tab to include gauges name.
+            tabs.getTab(i*2).setTitle(tabs.getTab(i*2).getTitle()
+                + " (" + label + ")");
+            tabs.getTab(i*2+1).setTitle(tabs.getTab(i*2+1).getTitle()
+                + " (" + label + ")");
+
             DoubleArrayPanel dap = new DoubleArrayPanel(
                 label, null, this, this, TitleOrientation.LEFT);
 
@@ -493,6 +549,7 @@
             }
 
             layout.addMember(dap);
+            i++;
         }
 
         layout.setHeight(items.length * ROW_HEIGHT);
@@ -650,10 +707,14 @@
     }
 
 
-    /** Store the currently focussed DoubleArrayPanel. */
+    /** Store the currently focussed DoubleArrayPanel and focus helper tab. */
     @Override
     public void onFocus(FocusEvent event) {
         itemWithFocus = (DoubleArrayPanel) event.getForm();
+        // Switch to respective tab.
+        // TODO which makes a focus loss
+        int inputIndex = doubleArrayPanels.indexOf(itemWithFocus);
+        tabs.selectTab(inputIndex*2 + (isWMode() ? 0 : 1));
     }
 
 
@@ -664,7 +725,7 @@
     }
 
 
-    /** Get the WQD data from servide and stuck them up that tables. */
+    /** Get the WQD data from service and stuck them up that tables. */
     protected void fetchWQData() {
         Config config    = Config.getInstance();
         String locale    = config.getLocale ();
@@ -675,39 +736,49 @@
         double[]  mm = getMinMaxKM(data);
         String river = getRiverName(data);
 
-        wqInfoService.getWQInfo(locale, river, mm[0], mm[0],
-            new AsyncCallback<WQInfoObject[]>() {
-                @Override
-                public void onFailure(Throwable caught) {
-                    GWT.log("Could not recieve wq informations.");
-                    SC.warn(caught.getMessage());
-                }
+        int i = 0;
 
-                @Override
-                public void onSuccess(WQInfoObject[] wqi) {
-                    int num = wqi != null ? wqi.length :0;
-                    GWT.log("Recieved " + num + " wq informations.");
-
-                    if (num == 0) {
-                        return;
+        // Get Data for respective gauge.
+        for (double[] range : gaugeRanges){
+            // Gauge ranges overlap, move start and end a bit closer to each other.
+            final double rDiff = (range[1] - range[0]) / 10d;
+            final int fi = i;
+            wqInfoService.getWQInfo(locale, river, range[0]+rDiff, range[1]-rDiff,
+                new AsyncCallback<WQInfoObject[]>() {
+                    @Override
+                    public void onFailure(Throwable caught) {
+                        GWT.log("Could not recieve wq informations.");
+                        SC.warn(caught.getMessage());
                     }
 
-                    addWQInfo(wqi);
+                    @Override
+                    public void onSuccess(WQInfoObject[] wqi) {
+                        int num = wqi != null ? wqi.length :0;
+                        GWT.log("Received " + num + " wq informations (" + fi + ".");
+
+                        if (num == 0) {
+                            return;
+                        }
+
+                        addWQInfo(wqi, fi);
+                    }
                 }
-            }
-        );
+            );
+            i++;
+        }
     }
 
 
-    protected void addWQInfo (WQInfoObject[] wqi) {
+    /** Add Info to helper table for gauge at index gaugeIdx. */
+    protected void addWQInfo (WQInfoObject[] wqi, int gaugeIdx) {
         for(WQInfoObject wi: wqi) {
             WQInfoRecord rec = new WQInfoRecord(wi);
 
             if (wi.getType().equals("W")) {
-                wTable.addData(rec);
+                wTables.get(gaugeIdx).addData(rec);
             }
             else {
-                qdTable.addData(rec);
+                qdTables.get(gaugeIdx).addData(rec);
             }
         }
     }

http://dive4elements.wald.intevation.org