Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1507:c21d14e48040
Improved validation and property handling.
flys-client/trunk@3645 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 11 Jan 2012 10:21:22 +0000 |
parents | 339f8aa641b5 |
children | 4f4d29404dba |
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 |
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 * |
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 boolean validate(FormItem item, Map errors) { |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 boolean valid = true; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
1507
c21d14e48040
Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1506
diff
changeset
|
26 String v = item.getValue().toString(); |
1504
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 NumberFormat f = NumberFormat.getDecimalFormat(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 try { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 if (v == null) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 throw new NumberFormatException("empty"); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 double value = f.parse(v); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 errors.remove(item.getFieldName()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 catch (NumberFormatException nfe) { |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 errors.put(item.getFieldName(), MSG.wrongFormat()); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 item.focusInItem(); |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 valid = false; |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 return valid; |
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 } |
02a9104c0451
Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 |