annotate gwt-client/src/main/java/org/dive4elements/river/client/client/utils/IntegerValidator.java @ 5861:172338b1407f

GWT client: Added copyright header.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:30:15 +0200
parents 5aa05a7a34b7
children ea9eef426962
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 *
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
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
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
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: 1504
diff changeset
13 import com.google.gwt.core.client.GWT;
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
14
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import com.smartgwt.client.widgets.form.fields.FormItem;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
17 import org.dive4elements.river.client.client.FLYSConstants;
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
18
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 * @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
21 */
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
22 public class IntegerValidator implements Validator {
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
23
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
24 /** The interface that provides i18n messages. */
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
25 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
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 /**
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 */
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
30 public boolean validate(FormItem item, Map errors) {
1504
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 boolean valid = true;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
1507
c21d14e48040 Improved validation and property handling.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1504
diff changeset
33 String v = item.getValue().toString();
1504
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 try {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 if (v == null) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 throw new NumberFormatException("empty");
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
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 int value = Integer.parseInt(v);
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 errors.remove(item.getFieldName());
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 catch (NumberFormatException nfe) {
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 errors.put(item.getFieldName(), MSG.wrongFormat());
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 item.focusInItem();
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 valid = false;
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 return valid;
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 }
02a9104c0451 Implemented the validators more object oriented.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 }

http://dive4elements.wald.intevation.org