comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/ValidationBehaviourSingleMultiInputItem.java @ 9256:6c24c857ccf9

fixation refactoring and inputItem behaviour to interfaces
author gernotbelger
date Fri, 13 Jul 2018 12:04:21 +0200
parents
children c7e5285d434f
comparison
equal deleted inserted replaced
9255:9be51f776798 9256:6c24c857ccf9
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.client.client.ui.uinfo;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.dive4elements.river.client.client.FLYSConstants;
16 import org.dive4elements.river.client.client.ui.AbstractSingleItemPanel.IMultiSingleBehaviour;
17
18 /**
19 * @author Domenico Nardi Tironi
20 *
21 */
22 public abstract class ValidationBehaviourSingleMultiInputItem implements IMultiSingleBehaviour {
23
24 private List<String> validInputs = null;
25 private String errorForItemMsg = null;
26 protected FLYSConstants MSG = null;
27
28 public ValidationBehaviourSingleMultiInputItem(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) {
29 this.validInputs = validInputs;
30 this.errorForItemMsg = errorForItemMsg;
31 this.MSG = MSG; // etwas unglücklich...
32 }
33
34 public ValidationBehaviourSingleMultiInputItem() {
35
36 }
37
38 protected final List<String> validateSingleInput(final String sValue) {
39 final List<String> errors = new ArrayList<String>();
40 // String filtered = "";
41 // int goodValues = 0;
42 errors.addAll(validateNumber(sValue));
43 boolean isGood = false;
44 for (final String validYear : this.validInputs) {
45 /* No list contains for strings? */
46 if (sValue.equals(validYear)) {
47 isGood = true;
48 break;
49 }
50 }
51 if (!isGood) {
52 String tmp = this.errorForItemMsg;
53 tmp = tmp.replace("$1", sValue);
54 errors.add(tmp);
55 // continue;
56 }
57
58 return errors;
59 }
60
61 protected final List<String> validateNumber(final String sValue) {
62 final List<String> errors = new ArrayList<String>();
63
64 try {
65 Integer.parseInt(sValue);
66 }
67 catch (final NumberFormatException e) {
68 errors.add(this.MSG.wrongFormat() + ": " + sValue);
69
70 }
71 return errors;
72 }
73
74 @Override
75 public final void setValidInputs(final List<String> validInputs) {
76 this.validInputs = validInputs;
77
78 }
79
80 @Override
81 public final void setErrorForItemMsg(final String errorForItemMsg) {
82 this.errorForItemMsg = errorForItemMsg;
83
84 }
85
86 @Override
87 public void setMSG(final FLYSConstants msg) {
88 this.MSG = this.MSG;
89
90 }
91
92 }

http://dive4elements.wald.intevation.org