Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 2937:a30d77d86386
Removed trailing whitespace
flys-client/trunk@4891 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 07 Jul 2012 09:37:23 +0000 |
parents | 0ef4753e5515 |
children | 24e9b5eb83f8 |
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 |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 /** |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 * |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 */ |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
49 public boolean validate(FormItem item, Map errors) { |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 boolean valid = true; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 |
1536
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
52 if(item.getValue() == null) { |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
53 return false; |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
54 } |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
55 String v = item.getValue().toString(); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 NumberFormat f = NumberFormat.getDecimalFormat(); |
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 try { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 if (v == null) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 throw new NumberFormatException("empty"); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 double value = f.parse(v); |
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 errors.remove(item.getFieldName()); |
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 catch (NumberFormatException nfe) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 errors.put(item.getFieldName(), MSG.wrongFormat()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 item.focusInItem(); |
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 valid = false; |
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 return valid; |
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 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 |