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