changeset 780:a39c2f531755

Implemented a new panel to enter kilometer ranges (with no option to insert locations). flys-client/trunk@2269 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 30 Jun 2011 10:29:43 +0000
parents f1a559d13eef
children 6653cf54b45d
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/DistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java
diffstat 8 files changed, 322 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/ChangeLog	Thu Jun 30 10:29:43 2011 +0000
@@ -1,3 +1,22 @@
+2011-06-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java:
+	  New. This panel is used to insert kilometer ranges. There is no input
+	  mode for locations as it is in LocationDistancePanel.
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java:
+	  Added i18n strings for the distance panel.
+
+	* src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java:
+	  Added a method to set the step width.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Create a DistancePanel UIProvider if the "uiprovider" string in the
+	  DESCRIBE of an artifact equals "distance_panel".
+
 2011-06-29  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue185 (IE8 + Chromium: Kein Zoomen von Diagrammen möglich)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Jun 30 10:29:43 2011 +0000
@@ -104,6 +104,8 @@
 
     String location_distance_state();
 
+    String distance_state();
+
     String location();
 
     String locations();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Jun 30 10:29:43 2011 +0000
@@ -36,6 +36,7 @@
 fix = TODO FIX ANALYSE TODO
 next = Next
 location_distance_state = Choose calculation location(s) / range [km]
+distance_state = Choose calculation range [km]
 location = Location(s)
 locations = Locations
 distance = Range
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Jun 30 10:29:43 2011 +0000
@@ -36,6 +36,7 @@
 fix = Fixierungsanalyse
 next = Weiter
 location_distance_state = Berechnungsort(e) / strecke w\u00e4hlen [km]
+distance_state = Berechnungsstrecke w\u00e4hlen [km]
 location = Ort(e)
 locations = Orte
 distance = Strecke
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Jun 30 10:29:43 2011 +0000
@@ -36,6 +36,7 @@
 fix = TODO FIX ANALYSE TODO
 next = Next
 location_distance_state = Choose calculation location(s) / range [km]
+distance_state = Choose calculation range [km]
 location = Location(s)
 locations = Locations
 distance = Range
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DistancePanel.java	Thu Jun 30 10:29:43 2011 +0000
@@ -0,0 +1,285 @@
+package de.intevation.flys.client.client.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
+import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
+import com.smartgwt.client.widgets.layout.HLayout;
+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.client.FLYSConstants;
+
+
+public class DistancePanel extends AbstractUIProvider implements BlurHandler {
+
+    public static final int DEFAULT_STEP_WIDTH = 100;
+
+
+    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
+
+    protected DoubleRangePanel distancePanel;
+
+    protected double min;
+    protected double max;
+
+
+    public DistancePanel() {
+        distancePanel = new DoubleRangePanel(
+            MSG.unitFrom(), MSG.unitTo(), MSG.unitWidth(),
+            0d, 0d, 0d, 250, this);
+    }
+
+
+    @Override
+    public Canvas create(DataList data) {
+        VLayout layout = new VLayout();
+        layout.setMembersMargin(10);
+
+        Label label = new Label(MSG.distance_state());
+
+        Canvas submit = getNextButton();
+
+        label.setHeight(25);
+        distancePanel.setHeight(50);
+
+        layout.addMember(label);
+        layout.addMember(distancePanel);
+        layout.addMember(submit);
+
+        initMinMaxValues(data);
+        initDefaultValues(data);
+
+        return layout;
+    }
+
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        String s = getOldSelectionString(dataList);
+        String l = dataList.getLabel();
+
+        Label label    = new Label(l);
+        Label selected = new Label(s);
+
+        HLayout layout = new HLayout();
+
+        layout.setWidth(400);
+        label.setWidth(200);
+        selected.setWidth(130);
+
+        layout.addMember(label);
+        layout.addMember(selected);
+
+        return layout;
+    }
+
+
+    protected String getOldSelectionString(DataList dataList) {
+        List<Data> items = dataList.getAll();
+
+        Data dFrom = getData(items, "ld_from");
+        Data dTo   = getData(items, "ld_to");
+        Data dStep = getData(items, "ld_step");
+
+        DataItem[] from = dFrom.getItems();
+        DataItem[] to   = dTo.getItems();
+        DataItem[] step = dStep.getItems();
+
+        StringBuilder sb = new StringBuilder();
+        sb.append(from[0].getLabel());
+        sb.append(" " + MSG.unitFrom() + " ");
+        sb.append(to[0].getLabel());
+        sb.append(" " + MSG.unitTo() + " ");
+        sb.append(step[0].getLabel());
+        sb.append(" " + MSG.unitWidth());
+
+        return sb.toString();
+    }
+
+
+    @Override
+    public List<String> validate() {
+        List<String> errors = new ArrayList<String>();
+
+        if (!distancePanel.validateForm()) {
+            errors.add(MSG.wrongFormat());
+
+            return errors;
+        }
+
+        validateFrom(errors);
+        validateTo(errors);
+
+        return errors;
+    }
+
+
+    protected void validateFrom(List<String> errors) {
+        double from = distancePanel.getFrom();
+
+        if (from < min || from > max) {
+            NumberFormat nf = NumberFormat.getDecimalFormat();
+
+            String tmp = MSG.error_validate_lower_range();
+            tmp        = tmp.replace("$1", nf.format(from));
+            tmp        = tmp.replace("$2", nf.format(min));
+
+            distancePanel.setFrom(min);
+            errors.add(tmp);
+        }
+    }
+
+
+    protected void validateTo(List<String> errors) {
+        double to = distancePanel.getTo();
+
+        if (to < min || to > max) {
+            NumberFormat nf = NumberFormat.getDecimalFormat();
+
+            String tmp = MSG.error_validate_upper_range();
+            tmp        = tmp.replace("$1", nf.format(to));
+            tmp        = tmp.replace("$2", nf.format(max));
+
+            distancePanel.setTo(max);
+            errors.add(tmp);
+        }
+    }
+
+
+    @Override
+    public Data[] getData() {
+        Data[] data = new Data[3];
+
+        data[0] = getDataFrom();
+        data[1] = getDataTo();
+        data[2] = getDataStep();
+
+        return data;
+    }
+
+
+    protected Data getDataFrom() {
+        String value  = String.valueOf(distancePanel.getFrom());
+        DataItem item = new DefaultDataItem("ld_from", "ld_from", value);
+        return new DefaultData(
+            "ld_from", null, null, new DataItem[] { item });
+    }
+
+
+    protected Data getDataTo() {
+        String value  = String.valueOf(distancePanel.getTo());
+        DataItem item = new DefaultDataItem("ld_to", "ld_to", value);
+        return new DefaultData(
+            "ld_to", null, null, new DataItem[] { item });
+    }
+
+
+    protected Data getDataStep() {
+        String value  = String.valueOf(distancePanel.getStep());
+        DataItem item = new DefaultDataItem("ld_step","ld_step", value);
+        return new DefaultData(
+            "ld_step", null, null, new DataItem[] { item });
+    }
+
+
+    @Override
+    public void onBlur(BlurEvent event) {
+        distancePanel.validateForm();
+    }
+
+
+    protected void initMinMaxValues(DataList data) {
+        Data f = getData(data.getAll(), "ld_from");
+        Data t = getData(data.getAll(), "ld_to");
+
+        DataItem[] fItems = f.getItems();
+        DataItem[] tItems = t.getItems();
+
+        try {
+            min = Double.valueOf(fItems[0].getStringValue());
+            max = Double.valueOf(tItems[0].getStringValue());
+        }
+        catch (NumberFormatException nfe) {
+            min = -Double.MAX_VALUE;
+            max =  Double.MAX_VALUE;
+        }
+    }
+
+
+    protected void initDefaultValues(DataList data) {
+        initDefaultFrom(data);
+        initDefaultTo(data);
+        initDefaultStep(data);
+    }
+
+
+    protected void initDefaultFrom(DataList data) {
+        Data f = getData(data.getAll(), "ld_from");
+
+        double from = min;
+
+        try {
+            from = getDefaultValue(f);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        distancePanel.setFrom(from);
+    }
+
+
+    protected void initDefaultTo(DataList data) {
+        Data t = getData(data.getAll(), "ld_to");
+
+        double to = max;
+
+        try {
+            to = getDefaultValue(t);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        distancePanel.setTo(to);
+    }
+
+
+    protected void initDefaultStep(DataList data) {
+        Data s = getData(data.getAll(), "ld_step");
+
+        double step = (double) DEFAULT_STEP_WIDTH;
+
+        try {
+            step = getDefaultValue(s);
+        }
+        catch (NumberFormatException nfe) {
+            // do nothing
+        }
+
+        distancePanel.setStep(step);
+    }
+
+
+    protected double getDefaultValue(Data data)
+    throws NumberFormatException
+    {
+        DataItem def      = data.getDefault();
+        String   defValue = def != null ? def.getStringValue() : null;
+
+        return Double.valueOf(defValue);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java	Thu Jun 30 10:29:43 2011 +0000
@@ -250,5 +250,15 @@
     public void setTo(double value) {
         setDoubleValue(value, FIELD_TO);
     }
+
+
+    /**
+     * Sets a new step width.
+     *
+     * @param value The new step width.
+     */
+    public void setStep(double value) {
+        setDoubleValue(value, FIELD_WIDTH);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Wed Jun 29 12:33:58 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Thu Jun 30 10:29:43 2011 +0000
@@ -19,6 +19,9 @@
         else if (uiProvider.equals("location_panel")) {
             return new SingleLocationPanel();
         }
+        else if (uiProvider.equals("distance_panel")) {
+            return new DistancePanel();
+        }
         else if (uiProvider.equals("wq_panel")) {
             return new WQInputPanel();
         }

http://dive4elements.wald.intevation.org