[PATCH] Hopefully a cleaner fix for flys/issue1549 using the FloatRangeValidator from SmartGWT to verify that the 'to' field stays positive
Wald Commits
scm-commit at wald.intevation.org
Fri Feb 21 15:28:14 CET 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1392992888 -3600
# Node ID 316a9eeb08365c8bbdd79b3ecb6c948ac7300e05
# Parent cfa7e2164f87c41243b4324282f700c63d046894
Hopefully a cleaner fix for flys/issue1549 using the FloatRangeValidator from SmartGWT to verify that the 'to' field stays positive.
diff -r cfa7e2164f87 -r 316a9eeb0836 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanel.java Fri Feb 21 15:28:08 2014 +0100
@@ -97,7 +97,6 @@
distancePanel = new DoubleRangePanel(
labelFrom(), labelTo(), labelStep(),
0d, 0d, 0d, 250, this, labelOrientation);
- distancePanel.setNegativeToAllowed(false);
}
diff -r cfa7e2164f87 -r 316a9eeb0836 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java Fri Feb 21 15:28:08 2014 +0100
@@ -45,9 +45,6 @@
* distance.*/
public static final String FIELD_WIDTH = "step";
- /** Whether or not negative 'to' values are allowed. */
- protected boolean negativeToAllowed = true;
-
/** The textboxes */
protected FloatItem fromItem;
protected FloatItem toItem;
@@ -57,6 +54,10 @@
public DoubleRangePanel() {
}
+ public FloatItem getToItem() {
+ return toItem;
+ }
+
/**
* Creates a new form with a single input field that displays an array of
@@ -156,11 +157,6 @@
stepItem.setValue(f.format(steps));
}
- public void setNegativeToAllowed(boolean isAllowed) {
- negativeToAllowed = isAllowed;
- }
-
-
public boolean validateForm() {
try {
return
@@ -197,14 +193,12 @@
@SuppressWarnings("rawtypes")
Map errors = getErrors();
- Double d = 0d;
-
try {
if (v == null) {
throw new NumberFormatException("empty");
}
- d = f.parse(v);
+ f.parse(v);
errors.remove(item.getFieldName());
}
@@ -216,17 +210,6 @@
valid = false;
}
- if (negativeToAllowed == false
- && item.getFieldName().equals(FIELD_TO) && d < 0d) {
- errors.put(item.getFieldName(), MESSAGES.toShouldNotBeNegative());
-
- item.setValue("");
-
- item.focusInItem();
-
- valid = false;
- }
-
setErrors(errors, true);
return valid;
diff -r cfa7e2164f87 -r 316a9eeb0836 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java Tue Feb 11 16:18:57 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WaterlevelGroundPanel.java Fri Feb 21 15:28:08 2014 +0100
@@ -8,7 +8,7 @@
package org.dive4elements.river.client.client.ui;
-import java.util.List;
+import com.smartgwt.client.widgets.form.validator.FloatRangeValidator;
public class WaterlevelGroundPanel extends DistancePanel {
@@ -21,6 +21,11 @@
public WaterlevelGroundPanel() {
super("left");
+
+ FloatRangeValidator frv = new FloatRangeValidator();
+ frv.setMin(0f);
+ frv.setMax(Float.MAX_VALUE);
+ distancePanel.getToItem().setValidators(frv);
}
@@ -125,16 +130,5 @@
// We don't need a helper panel here. But we have to override this
// method to avoid the table creation in the parent class.
}
-
- @Override
- protected void validateTo(List<String> errors) {
- double to = distancePanel.getTo();
-
- if (to < 0d) {
- distancePanel.setTo(max);
- errors.add(MSG.negative_values_not_allowed_for_to());
- }
- super.validateTo(errors);
- }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4elements-commits
mailing list