annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1536:4f4d29404dba

Filter the helper input tables using the range filter. flys-client/trunk@3754 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 24 Jan 2012 08:46:33 +0000
parents c21d14e48040
children 0ef4753e5515
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
1536
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1507
diff changeset
26 if(item.getValue() == null) {
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1507
diff changeset
27 return false;
4f4d29404dba Filter the helper input tables using the range filter.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1507
diff changeset
28 }
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1506
diff changeset
29 String v = item.getValue().toString();
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 NumberFormat f = NumberFormat.getDecimalFormat();
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 try {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 if (v == null) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 throw new NumberFormatException("empty");
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
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 double value = f.parse(v);
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 errors.remove(item.getFieldName());
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 catch (NumberFormatException nfe) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 errors.put(item.getFieldName(), MSG.wrongFormat());
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 item.focusInItem();
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 valid = false;
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 return valid;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 }
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 }
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52

http://dive4elements.wald.intevation.org