comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleRangePanel.java @ 7748:316a9eeb0836

Hopefully a cleaner fix for flys/issue1549 using the FloatRangeValidator from SmartGWT to verify that the 'to' field stays positive.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 21 Feb 2014 15:28:08 +0100
parents 1d6b957d8953
children 7337034eb5d5
comparison
equal deleted inserted replaced
7747:cfa7e2164f87 7748:316a9eeb0836
43 43
44 /** The constant name of the input field to enter the step width of a 44 /** The constant name of the input field to enter the step width of a
45 * distance.*/ 45 * distance.*/
46 public static final String FIELD_WIDTH = "step"; 46 public static final String FIELD_WIDTH = "step";
47 47
48 /** Whether or not negative 'to' values are allowed. */
49 protected boolean negativeToAllowed = true;
50
51 /** The textboxes */ 48 /** The textboxes */
52 protected FloatItem fromItem; 49 protected FloatItem fromItem;
53 protected FloatItem toItem; 50 protected FloatItem toItem;
54 protected FloatItem stepItem; 51 protected FloatItem stepItem;
55 52
56 53
57 public DoubleRangePanel() { 54 public DoubleRangePanel() {
55 }
56
57 public FloatItem getToItem() {
58 return toItem;
58 } 59 }
59 60
60 61
61 /** 62 /**
62 * Creates a new form with a single input field that displays an array of 63 * Creates a new form with a single input field that displays an array of
154 fromItem.setValue(f.format(from)); 155 fromItem.setValue(f.format(from));
155 toItem.setValue(f.format(to)); 156 toItem.setValue(f.format(to));
156 stepItem.setValue(f.format(steps)); 157 stepItem.setValue(f.format(steps));
157 } 158 }
158 159
159 public void setNegativeToAllowed(boolean isAllowed) {
160 negativeToAllowed = isAllowed;
161 }
162
163
164 public boolean validateForm() { 160 public boolean validateForm() {
165 try { 161 try {
166 return 162 return
167 validateForm(fromItem) && 163 validateForm(fromItem) &&
168 validateForm(toItem) && 164 validateForm(toItem) &&
195 191
196 NumberFormat f = NumberFormat.getDecimalFormat(); 192 NumberFormat f = NumberFormat.getDecimalFormat();
197 @SuppressWarnings("rawtypes") 193 @SuppressWarnings("rawtypes")
198 Map errors = getErrors(); 194 Map errors = getErrors();
199 195
200 Double d = 0d;
201
202 try { 196 try {
203 if (v == null) { 197 if (v == null) {
204 throw new NumberFormatException("empty"); 198 throw new NumberFormatException("empty");
205 } 199 }
206 200
207 d = f.parse(v); 201 f.parse(v);
208 202
209 errors.remove(item.getFieldName()); 203 errors.remove(item.getFieldName());
210 } 204 }
211 catch (NumberFormatException nfe) { 205 catch (NumberFormatException nfe) {
212 errors.put(item.getFieldName(), MESSAGES.wrongFormat()); 206 errors.put(item.getFieldName(), MESSAGES.wrongFormat());
214 item.focusInItem(); 208 item.focusInItem();
215 209
216 valid = false; 210 valid = false;
217 } 211 }
218 212
219 if (negativeToAllowed == false
220 && item.getFieldName().equals(FIELD_TO) && d < 0d) {
221 errors.put(item.getFieldName(), MESSAGES.toShouldNotBeNegative());
222
223 item.setValue("");
224
225 item.focusInItem();
226
227 valid = false;
228 }
229
230 setErrors(errors, true); 213 setErrors(errors, true);
231 214
232 return valid; 215 return valid;
233 } 216 }
234 217

http://dive4elements.wald.intevation.org