changeset 1536:4f4d29404dba

Filter the helper input tables using the range filter. flys-client/trunk@3754 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 24 Jan 2012 08:46:33 +0000
parents 03e82be2aabc
children 2b104fa094e2
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/event/RangeFilterEvent.java flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java
diffstat 5 files changed, 114 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jan 23 15:45:20 2012 +0000
+++ b/flys-client/ChangeLog	Tue Jan 24 08:46:33 2012 +0000
@@ -1,3 +1,17 @@
+2012-01-24  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java:
+	  Apply the filter input on the tables.
+
+	* src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java:
+	  Added validator to the input fields. Validates data on key up event.
+
+	* src/main/java/de/intevation/flys/client/client/event/RangeFilterEvent.java:
+	  Use Float as data type instead of String.
+
+	* src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java:
+	  Return false if the FormItem is null.
+
 2012-01-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/event/RangeFilterEvent.java	Mon Jan 23 15:45:20 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/event/RangeFilterEvent.java	Tue Jan 24 08:46:33 2012 +0000
@@ -1,27 +1,44 @@
 package de.intevation.flys.client.client.event;
 
+import com.google.gwt.i18n.client.NumberFormat;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
 public class RangeFilterEvent {
 
-    protected String from;
-    protected String to;
+    protected Float from;
+    protected Float to;
 
 
     public RangeFilterEvent(String from, String to) {
-        this.from = from;
-        this.to = to;
+        NumberFormat nf = NumberFormat.getDecimalFormat();
+        double d;
+
+        try {
+            d = nf.parse(from);
+            this.from = Float.valueOf(String.valueOf(d));
+        }
+        catch(NumberFormatException nfe) {
+            this.from = Float.NaN;
+        }
+        try {
+            d = nf.parse(to);
+            this.to = Float.valueOf(String.valueOf(d));
+        }
+        catch(NumberFormatException nfe) {
+            this.to = Float.NaN;
+        }
     }
 
 
-    public String getFrom() {
-        return String.valueOf(this.from);
+    public Float getFrom() {
+        return this.from;
     }
 
 
-    public String getTo() {
-        return String.valueOf(this.to);
+    public Float getTo() {
+        return this.to;
     }
 }
 // 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/LocationDistancePanel.java	Mon Jan 23 15:45:20 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Tue Jan 24 08:46:33 2012 +0000
@@ -8,6 +8,10 @@
 import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.Criterion;
+import com.smartgwt.client.data.AdvancedCriteria;
+import com.smartgwt.client.types.OperatorId;
+
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.DynamicForm;
@@ -782,7 +786,55 @@
 
 
     public void onFilterCriteriaChanged(RangeFilterEvent event) {
-        GWT.log("filtering range");
+        Float from = event.getFrom() - 0.001f;
+        Float to = event.getTo() + 0.001f;
+        GWT.log("filtering range: " + from + " to " + to);
+
+
+        Criterion combinedFilter = null;
+        Criterion locationFilter = null;
+        if (from.equals(Float.NaN) && to.equals(Float.NaN)) {
+            locationsTable.clearCriteria();
+            distanceTable.clearCriteria();
+            locationDistanceTable.clearCriteria();
+        }
+        else if (from.equals(Float.NaN)) {
+            combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to);
+            locationFilter =
+                new Criterion("from", OperatorId.LESS_OR_EQUAL, to);
+            locationsTable.filterData(locationFilter);
+            distanceTable.filterData(combinedFilter);
+            locationDistanceTable.filterData(combinedFilter);
+            return;
+        }
+        else if (to.equals(Float.NaN)) {
+            combinedFilter =
+                new Criterion("from", OperatorId.GREATER_OR_EQUAL, from);
+             locationsTable.filterData(combinedFilter);
+            distanceTable.filterData(combinedFilter);
+            locationDistanceTable.filterData(combinedFilter);
+        }
+        else {
+            AdvancedCriteria c1 =
+                new AdvancedCriteria(OperatorId.AND, new Criterion[] {
+                    new Criterion("from", OperatorId.GREATER_OR_EQUAL, from),
+                    new Criterion("from", OperatorId.LESS_OR_EQUAL, to)
+                });
+
+            AdvancedCriteria c2 =
+                new AdvancedCriteria(OperatorId.AND, new Criterion[] {
+                    new Criterion("to", OperatorId.GREATER_OR_EQUAL, from),
+                    new Criterion("to", OperatorId.LESS_OR_EQUAL, to)
+                });
+
+            combinedFilter =
+                new AdvancedCriteria(OperatorId.OR, new Criterion[] {
+                    c1, c2
+                });
+        }
+        locationsTable.filterData(combinedFilter);
+        distanceTable.filterData(combinedFilter);
+        locationDistanceTable.filterData(combinedFilter);
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java	Mon Jan 23 15:45:20 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/RangeTableFilter.java	Tue Jan 24 08:46:33 2012 +0000
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import com.google.gwt.core.client.GWT;
 
@@ -16,7 +17,7 @@
 import de.intevation.flys.client.client.event.FilterHandler;
 import de.intevation.flys.client.client.event.RangeFilterEvent;
 import de.intevation.flys.client.client.FLYSConstants;
-
+import de.intevation.flys.client.client.utils.DoubleValidator;
 
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
@@ -32,6 +33,7 @@
 
     protected TextItem fromField;
     protected TextItem toField;
+    protected DynamicForm filterForm;
 
     public RangeTableFilter() {
         super();
@@ -50,11 +52,11 @@
         toField.addChangedHandler(this);
         toField.addKeyUpHandler(this);
 
-        DynamicForm form = new DynamicForm();
-        form.setNumCols(4);
-        form.setFields(fromField, toField);
+        filterForm = new DynamicForm();
+        filterForm.setNumCols(4);
+        filterForm.setFields(fromField, toField);
 
-        addMember(form);
+        addMember(filterForm);
     }
 
 
@@ -65,6 +67,18 @@
 
 
     public void onKeyUp(KeyUpEvent event) {
+        DoubleValidator validator = new DoubleValidator();
+        Map errors = filterForm.getErrors();
+        if(event.getItem().getValue() != null && 
+           !validator.validate(event.getItem(), errors)) {
+            filterForm.setErrors(errors, true);
+            GWT.log("no valid input!");
+            return;
+        }
+        else {
+            errors.clear();
+            filterForm.setErrors(errors, true);
+        }
         //To deactivate "As you type" filter add
         // ' && event.getKeyName().equals("Enter")'
         // to the if-clause.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java	Mon Jan 23 15:45:20 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java	Tue Jan 24 08:46:33 2012 +0000
@@ -23,6 +23,9 @@
     public boolean validate(FormItem item, Map errors) {
         boolean valid = true;
 
+        if(item.getValue() == null) {
+            return false;
+        }
         String v = item.getValue().toString();
 
         NumberFormat f = NumberFormat.getDecimalFormat();

http://dive4elements.wald.intevation.org