changeset 1528:ff41405a891d

Added a new widget to simply insert a WQ mode and values as array. flys-client/trunk@3726 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 19 Jan 2012 17:03:38 +0000
parents 252c22237fe7
children e91f87b2524e
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/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java
diffstat 7 files changed, 316 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/ChangeLog	Thu Jan 19 17:03:38 2012 +0000
@@ -1,3 +1,19 @@
+2012-01-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java:
+	  New. This widget allows choosing between W/Q mode and inserting values as
+	  array.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  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_de.properties:
+	  Added labels for historical WQ selection used in WQSimpleArrayPanel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Create new instances of WQSimpleArrayPanel if ui provider is set to
+	  'wq_simple_array'.
+
 2012-01-19  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Jan 19 17:03:38 2012 +0000
@@ -226,6 +226,8 @@
 
     String wqadaptedTitle();
 
+    String wqHistorical();
+
     String unitWNN();
 
     String wqW();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Jan 19 17:03:38 2012 +0000
@@ -128,6 +128,7 @@
 
 wqTitle = Input for W/Q Data
 wqadaptedTitle = Input for W/Q Data
+wqHistorical = Selection of Analyse Type
 calcTableTitle = Calculated Output
 helperPanelTitle = Input Support
 wqW = W at Gauge [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Jan 19 17:03:38 2012 +0000
@@ -128,6 +128,7 @@
 
 wqTitle = Eingabe f\u00fcr W/Q Daten
 wqadaptedTitle = Eingabe f\u00fcr W/Q Daten
+wqHistorical = Auswahl der Analyseart
 calcTableTitle = Berechnungsausgabe
 helperPanelTitle = Eingabeunterst\u00fctzung
 wqW = W am Pegel [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Jan 19 17:03:38 2012 +0000
@@ -128,6 +128,7 @@
 
 wqTitle = Input for W/Q Data
 wqadaptedTitle = Input for W/Q Data
+wqHistorical = Selection of Analyse Type
 calcTableTitle = Calculated Output
 helperPanelTitle = Input Support
 wqW = W at Gauge [cm]
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Jan 19 16:59:43 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Jan 19 17:03:38 2012 +0000
@@ -65,6 +65,9 @@
         else if (uiProvider.equals("timerange")) {
             return new IntegerRangePanel();
         }
+        else if (uiProvider.equals("wq_simple_array")) {
+            return new WQSimpleArrayPanel();
+        }
         else {
             return new SelectProvider();
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQSimpleArrayPanel.java	Thu Jan 19 17:03:38 2012 +0000
@@ -0,0 +1,292 @@
+package de.intevation.flys.client.client.ui;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
+import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
+import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+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.IntegerArrayData;
+import de.intevation.flys.client.shared.model.IntegerOptionsData;
+import de.intevation.flys.client.client.FLYSConstants;
+
+
+/**
+ * An UIProvider for inserting a mode for W or Q and an array of values for each
+ * mode.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class WQSimpleArrayPanel
+extends      AbstractUIProvider
+implements   BlurHandler
+{
+    public static final String FIELD_MODE   = "field_mode";
+    public static final String FIELD_VALUES = "field_values";
+
+    public static final int MODE_W = 0;
+
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    protected String modeName;
+    protected String valuesName;
+
+    protected Canvas valuesWrapper;
+
+    protected DynamicForm      modeForm;
+    protected DoubleArrayPanel panelW;
+    protected DoubleArrayPanel panelQ;
+
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout rootLayout = new VLayout();
+        rootLayout.addMember(createLabel(data));
+        rootLayout.addMember(createModeForm(data));
+        rootLayout.addMember(createValuesForm(data));
+        rootLayout.addMember(getNextButton());
+
+        initializeMode(data);
+
+        return rootLayout;
+    }
+
+
+    @Override
+    public Canvas createOld(DataList data) {
+        // TODO IMPLEMENT ME
+        return new Canvas();
+    }
+
+
+    @Override
+    protected Data[] getData() {
+        Data mode = getModeAsData();
+
+        if (getMode() == MODE_W) {
+            return new Data[] { mode, getWValuesAsData() };
+        }
+        else {
+            return new Data[] { mode, getQValuesAsData() };
+        }
+    }
+
+
+    @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+
+        // TODO IMPLEMENT ME
+
+        return errors;
+    }
+
+
+    @Override
+    public void onBlur(BlurEvent event) {
+        // TODO TRIGGER VALIDATION HERE
+    }
+
+
+    protected void initializeMode(DataList dataList) {
+        IntegerOptionsData data  = findOptionsData(dataList);
+        DataItem[]         items = data != null ? data.getItems() : null;
+
+        if (items != null) {
+            String value = items[0].getStringValue();
+            modeForm.setValue(modeName, value);
+            switchMode(value);
+        }
+    }
+
+
+    protected Canvas createLabel(DataList dataList) {
+        Label label = new Label(MSG.wqHistorical());
+        label.setWidth100();
+        label.setHeight(25);
+
+        return label;
+    }
+
+
+    protected IntegerArrayData findValuesData(DataList dataList) {
+        IntegerArrayData data = null;
+
+        for (int i = 0, n = dataList.size(); i < n; i++) {
+            Data tmp = dataList.get(i);
+
+            if (tmp instanceof IntegerArrayData) {
+                return (IntegerArrayData) tmp;
+            }
+        }
+
+        return null;
+    }
+
+
+    protected IntegerOptionsData findOptionsData(DataList dataList) {
+        IntegerOptionsData data = null;
+
+        for (int i = 0, n = dataList.size(); i < n; i++) {
+            Data tmp = dataList.get(i);
+
+            if (tmp instanceof IntegerOptionsData) {
+                return (IntegerOptionsData) tmp;
+            }
+        }
+
+        return null;
+    }
+
+
+    protected Canvas createModeForm(DataList dataList) {
+        IntegerOptionsData data = findOptionsData(dataList);
+        DataItem[]         opts = data != null ? data.getItems() : null;
+
+        if (data == null || opts == null) {
+            return new Label("NO MODES FOUND");
+        }
+
+        modeName = data.getLabel();
+        modeForm = new DynamicForm();
+
+        RadioGroupItem items = new RadioGroupItem(data.getLabel());
+        LinkedHashMap values = new LinkedHashMap();
+
+        for (DataItem opt: opts) {
+            values.put(opt.getStringValue(), opt.getLabel());
+        }
+
+        items.setValueMap(values);
+        items.setVertical(false);
+        items.setShowTitle(false);
+        items.addChangedHandler(new ChangedHandler() {
+            @Override
+            public void onChanged(ChangedEvent event) {
+                switchMode((String) event.getValue());
+            }
+        });
+
+        modeForm.setFields(items);
+
+        return modeForm;
+    }
+
+
+    protected Canvas createValuesForm(DataList dataList) {
+        IntegerArrayData data = findValuesData(dataList);
+
+        if (data == null) {
+            return new Label("NO VALUES GIVEN!");
+        }
+
+        valuesName = data.getLabel();
+        panelW     = new DoubleArrayPanel(MSG.unitWSingle(), null, this);
+        panelQ     = new DoubleArrayPanel(MSG.unitQSingle(), null, this);
+
+        valuesWrapper = new Canvas();
+        valuesWrapper.setWidth100();
+        valuesWrapper.setHeight(35);
+
+        return valuesWrapper;
+    }
+
+
+    public void switchMode(String newMode) {
+        for (Canvas child: valuesWrapper.getChildren()) {
+            valuesWrapper.removeChild(child);
+        }
+
+        if (newMode.equals("0")) {
+            valuesWrapper.addChild(panelW);
+        }
+        else if (newMode.equals("1")) {
+            valuesWrapper.addChild(panelQ);
+        }
+    }
+
+
+    public String getModeAsString() {
+        return (String) modeForm.getValue(modeName);
+    }
+
+
+    public int getMode() {
+        String modeValue = getModeAsString();
+
+        try {
+            return Integer.valueOf(modeValue);
+        }
+        catch (NumberFormatException nfe) {
+            // do something
+        }
+        catch (NullPointerException npe) {
+            // do something
+        }
+
+        return -1;
+    }
+
+
+    public Data getModeAsData() {
+        String  value = getModeAsString();
+        DataItem item = new DefaultDataItem(value, value, value);
+
+        return new DefaultData(modeName, null, null, new DataItem[] { item });
+    }
+
+
+    public Data getWValuesAsData() {
+        double[] values = panelW.getInputValues();
+        String valueStr = getStringValue(values);
+
+        DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr);
+
+        return new DefaultData(valuesName, null, null, new DataItem[] { item });
+    }
+
+
+    public Data getQValuesAsData() {
+        double[] values = panelQ.getInputValues();
+        String valueStr = getStringValue(values);
+
+        DataItem item = new DefaultDataItem(valueStr, valueStr, valueStr);
+
+        return new DefaultData(valuesName, null, null, new DataItem[] { item });
+    }
+
+
+    protected static String getStringValue(double[] values) {
+        StringBuilder sb = new StringBuilder();
+        boolean    first = true;
+
+        for (double value: values) {
+            if (first) {
+                sb.append(String.valueOf(value));
+                first = false;
+            }
+            else {
+                sb.append(";" + String.valueOf(value));
+            }
+        }
+
+        return sb.toString();
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org