Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/utils/DoubleValidator.java @ 9227:84397da33d17
Allow to control specific behaviour in TwinDatacagePanel
Implemented client logic of 'intelligent datacage filtering' for SINFO
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 18:28:08 +0200 |
parents | ea9eef426962 |
children |
rev | line source |
---|---|
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
9 package org.dive4elements.river.client.client.utils; |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 import java.util.Map; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
13 import com.google.gwt.core.client.GWT; |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 import com.google.gwt.i18n.client.NumberFormat; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 import com.smartgwt.client.widgets.form.fields.FormItem; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
18 import org.dive4elements.river.client.client.FLYSConstants; |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
19 |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 /** |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 * @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
|
22 */ |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
23 public class DoubleValidator implements Validator { |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
24 |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
25 /** The interface that provides i18n messages. */ |
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
26 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 |
2929
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
28 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
29 /** Statically determine doubility of String value. */ |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
30 public static boolean isDouble(Object obj) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
31 if (obj == null) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
32 return false; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
33 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
34 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
35 boolean valid = true; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
36 String v = obj.toString(); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
37 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
38 NumberFormat f = NumberFormat.getDecimalFormat(); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
39 |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
40 try { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
41 if (v == null) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
42 throw new NumberFormatException("empty"); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
43 } |
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 double value = f.parse(v); |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
46 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
47 catch (NumberFormatException nfe) { |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
48 valid = false; |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
49 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
50 return valid; |
2937
a30d77d86386
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
51 |
2929
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
52 } |
0ef4753e5515
Improved manual wsp input validation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1536
diff
changeset
|
53 |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
54 |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 /** |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
56 * @return true if items value can be converted to double, if false, |
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
57 * expect error message in \param errors map. |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 */ |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
59 public boolean validate(FormItem item, Map errors) { |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 boolean valid = true; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 |
1536
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
62 if(item.getValue() == null) { |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
63 return false; |
4f4d29404dba
Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1507
diff
changeset
|
64 } |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
65 String v = item.getValue().toString(); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 NumberFormat f = NumberFormat.getDecimalFormat(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 try { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 if (v == null) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 throw new NumberFormatException("empty"); |
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 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 double value = f.parse(v); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
75 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
76 errors.remove(item.getFieldName()); |
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 catch (NumberFormatException nfe) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 errors.put(item.getFieldName(), MSG.wrongFormat()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
81 item.focusInItem(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 valid = false; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 return valid; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 } |
3351
24e9b5eb83f8
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2937
diff
changeset
|
88 // 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
|
89 |