comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java @ 5123:64766b89beb6

WQAdaptedInputPanel: Refactored to remove code dupes.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 27 Feb 2013 12:19:41 +0100
parents 5f70c73b11ed
children 17f4cd1acc96
comparison
equal deleted inserted replaced
5119:15ff9ddc765e 5123:64766b89beb6
266 else { 266 else {
267 return validateQ(); 267 return validateQ();
268 } 268 }
269 } 269 }
270 270
271 271 protected List<String> validateRange(Map<String, double[]> ranges) {
272 protected List<String> validateW() {
273 List<String> errors = new ArrayList<String>(); 272 List<String> errors = new ArrayList<String>();
274 NumberFormat nf = NumberFormat.getDecimalFormat(); 273 NumberFormat nf = NumberFormat.getDecimalFormat();
275 274
276 Iterator<String> iter = wqranges.keySet().iterator(); 275 Iterator<String> iter = wqranges.keySet().iterator();
277 276
284 if (!dap.validateForm()) { 283 if (!dap.validateForm()) {
285 errors.add(MSG.error_invalid_double_value()); 284 errors.add(MSG.error_invalid_double_value());
286 return errors; 285 return errors;
287 } 286 }
288 287
289 double[] mm = wranges.get(key); 288 double[] mm = ranges.get(key);
290 if (mm == null) { 289 if (mm == null) {
291 SC.warn(MSG.error_read_minmax_values()); 290 SC.warn(MSG.error_read_minmax_values());
292 continue; 291 continue;
293 } 292 }
294 293
324 323
325 return errors; 324 return errors;
326 } 325 }
327 326
328 327
328 protected List<String> validateW() {
329 return validateRange(wranges);
330 }
331
332
329 protected List<String> validateQ() { 333 protected List<String> validateQ() {
330 List<String> errors = new ArrayList<String>(); 334 return validateRange(qranges);
331 NumberFormat nf = NumberFormat.getDecimalFormat();
332
333 Iterator<String> iter = wqranges.keySet().iterator();
334
335 while (iter.hasNext()) {
336 List<String> tmpErrors = new ArrayList<String>();
337
338 String key = iter.next();
339 DoubleArrayPanel dap = wqranges.get(key);
340
341 if (!dap.validateForm()) {
342 errors.add(MSG.error_invalid_double_value());
343 return errors;
344 }
345
346 double[] mm = qranges.get(key);
347 if (mm == null) {
348 SC.warn(MSG.error_read_minmax_values());
349 continue;
350 }
351
352 double[] values = dap.getInputValues();
353 double[] good = new double[values.length];
354
355 int idx = 0;
356
357 for (double value: values) {
358 if (value < mm[0] || value > mm[1]) {
359 String tmp = MSG.error_validate_range();
360 tmp = tmp.replace("$1", nf.format(value));
361 tmp = tmp.replace("$2", nf.format(mm[0]));
362 tmp = tmp.replace("$3", nf.format(mm[1]));
363 tmpErrors.add(tmp);
364 }
365 else {
366 good[idx++] = value;
367 }
368 }
369
370 double[] justGood = new double[idx];
371 for (int i = 0; i < justGood.length; i++) {
372 justGood[i] = good[i];
373 }
374
375 if (!tmpErrors.isEmpty()) {
376 dap.setValues(justGood);
377
378 errors.addAll(tmpErrors);
379 }
380 }
381
382 return errors;
383 } 335 }
384 336
385 337
386 protected void initUserDefaults(DataList dataList) { 338 protected void initUserDefaults(DataList dataList) {
387 339

http://dive4elements.wald.intevation.org