Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java @ 563:469528551b78
Introduced an input validation for the location panels.
flys-client/trunk@2104 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 14 Jun 2011 10:42:34 +0000 |
parents | 2e02db03e576 |
children | 1d20533a4ae3 |
comparison
equal
deleted
inserted
replaced
562:9f16ac843dda | 563:469528551b78 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.ArrayList; | |
3 import java.util.List; | 4 import java.util.List; |
4 | 5 |
5 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
7 import com.google.gwt.i18n.client.NumberFormat; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | 8 import com.google.gwt.user.client.rpc.AsyncCallback; |
7 | 9 |
10 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Canvas; | 11 import com.smartgwt.client.widgets.Canvas; |
9 import com.smartgwt.client.widgets.Label; | 12 import com.smartgwt.client.widgets.Label; |
10 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; | 13 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; |
11 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; | 14 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; |
12 import com.smartgwt.client.widgets.form.fields.FormItem; | 15 import com.smartgwt.client.widgets.form.fields.FormItem; |
55 GWT.create(DistanceInfoService.class); | 58 GWT.create(DistanceInfoService.class); |
56 | 59 |
57 /** A container that will contain the location or the distance panel.*/ | 60 /** A container that will contain the location or the distance panel.*/ |
58 protected HLayout container; | 61 protected HLayout container; |
59 | 62 |
63 /** The minimal value that the user is allowed to enter.*/ | |
64 protected double min; | |
65 | |
66 /** The maximal value that the user is allowed to enter.*/ | |
67 protected double max; | |
68 | |
60 /** The values entered in the location mode.*/ | 69 /** The values entered in the location mode.*/ |
61 protected double[] values; | 70 protected double[] values; |
62 | 71 |
63 /** The input panel for locations */ | 72 /** The input panel for locations */ |
64 protected DoubleArrayPanel locationPanel; | 73 protected DoubleArrayPanel locationPanel; |
183 | 192 |
184 if (data == null) { | 193 if (data == null) { |
185 return; | 194 return; |
186 } | 195 } |
187 | 196 |
197 DataItem[] items = data.getItems(); | |
198 DataItem iMin = getDataItem(items, "min"); | |
199 DataItem iMax = getDataItem(items, "max"); | |
200 | |
201 try { | |
202 min = Double.parseDouble(iMin.getStringValue()); | |
203 max = Double.parseDouble(iMax.getStringValue()); | |
204 } | |
205 catch (NumberFormatException nfe) { | |
206 SC.warn(MESSAGES.error_read_minmax_values()); | |
207 min = -Double.MAX_VALUE; | |
208 max = Double.MAX_VALUE; | |
209 } | |
210 | |
188 DataItem def = data.getDefault(); | 211 DataItem def = data.getDefault(); |
189 String value = def.getStringValue(); | 212 String value = def.getStringValue(); |
190 | 213 |
191 try { | 214 try { |
192 double d = Double.parseDouble(value); | 215 double d = Double.parseDouble(value); |
234 container.setMembersMargin(30); | 257 container.setMembersMargin(30); |
235 | 258 |
236 helperContainer.addChild(locationTable); | 259 helperContainer.addChild(locationTable); |
237 createInputPanel(); | 260 createInputPanel(); |
238 return layout; | 261 return layout; |
262 } | |
263 | |
264 | |
265 @Override | |
266 public List<String> validate() { | |
267 List<String> errors = new ArrayList<String>(); | |
268 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
269 | |
270 saveLocationValues(locationPanel); | |
271 | |
272 if (!locationPanel.validateForm()) { | |
273 errors.add(MESSAGES.wrongFormat()); | |
274 return errors; | |
275 } | |
276 | |
277 double[] values = getLocationValues(); | |
278 double[] good = new double[values.length]; | |
279 int idx = 0; | |
280 | |
281 for (double value: values) { | |
282 if (value < min || value > max) { | |
283 String tmp = MESSAGES.error_validate_range(); | |
284 tmp = tmp.replace("$1", nf.format(value)); | |
285 tmp = tmp.replace("$2", nf.format(min)); | |
286 tmp = tmp.replace("$3", nf.format(max)); | |
287 errors.add(tmp); | |
288 } | |
289 else { | |
290 good[idx++] = value; | |
291 } | |
292 } | |
293 | |
294 double[] justGood = new double[idx]; | |
295 for (int i = 0; i < justGood.length; i++) { | |
296 justGood[i] = good[i]; | |
297 } | |
298 | |
299 if (!errors.isEmpty()) { | |
300 locationPanel.setValues(justGood); | |
301 } | |
302 | |
303 return errors; | |
239 } | 304 } |
240 | 305 |
241 | 306 |
242 /** | 307 /** |
243 * This method returns the selected data. | 308 * This method returns the selected data. |