annotate flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java @ 1504:02a9104c0451

Implemented the validators more object oriented. flys-client/trunk@3634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 09 Jan 2012 17:29:56 +0000
parents
children 339f8aa641b5
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
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import com.google.gwt.i18n.client.NumberFormat;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import com.smartgwt.client.widgets.form.fields.FormItem;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 /**
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 * @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
11 */
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 public class DoubleValidator extends Validator {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 /**
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 */
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 @Override
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 protected boolean validate(FormItem item, Map errors) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 boolean valid = true;
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 String v = (String) item.getValue();
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 NumberFormat f = NumberFormat.getDecimalFormat();
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 try {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 if (v == null) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 throw new NumberFormatException("empty");
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 }
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 double value = f.parse(v);
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 errors.remove(item.getFieldName());
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 catch (NumberFormatException nfe) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 errors.put(item.getFieldName(), MSG.wrongFormat());
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 item.focusInItem();
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 valid = false;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 }
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 return valid;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 }
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

http://dive4elements.wald.intevation.org