[PATCH] datatransfer bezugsjahr, qserieslength

Wald Commits scm-commit at wald.intevation.org
Fri Jul 20 11:19:20 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1532078347 -7200
# Node ID 717c9dc1859fc698280e5e0dfee0d96683b21ec3
# Parent  2323d005f9a5a6df7d40f7a00544079e1a055d35
datatransfer bezugsjahr, qserieslength

diff -r 2323d005f9a5 -r 717c9dc1859f gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java	Fri Jul 20 10:39:02 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java	Fri Jul 20 11:19:07 2018 +0200
@@ -8,10 +8,31 @@
 
 package org.dive4elements.river.client.client.ui;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.dive4elements.river.client.client.Config;
+import org.dive4elements.river.client.client.FLYSConstants;
+import org.dive4elements.river.client.client.services.WQInfoService;
+import org.dive4elements.river.client.client.services.WQInfoServiceAsync;
+import org.dive4elements.river.client.client.ui.wq.QDTable;
+import org.dive4elements.river.client.client.ui.wq.WTable;
+import org.dive4elements.river.client.shared.model.ArtifactDescription;
+import org.dive4elements.river.client.shared.model.Data;
+import org.dive4elements.river.client.shared.model.DataItem;
+import org.dive4elements.river.client.shared.model.DataList;
+import org.dive4elements.river.client.shared.model.DefaultData;
+import org.dive4elements.river.client.shared.model.DefaultDataItem;
+import org.dive4elements.river.client.shared.model.WQDataItem;
+import org.dive4elements.river.client.shared.model.WQInfoObject;
+import org.dive4elements.river.client.shared.model.WQInfoRecord;
+
 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.data.Record;
 import com.smartgwt.client.types.TitleOrientation;
 import com.smartgwt.client.types.VerticalAlignment;
@@ -33,47 +54,21 @@
 import com.smartgwt.client.widgets.tab.Tab;
 import com.smartgwt.client.widgets.tab.TabSet;
 
-import org.dive4elements.river.client.client.Config;
-import org.dive4elements.river.client.client.FLYSConstants;
-import org.dive4elements.river.client.client.services.WQInfoService;
-import org.dive4elements.river.client.client.services.WQInfoServiceAsync;
-import org.dive4elements.river.client.client.ui.wq.QDTable;
-import org.dive4elements.river.client.client.ui.wq.WTable;
-import org.dive4elements.river.client.shared.model.ArtifactDescription;
-import org.dive4elements.river.client.shared.model.Data;
-import org.dive4elements.river.client.shared.model.DataItem;
-import org.dive4elements.river.client.shared.model.DataList;
-import org.dive4elements.river.client.shared.model.DefaultData;
-import org.dive4elements.river.client.shared.model.DefaultDataItem;
-import org.dive4elements.river.client.shared.model.WQDataItem;
-import org.dive4elements.river.client.shared.model.WQInfoObject;
-import org.dive4elements.river.client.shared.model.WQInfoRecord;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-
 /**
  * This UIProvider creates a widget to enter W or Q data for discharge
  * longitudinal section computations.
  *
  * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
  */
-public class WQAdaptedInputPanel
-extends      AbstractUIProvider
-implements   ChangeHandler, BlurHandler, FocusHandler
-{
+public class WQAdaptedInputPanel extends AbstractUIProvider implements ChangeHandler, BlurHandler, FocusHandler {
     private static final long serialVersionUID = -3218827566805476423L;
 
     /** The message class that provides i18n strings. */
     protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class);
 
     public static final String FIELD_WQ_MODE = "wq_isq";
-    public static final String FIELD_WQ_W    = "W";
-    public static final String FIELD_WQ_Q    = "Q";
+    public static final String FIELD_WQ_W = "W";
+    public static final String FIELD_WQ_Q = "Q";
 
     public static final String GAUGE_SEPARATOR = ":";
 
@@ -93,8 +88,7 @@
     public static final String FIELD_MODE_RANGE = "range";
 
     /** Service to fetch W/Q MainValues. */
-    protected WQInfoServiceAsync wqInfoService =
-        GWT.create(WQInfoService.class);
+    protected WQInfoServiceAsync wqInfoService = GWT.create(WQInfoService.class);
 
     /** The message class that provides i18n strings. */
     protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
@@ -106,7 +100,7 @@
     protected ArrayList<DoubleArrayPanel> doubleArrayPanels;
 
     /** [startkm,endkm] per gauge in selected range. */
-    protected double[][] gaugeRanges;
+    protected List<Double[]> gaugeRanges;
 
     /** Stores the min/max values for each q range (gauge). */
     protected Map<String, double[]> qranges;
@@ -129,30 +123,28 @@
     /** The currently focussed Input element. */
     protected DoubleArrayPanel itemWithFocus;
 
-
     public WQAdaptedInputPanel() {
-        wqranges = new HashMap<String, DoubleArrayPanel>();
-        doubleArrayPanels = new ArrayList<DoubleArrayPanel>();
-        qranges  = new HashMap<String, double[]>();
-        wranges  = new HashMap<String, double[]>();
-        wTables  = new ArrayList<WTable>();
-        qdTables = new ArrayList<QDTable>();
+        this.wqranges = new HashMap<String, DoubleArrayPanel>();
+        this.doubleArrayPanels = new ArrayList<DoubleArrayPanel>();
+        this.qranges = new HashMap<String, double[]>();
+        this.wranges = new HashMap<String, double[]>();
+        this.wTables = new ArrayList<WTable>();
+        this.qdTables = new ArrayList<QDTable>();
     }
 
-
     /** Create labels, canvasses, layouts. */
     @Override
-    public Canvas create(DataList data) {
+    public Canvas create(final DataList data) {
         readGaugeRanges(data);
         initHelperPanel();
 
-        Canvas submit = getNextButton();
-        Canvas widget = createWidget(data);
-        Label  label  = new Label(MSG.wqadaptedTitle());
+        final Canvas submit = getNextButton();
+        final Canvas widget = createWidget(data);
+        final Label label = new Label(this.MSG.wqadaptedTitle());
 
         label.setHeight(25);
 
-        VLayout layout = new VLayout();
+        final VLayout layout = new VLayout();
         layout.setMembersMargin(10);
         layout.setWidth(350);
 
@@ -169,100 +161,94 @@
         // the code in the W/Q radiogroup-changehandler behaves
         // exactly vice versa (enabling Q, selecting tab 0).
         enableWTabs();
-        tabs.selectTab(1);
+        this.tabs.selectTab(1);
 
         return layout;
     }
 
-
     /** Inits the helper panel. */
     // TODO duplicate in WQInputPanel
     protected void initHelperPanel() {
-        tabs = new TabSet();
-        tabs.setWidth100();
-        tabs.setHeight100();
+        this.tabs = new TabSet();
+        this.tabs.setWidth100();
+        this.tabs.setHeight100();
 
         // For each gauge, add two tabs with helper tables.
 
-        for (int i = 0; i< gaugeRanges.length; i++) {
+        for (int i = 0; i < this.gaugeRanges.size(); 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());
+            final Tab wTab = new Tab(this.MESSAGE.wq_table_w());
+            final Tab qTab = new Tab(this.MESSAGE.wq_table_q());
 
-            QDTable qdTable = new QDTable();
-            WTable  wTable  = new WTable();
+            final QDTable qdTable = new QDTable();
+            final WTable wTable = new WTable();
 
-            wTables.add(wTable);
-            qdTables.add(qdTable);
+            this.wTables.add(wTable);
+            this.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);
-            //tabs.disableTab(i*2+1);
+            this.tabs.addTab(wTab, i * 2 + 0);
+            this.tabs.addTab(qTab, i * 2 + 1);
+            // tabs.disableTab(i*2+1);
         }
 
         // Defaults at "Q", first input field.
-        tabs.selectTab(0);
+        this.tabs.selectTab(0);
         enableQTabs();
 
-        helperContainer.addMember(tabs);
+        this.helperContainer.addMember(this.tabs);
     }
 
-
     /**
      * Initializes the listeners of the WQD tables.
      */
     // TODO dupe from WQInputPanel
     protected void initTableListeners() {
         int i = 0;
-        for (QDTable qdTable: qdTables) {
+        for (final QDTable qdTable : this.qdTables) {
             // Register listener such that values are filled in on click.
             final QDTable table = qdTable;
             final int fi = i;
-            CellClickHandler handler = new CellClickHandler() {
+            final CellClickHandler handler = new CellClickHandler() {
                 @Override
-                public void onCellClick(CellClickEvent e) {
+                public void onCellClick(final CellClickEvent e) {
                     if (isWMode() || table.isLocked()) {
                         return;
                     }
 
-                    Record r   = e.getRecord();
-                    double val = r.getAttributeAsDouble("value");
+                    final Record r = e.getRecord();
+                    final double val = r.getAttributeAsDouble("value");
 
-                    doubleArrayPanels.get(fi).setValues(new double[]{val});
+                    WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val });
                     // If a named value for first gauge is chosen,
                     // try to find and set
                     // the values to the other panels too.
                     if (fi == 0) {
-                        String valueName = r.getAttribute("name");
+                        final String valueName = r.getAttribute("name");
                         int oi = 0;
                         // TODO instead of oi use random access.
-                        for (QDTable otherQDTable: qdTables) {
+                        for (final QDTable otherQDTable : WQAdaptedInputPanel.this.qdTables) {
                             if (oi == 0) {
                                 oi++;
                                 continue;
                             }
-                            Double value = otherQDTable.findRecordValue(
-                                valueName);
+                            final Double value = otherQDTable.findRecordValue(valueName);
                             if (value == null) {
-                                SC.warn(MSG.noMainValueAtGauge());
-                            }
-                            else {
-                                doubleArrayPanels.get(oi).setValues(
-                                    new double[]{value});
+                                SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge());
+                            } else {
+                                WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value });
                             }
                             oi++;
                         }
-                    }
-                    else {
+                    } else {
                         // Focus next.
-                        if (fi != doubleArrayPanels.size()-1) {
-                            doubleArrayPanels.get(fi+1).focusInItem(1);
+                        if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) {
+                            WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1);
                         }
                     }
                 }
@@ -273,50 +259,46 @@
         }
 
         i = 0;
-        for (WTable wTable: wTables) {
+        for (final WTable wTable : this.wTables) {
             // Register listener such that values are filled in on click.
             final WTable table = wTable;
             final int fi = i;
-            CellClickHandler handler = new CellClickHandler() {
+            final CellClickHandler handler = new CellClickHandler() {
                 @Override
-                public void onCellClick(CellClickEvent e) {
-                    if (!isWMode() /*|| table.isLocked()*/) {
+                public void onCellClick(final CellClickEvent e) {
+                    if (!isWMode() /* || table.isLocked() */) {
                         return;
                     }
 
-                    Record r   = e.getRecord();
-                    double val = r.getAttributeAsDouble("value");
+                    final Record r = e.getRecord();
+                    final double val = r.getAttributeAsDouble("value");
 
-                    doubleArrayPanels.get(fi).setValues(new double[]{val});
+                    WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val });
                     // If a named value for first gauge is chosen,
                     // try to find and set
                     // the values to the other panels too.
                     if (fi == 0) {
-                        String valueName = r.getAttribute("name");
+                        final String valueName = r.getAttribute("name");
                         int oi = 0;
                         // TODO instead of oi use random access.
-                        for (WTable otherWTable: wTables) {
+                        for (final WTable otherWTable : WQAdaptedInputPanel.this.wTables) {
                             if (oi == 0) {
                                 oi++;
                                 continue;
                             }
-                            Double value = otherWTable.findRecordValue(
-                                valueName);
+                            final Double value = otherWTable.findRecordValue(valueName);
                             if (value == null) {
                                 // TODO: afterwards it freaks out
-                                SC.warn(MSG.noMainValueAtGauge());
-                            }
-                            else {
-                                doubleArrayPanels.get(oi).setValues(
-                                    new double[]{value});
+                                SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge());
+                            } else {
+                                WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value });
                             }
                             oi++;
                         }
-                    }
-                    else {
+                    } else {
                         // Focus next.
-                        if (fi != doubleArrayPanels.size()-1) {
-                            doubleArrayPanels.get(fi+1).focusInItem(1);
+                        if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) {
+                            WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1);
                         }
                     }
                 }
@@ -327,21 +309,20 @@
         }
     }
 
+    @Override
+    public Canvas createOld(final DataList dataList) {
+        final List<Data> all = dataList.getAll();
+        final Data wqData = getData(all, "wq_values");
+        final Data wqMode = getData(all, "wq_isq");
+        final boolean isQ = wqMode.getItems()[0].getStringValue().equals("true");
+        final Canvas back = getBackButton(dataList.getState());
 
-    @Override
-    public Canvas createOld(DataList dataList) {
-        List<Data> all = dataList.getAll();
-        Data    wqData = getData(all, "wq_values");
-        Data    wqMode = getData(all, "wq_isq");
-        boolean isQ = wqMode.getItems()[0].getStringValue().equals("true");
-        Canvas back = getBackButton(dataList.getState());
+        final HLayout valLayout = new HLayout();
+        final HLayout modeLayout = new HLayout();
+        final VLayout vlayout = new VLayout();
 
-        HLayout valLayout  = new HLayout();
-        HLayout modeLayout = new HLayout();
-        VLayout vlayout    = new VLayout();
-
-        Label wqLabel   = new Label(dataList.getLabel());
-        Label modeLabel = new Label("");
+        final Label wqLabel = new Label(dataList.getLabel());
+        final Label modeLabel = new Label("");
 
         wqLabel.setValign(VerticalAlignment.TOP);
 
@@ -362,30 +343,29 @@
         return vlayout;
     }
 
+    /** Create area showing previously entered w or q data. */
+    protected Canvas createOldWQValues(final Data wqData, final boolean isQ) {
+        final VLayout layout = new VLayout();
 
-    /** Create area showing previously entered w or q data. */
-    protected Canvas createOldWQValues(Data wqData, boolean isQ) {
-        VLayout layout = new VLayout();
+        final DataItem item = wqData.getItems()[0];
+        final String value = item.getStringValue();
 
-        DataItem item  = wqData.getItems()[0];
-        String   value = item.getStringValue();
+        final String[] gauges = value.split(GAUGE_SEPARATOR);
 
-        String[] gauges = value.split(GAUGE_SEPARATOR);
+        final String unit = isQ ? "m³/s" : "cm";
 
-        String unit = isQ ? "m³/s" : "cm";
+        for (final String gauge : gauges) {
+            final HLayout h = new HLayout();
 
-        for (String gauge: gauges) {
-            HLayout h = new HLayout();
+            final String[] parts = gauge.split(GAUGE_PART_SEPARATOR);
+            final String[] values = parts[3].split(VALUE_SEPARATOR);
 
-            String[] parts  = gauge.split(GAUGE_PART_SEPARATOR);
-            String[] values = parts[3].split(VALUE_SEPARATOR);
+            final Label l = new Label(parts[2] + ": ");
 
-            Label l = new Label(parts[2] + ": ");
+            final StringBuilder sb = new StringBuilder();
+            boolean first = true;
 
-            StringBuilder sb = new StringBuilder();
-            boolean    first = true;
-
-            for (String v: values) {
+            for (final String v : values) {
                 if (!first) {
                     sb.append(", ");
                 }
@@ -397,7 +377,7 @@
                 first = false;
             }
 
-            Label v = new Label(sb.toString());
+            final Label v = new Label(sb.toString());
 
             l.setWidth(65);
             v.setWidth(65);
@@ -411,16 +391,15 @@
         return layout;
     }
 
+    /** Create non-input helper part of the UI. */
+    protected Canvas createWidget(final DataList dataList) {
+        final VLayout layout = new VLayout();
 
-    /** Create non-input helper part of the UI. */
-    protected Canvas createWidget(DataList dataList) {
-        VLayout layout = new VLayout();
+        final Canvas mode = createMode(dataList);
+        final Canvas list = createList(dataList);
 
-        Canvas mode = createMode(dataList);
-        Canvas list = createList(dataList);
-
-        DataItem[] items = getWQItems(dataList);
-        int listHeight   = ROW_HEIGHT * items.length;
+        final DataItem[] items = getWQItems(dataList);
+        final int listHeight = ROW_HEIGHT * items.length;
 
         mode.setHeight(25);
         mode.setWidth(200);
@@ -436,58 +415,54 @@
         return layout;
     }
 
-
     @Override
     public List<String> validate() {
         if (isWMode()) {
             return validateW();
-        }
-        else {
+        } else {
             return validateQ();
         }
     }
 
+    protected List<String> validateRange(final Map<String, double[]> ranges) {
+        final List<String> errors = new ArrayList<String>();
+        final NumberFormat nf = NumberFormat.getDecimalFormat();
 
-    protected List<String> validateRange(Map<String, double[]> ranges) {
-        List<String> errors = new ArrayList<String>();
-        NumberFormat nf     = NumberFormat.getDecimalFormat();
+        for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) {
 
-        for (Map.Entry<String, DoubleArrayPanel> entry: wqranges.entrySet()) {
-
-            String           key = entry.getKey();
-            DoubleArrayPanel dap = entry.getValue();
+            final String key = entry.getKey();
+            final DoubleArrayPanel dap = entry.getValue();
 
             if (!dap.validateForm()) {
-                errors.add(MSG.error_invalid_double_value());
+                errors.add(this.MSG.error_invalid_double_value());
                 return errors;
             }
 
-            double[] mm  = ranges.get(key);
+            final double[] mm = ranges.get(key);
             if (mm == null) {
-                SC.warn(MSG.error_read_minmax_values());
+                SC.warn(this.MSG.error_read_minmax_values());
                 continue;
             }
 
-            double[] values = dap.getInputValues();
-            double[] good   = new double[values.length];
+            final double[] values = dap.getInputValues();
+            final double[] good = new double[values.length];
 
             int idx = 0;
 
-            List<String> tmpErrors = new ArrayList<String>();
-            for (double value: values) {
+            final List<String> tmpErrors = new ArrayList<String>();
+            for (final double value : values) {
                 if (value < mm[0] || value > mm[1]) {
-                    String tmp = MSG.error_validate_range();
+                    String tmp = this.MSG.error_validate_range();
                     tmp = tmp.replace("$1", nf.format(value));
                     tmp = tmp.replace("$2", nf.format(mm[0]));
                     tmp = tmp.replace("$3", nf.format(mm[1]));
                     tmpErrors.add(tmp);
-                }
-                else {
+                } else {
                     good[idx++] = value;
                 }
             }
 
-            double[] justGood = new double[idx];
+            final double[] justGood = new double[idx];
             for (int i = 0; i < justGood.length; i++) {
                 justGood[i] = good[i];
             }
@@ -502,80 +477,74 @@
         return errors;
     }
 
-
     protected List<String> validateW() {
-        return validateRange(wranges);
+        return validateRange(this.wranges);
     }
 
-
     protected List<String> validateQ() {
-        return validateRange(qranges);
+        return validateRange(this.qranges);
     }
 
-
-    protected void initUserDefaults(DataList dataList) {
+    protected void initUserDefaults(final DataList dataList) {
         initUserWQValues(dataList);
         initUserWQMode(dataList);
     }
 
+    protected void initUserWQMode(final DataList dataList) {
+        final List<Data> allData = dataList.getAll();
 
-    protected void initUserWQMode(DataList dataList) {
-        List<Data> allData = dataList.getAll();
-
-        Data     dDef  = getData(allData, "wq_mode");
-        DataItem def   = dDef != null ? dDef.getDefault() : null;
-        String   value = def != null ? def.getStringValue() : null;
+        final Data dDef = getData(allData, "wq_mode");
+        final DataItem def = dDef != null ? dDef.getDefault() : null;
+        final String value = def != null ? def.getStringValue() : null;
 
         if (value != null && value.equals(FIELD_WQ_W)) {
-            modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W);
-        }
-        else {
-            modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q);
+            this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W);
+        } else {
+            this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q);
         }
     }
 
+    protected void initUserWQValues(final DataList dataList) {
+        final List<Data> allData = dataList.getAll();
 
-    protected void initUserWQValues(DataList dataList) {
-        List<Data> allData = dataList.getAll();
-
-        Data     dDef  = getData(allData, "wq_values");
-        DataItem def   = dDef != null ? dDef.getDefault() : null;
-        String   value = def != null ? def.getStringValue() : null;
+        final Data dDef = getData(allData, "wq_values");
+        final DataItem def = dDef != null ? dDef.getDefault() : null;
+        final String value = def != null ? def.getStringValue() : null;
 
         if (value == null || value.length() == 0) {
             return;
         }
 
-        String[] lines = value.split(GAUGE_SEPARATOR);
+        final String[] lines = value.split(GAUGE_SEPARATOR);
 
         if (lines == null || lines.length == 0) {
             return;
         }
 
-        for (String line: lines) {
-            String[] cols  = line.split(GAUGE_PART_SEPARATOR);
-            String   title = createLineTitle(line);
+        for (final String line : lines) {
+            final String[] cols = line.split(GAUGE_PART_SEPARATOR);
+            final String title = createLineTitle(line);
 
             if (cols == null || cols.length < 3) {
                 continue;
             }
 
-            String[] strValues = cols[2].split(VALUE_SEPARATOR);
-            double[] values    = new double[strValues.length];
+            final String[] strValues = cols[2].split(VALUE_SEPARATOR);
+            final double[] values = new double[strValues.length];
 
             int idx = 0;
 
-            for (String strValue: strValues) {
+            for (final String strValue : strValues) {
                 try {
                     values[idx++] = Double.valueOf(strValue);
                 }
-                catch (NumberFormatException nfe) {
+                catch (final NumberFormatException nfe) {
                     // do nothing
                 }
             }
 
-            String           key = cols[0] + GAUGE_PART_SEPARATOR + cols[1];
-            DoubleArrayPanel dap = wqranges.get(key);
+            final String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1];
+            final DoubleArrayPanel dap = this.wqranges.get(key);
 
             if (dap == null) {
                 continue;
@@ -586,55 +555,54 @@
     }
 
     /** Populate Gauge Ranges array. */
-    private void readGaugeRanges(DataList dataList) {
-        DataItem[] items = getWQItems(dataList);
-        gaugeRanges = new double[items.length][2];
+    private void readGaugeRanges(final DataList dataList) {
+        final DataItem[] items = getWQItems(dataList);
+        this.gaugeRanges = new ArrayList<Double[]>();
 
         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]);
+        for (final DataItem item : items) {
+            if (item instanceof WQDataItem) {
+                final String[] startEndKm = item.getLabel().split(";");
+                final Double[] kvp = new Double[] { Double.parseDouble(startEndKm[0]), Double.parseDouble(startEndKm[1]) };
+                this.gaugeRanges.add(kvp);
+            }
             i++;
         }
     }
 
+    protected Canvas createList(final DataList dataList) {
+        final VLayout layout = new VLayout();
 
-    protected Canvas createList(DataList dataList) {
-        VLayout layout = new VLayout();
-
-        DataItem[] items = getWQItems(dataList);
+        final DataItem[] items = getWQItems(dataList);
 
         int i = 0;
 
-        for (DataItem item: items) {
-            String title = item.getLabel(); // of form: 70.5;112.0
-            String label = item.getStringValue();
+        for (final DataItem item : items) {
+            if (item instanceof WQDataItem) {
+                final String title = item.getLabel(); // of form: 70.5;112.0
+                final 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 + ")");
+                // Rename W and Q tab to include gauges name.
+                this.tabs.getTab(i * 2).setTitle(this.tabs.getTab(i * 2).getTitle() + " (" + label + ")");
+                this.tabs.getTab(i * 2 + 1).setTitle(this.tabs.getTab(i * 2 + 1).getTitle() + " (" + label + ")");
 
-            DoubleArrayPanel dap = new DoubleArrayPanel(
-                label, null, this, this, TitleOrientation.LEFT);
+                final DoubleArrayPanel dap = new DoubleArrayPanel(label, null, this, this, TitleOrientation.LEFT);
 
-            wqranges.put(title, dap);
-            doubleArrayPanels.add(dap);
+                this.wqranges.put(title, dap);
+                this.doubleArrayPanels.add(dap);
 
-            if (item instanceof WQDataItem) {
-                WQDataItem wq = (WQDataItem) item;
-                double[] mmQ = wq.getQRange();
-                double[] mmW = wq.getWRange();
+                if (item instanceof WQDataItem) {
+                    final WQDataItem wq = (WQDataItem) item;
+                    final double[] mmQ = wq.getQRange();
+                    final double[] mmW = wq.getWRange();
 
-                qranges.put(title, mmQ);
-                wranges.put(title, mmW);
+                    this.qranges.put(title, mmQ);
+                    this.wranges.put(title, mmW);
+                }
+
+                layout.addMember(dap);
             }
-
-            layout.addMember(dap);
             i++;
         }
 
@@ -643,15 +611,14 @@
         return layout;
     }
 
+    /** Get items which are not WQ_MODE. */
+    protected DataItem[] getWQItems(final DataList dataList) {
+        final List<Data> data = dataList.getAll();
 
-    /** Get items which are not WQ_MODE. */
-    protected DataItem[] getWQItems(DataList dataList) {
-        List<Data> data = dataList.getAll();
+        for (final Data d : data) {
+            final String name = d.getLabel();
 
-        for (Data d: data) {
-            String name = d.getLabel();
-
-            if (name.equals(FIELD_WQ_MODE)) {
+            if (name.equals(FIELD_WQ_MODE) || name.startsWith("ignore_")) {
                 continue;
             }
 
@@ -661,137 +628,121 @@
         return null;
     }
 
-
     /**
      * Create radio button for switching w and q input.
      * Radiobutton-change also triggers helper panel tab selection.
      */
-    protected Canvas createMode(DataList dataList) {
-        RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE);
+    protected Canvas createMode(final DataList dataList) {
+        final RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE);
         wq.setShowTitle(false);
         wq.setVertical(false);
         wq.setWidth(200);
 
-        LinkedHashMap wqValues = new LinkedHashMap();
-        wqValues.put(FIELD_WQ_W, MSG.wqW());
-        wqValues.put(FIELD_WQ_Q, MSG.wqQatGauge());
+        final LinkedHashMap wqValues = new LinkedHashMap();
+        wqValues.put(FIELD_WQ_W, this.MSG.wqW());
+        wqValues.put(FIELD_WQ_Q, this.MSG.wqQatGauge());
 
         wq.setValueMap(wqValues);
 
-        modes = new DynamicForm();
-        modes.setFields(wq);
-        modes.setWidth(200);
+        this.modes = new DynamicForm();
+        this.modes.setFields(wq);
+        this.modes.setWidth(200);
         wq.addChangeHandler(new ChangeHandler() {
             @Override
-            public void onChange(ChangeEvent e) {
-                DynamicForm form = e.getForm();
+            public void onChange(final ChangeEvent e) {
+                final DynamicForm form = e.getForm();
 
-                if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) {
-                    tabs.selectTab(0);
+                if (form.getValueAsString(FIELD_WQ_MODE).contains("Q")) {
+                    WQAdaptedInputPanel.this.tabs.selectTab(0);
                     enableQTabs();
-                }
-                else {
-                    tabs.selectTab(1);
+                } else {
+                    WQAdaptedInputPanel.this.tabs.selectTab(1);
                     enableWTabs();
                 }
             }
         });
 
-
-        LinkedHashMap initial = new LinkedHashMap();
+        final LinkedHashMap initial = new LinkedHashMap();
         initial.put(FIELD_WQ_MODE, FIELD_WQ_Q);
-        modes.setValues(initial);
-        tabs.selectTab(1);
-        return modes;
+        this.modes.setValues(initial);
+        this.tabs.selectTab(1);
+        return this.modes;
     }
 
-
     public void enableWTabs() {
-        for (int i = 0; i < doubleArrayPanels.size(); i++) {
-            tabs.disableTab(2*i);
-            tabs.enableTab(2*i+1);
+        for (int i = 0; i < this.doubleArrayPanels.size(); i++) {
+            this.tabs.disableTab(2 * i);
+            this.tabs.enableTab(2 * i + 1);
         }
     }
 
-
     public void enableQTabs() {
-        for (int i = 0; i < doubleArrayPanels.size(); i++) {
-            tabs.enableTab(2*i);
-            tabs.disableTab(2*i+1);
+        for (int i = 0; i < this.doubleArrayPanels.size(); i++) {
+            this.tabs.enableTab(2 * i);
+            this.tabs.disableTab(2 * i + 1);
         }
     }
 
-
-    public String createLineTitle(String key) {
-        String[] splitted = key.split(";");
+    public String createLineTitle(final String key) {
+        final String[] splitted = key.split(";");
 
         return splitted[0] + " - " + splitted[1];
     }
 
-
     @Override
     public Data[] getData() {
-        Data mode   = getWQMode();
-        Data values = getWQValues();
+        final Data mode = getWQMode();
+        final Data values = getWQValues();
 
         return new Data[] { mode, values };
     }
 
-
     public boolean isWMode() {
-        String mode = (String) modes.getValue(FIELD_WQ_MODE);
+        final String mode = (String) this.modes.getValue(FIELD_WQ_MODE);
 
         return FIELD_WQ_W.equals(mode);
     }
 
-
     protected Data getWQMode() {
-        String wqMode = modes.getValueAsString(FIELD_WQ_MODE);
+        final String wqMode = this.modes.getValueAsString(FIELD_WQ_MODE);
         String value = "false";
         if (wqMode.equals("Q")) {
             value = "true";
         }
-        DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value);
-        Data mode = new DefaultData(
-            "wq_isq", null, null, new DataItem[] { item });
+        final DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value);
+        final Data mode = new DefaultData("wq_isq", null, null, new DataItem[] { item });
 
         return mode;
     }
 
-
     protected Data getWQValues() {
         String wqvalue = null;
 
-        for (Map.Entry<String, DoubleArrayPanel> entry: wqranges.entrySet()) {
-            String           key = entry.getKey();
-            DoubleArrayPanel dap = entry.getValue();
-            String label = dap.getItemTitle();
+        for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) {
+            final String key = entry.getKey();
+            final DoubleArrayPanel dap = entry.getValue();
+            final String label = dap.getItemTitle();
 
-            double[] values = dap.getInputValues();
+            final double[] values = dap.getInputValues();
             if (wqvalue == null) {
                 wqvalue = createValueString(key + ";" + label, values);
-            }
-            else {
-                wqvalue += GAUGE_SEPARATOR
-                    + createValueString(key + ";" + label, values);
+            } else {
+                wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values);
             }
         }
 
-        DataItem valueItem = new DefaultDataItem(
-            "wq_values", "wq_values", wqvalue);
-        Data values = new DefaultData(
-            "wq_values", null, null, new DataItem[] { valueItem });
+        final DataItem valueItem = new DefaultDataItem("wq_values", "wq_values", wqvalue);
+        final Data values = new DefaultData("wq_values", null, null, new DataItem[] { valueItem });
 
         return values;
     }
 
-
-    protected String createValueString(String key, double[] values) {
-        StringBuilder sb = new StringBuilder();
+    protected String createValueString(final String key, final double[] values) {
+        final StringBuilder sb = new StringBuilder();
 
         boolean first = true;
 
-        for (double value: values) {
+        for (final double value : values) {
             if (!first) {
                 sb.append(",");
             }
@@ -804,118 +755,108 @@
         return key + ";" + sb.toString();
     }
 
-
     @Override
-    public void onChange(ChangeEvent event) {
+    public void onChange(final ChangeEvent event) {
         // TODO IMPLEMENT ME
     }
 
-
     /** Store the currently focussed DoubleArrayPanel and focus helper tab. */
     @Override
-    public void onFocus(FocusEvent event) {
-        itemWithFocus = (DoubleArrayPanel) event.getForm();
+    public void onFocus(final FocusEvent event) {
+        this.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));
+        final int inputIndex = this.doubleArrayPanels.indexOf(this.itemWithFocus);
+        this.tabs.selectTab(inputIndex * 2 + (isWMode() ? 0 : 1));
     }
 
-
     @Override
-    public void onBlur(BlurEvent event) {
-        DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm();
+    public void onBlur(final BlurEvent event) {
+        final DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm();
         dap.validateForm(event.getItem());
     }
 
-
     /** Get the WQD data from service and stuck them up that tables. */
     protected void fetchWQData() {
-        Config config    = Config.getInstance();
-        String locale    = config.getLocale ();
+        final Config config = Config.getInstance();
+        final String locale = config.getLocale();
 
-        ArtifactDescription adescr = artifact.getArtifactDescription();
-        DataList[] data = adescr.getOldData();
+        final ArtifactDescription adescr = this.artifact.getArtifactDescription();
+        final DataList[] data = adescr.getOldData();
 
-        double[]  mm = getMinMaxKM(data);
-        String river = getRiverName(data);
+        final double[] mm = getMinMaxKM(data);
+        final String river = getRiverName(data);
 
         int i = 0;
 
         // Get Data for respective gauge.
-        for (double[] range : gaugeRanges){
+        for (final Double[] range : this.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());
+            this.wqInfoService.getWQInfo(locale, river, range[0] + rDiff, range[1] - rDiff, new AsyncCallback<WQInfoObject[]>() {
+                @Override
+                public void onFailure(final Throwable caught) {
+                    GWT.log("Could not recieve wq informations.");
+                    SC.warn(caught.getMessage());
+                }
+
+                @Override
+                public void onSuccess(final WQInfoObject[] wqi) {
+                    final int num = wqi != null ? wqi.length : 0;
+                    GWT.log("Received " + num + " wq informations (" + fi + ".");
+
+                    if (num == 0) {
+                        return;
                     }
 
-                    @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);
-                    }
+                    addWQInfo(wqi, fi);
                 }
-            );
+            });
             i++;
         }
     }
 
-
     /** 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);
+    protected void addWQInfo(final WQInfoObject[] wqi, final int gaugeIdx) {
+        for (final WQInfoObject wi : wqi) {
+            final WQInfoRecord rec = new WQInfoRecord(wi);
 
             if (wi.getType().equals("W")) {
-                wTables.get(gaugeIdx).addData(rec);
-            }
-            else {
-                qdTables.get(gaugeIdx).addData(rec);
+                this.wTables.get(gaugeIdx).addData(rec);
+            } else {
+                this.qdTables.get(gaugeIdx).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.
+     * @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();
+    protected double[] getMinMaxKM(final DataList[] data) {
+        final ArtifactDescription adesc = this.artifact.getArtifactDescription();
         return adesc.getKMRange();
     }
 
-
     /**
      * Returns the name of the selected river.
      *
-     * @param data The DataList with all data.
+     * @param data
+     *            The DataList with all data.
      *
      * @return the name of the current river.
      */
-    protected String getRiverName(DataList[] data) {
-        ArtifactDescription adesc = artifact.getArtifactDescription();
+    protected String getRiverName(final DataList[] data) {
+        final ArtifactDescription adesc = this.artifact.getArtifactDescription();
         return adesc.getRiver();
     }
 }
diff -r 2323d005f9a5 -r 717c9dc1859f gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java	Fri Jul 20 10:39:02 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java	Fri Jul 20 11:19:07 2018 +0200
@@ -15,6 +15,7 @@
 import org.dive4elements.river.client.client.ui.DoubleArrayPanel;
 import org.dive4elements.river.client.client.ui.WQAdaptedInputPanel;
 import org.dive4elements.river.client.shared.model.Data;
+import org.dive4elements.river.client.shared.model.DataItem;
 import org.dive4elements.river.client.shared.model.DataList;
 
 import com.google.gwt.i18n.client.NumberFormat;
@@ -29,11 +30,23 @@
 public class BunduWstWQPanel extends WQAdaptedInputPanel {
     private static final long serialVersionUID = -3218827566805476423L;
 
+    private int bezugsjahr = 0;
+    private int qSeriesLength = 0;
+
     /** get bezugsjahr + range from server HERE **/
     @Override
     public Canvas create(final DataList data) {
-        final Data test = data.get(0);
 
+        for (final Data container : data.getAll()) {
+
+            for (final DataItem item : container.getItems()) {
+                if ("ignore_bezugsjahr".equals(item.getLabel())) {
+                    this.bezugsjahr = Integer.valueOf(item.getStringValue());
+                } else if ("ignore_q_series_length".equals(item.getLabel())) {
+                    this.qSeriesLength = Integer.valueOf(item.getStringValue());
+                }
+            }
+        }
         return super.create(data);
     }
 


More information about the Dive4Elements-commits mailing list