annotate flys-client/src/main/java/org/dive4elements/river/client/client/utils/IntegerValidator.java @ 5835:821a02bbfb4e

Fixed internal java dependencies
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 13:12:15 +0200
parents f507086aa94b
children
rev   line source
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
1 package org.dive4elements.river.client.client.utils;
1504
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: 1504
diff changeset
5 import com.google.gwt.core.client.GWT;
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
6
1504
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
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 import org.dive4elements.river.client.client.FLYSConstants;
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
10
1504
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 * @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
13 */
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
14 public class IntegerValidator implements Validator {
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
15
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
16 /** The interface that provides i18n messages. */
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
17 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
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 */
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
22 public boolean validate(FormItem item, Map errors) {
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 boolean valid = true;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
25 String v = item.getValue().toString();
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 try {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 if (v == null) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 throw new NumberFormatException("empty");
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
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 int value = Integer.parseInt(v);
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 errors.remove(item.getFieldName());
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 }
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 catch (NumberFormatException nfe) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 errors.put(item.getFieldName(), MSG.wrongFormat());
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 item.focusInItem();
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 valid = false;
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 return valid;
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 }

http://dive4elements.wald.intevation.org