comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedFixingInputPanel.java @ 6060:0a200ba54461

Fix WQ input validation for fixing analysis It is basically the same as the other WQ inputs but here all positive numbers are valid.
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 22 May 2013 17:08:06 +0200
parents
children e6bdba4f227f
comparison
equal deleted inserted replaced
6059:5f52a8079625 6060:0a200ba54461
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.client.client.ui;
10
11 import com.google.gwt.i18n.client.NumberFormat;
12
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
16 import java.util.Map;
17
18 /**
19 * This UIProvider creates a widget to enter W or Q data for
20 * Fixation analysis
21 *
22 * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
23 */
24 public class WQAdaptedFixingInputPanel
25 extends WQAdaptedInputPanel
26 {
27 private static final long serialVersionUID = -3218827566805476423L;
28
29 @Override
30 protected List<String> validateRange(Map<String, double[]> ranges) {
31 List<String> errors = new ArrayList<String>();
32 NumberFormat nf = NumberFormat.getDecimalFormat();
33
34 Iterator<String> iter = wqranges.keySet().iterator();
35
36 while (iter.hasNext()) {
37 List<String> tmpErrors = new ArrayList<String>();
38
39 String key = iter.next();
40 DoubleArrayPanel dap = wqranges.get(key);
41
42 if (!dap.validateForm()) {
43 errors.add(MSG.error_invalid_double_value());
44 return errors;
45 }
46
47 int idx = 0;
48
49 double[] values = dap.getInputValues();
50
51 double[] good = new double[values.length];
52
53 for (double value: values) {
54 if (value <= 0) {
55 String tmp = MSG.error_validate_positive();
56 tmp = tmp.replace("$1", nf.format(value));
57 errors.add(tmp);
58 } else {
59 good[idx++] = value;
60 }
61 }
62
63 double[] justGood = new double[idx];
64 for (int i = 0; i < justGood.length; i++) {
65 justGood[i] = good[i];
66 }
67
68 if (!errors.isEmpty()) {
69 dap.setValues(justGood);
70 }
71 }
72 return errors;
73 }
74 }
75 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org