Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 4269:0c766c475805
Add Panel and Tree UI classes for dispayling the measurement station info
The new ui classes are using the new extracted base class InfoPanel and InfoTree
which are in common with the gauge info.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 26 Oct 2012 12:22:06 +0200 |
parents | 24e9b5eb83f8 |
children |
rev | line source |
---|---|
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.client.utils; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.Map; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
5 import com.google.gwt.core.client.GWT; |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 import com.google.gwt.i18n.client.NumberFormat; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 import com.smartgwt.client.widgets.form.fields.FormItem; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
10 import de.intevation.flys.client.client.FLYSConstants; |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
11 |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 /** |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 */ |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
15 public class DoubleValidator implements Validator { |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
16 |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
17 /** The interface that provides i18n messages. */ |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
18 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 |
2929
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
20 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
21 /** Statically determine doubility of String value. */ |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
22 public static boolean isDouble(Object obj) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
23 if (obj == null) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
24 return false; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
25 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
26 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
27 boolean valid = true; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
28 String v = obj.toString(); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
29 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
30 NumberFormat f = NumberFormat.getDecimalFormat(); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
31 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
32 try { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
33 if (v == null) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
34 throw new NumberFormatException("empty"); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
35 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
36 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
37 double value = f.parse(v); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
38 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
39 catch (NumberFormatException nfe) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
40 valid = false; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
41 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
42 return valid; |
2937
a30d77d86386
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
43 |
2929
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
44 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
45 |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
46 |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 /** |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
48 * @return true if items value can be converted to double, if false, |
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
49 * expect error message in \param errors map. |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 */ |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
51 public boolean validate(FormItem item, Map errors) { |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 boolean valid = true; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 |
1536
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
54 if(item.getValue() == null) { |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
55 return false; |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
56 } |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
57 String v = item.getValue().toString(); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 NumberFormat f = NumberFormat.getDecimalFormat(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 try { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 if (v == null) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 throw new NumberFormatException("empty"); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 double value = f.parse(v); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 errors.remove(item.getFieldName()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 catch (NumberFormatException nfe) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 errors.put(item.getFieldName(), MSG.wrongFormat()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 item.focusInItem(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 valid = false; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 return valid; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 } |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 |