Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/ValidationBehaviourSingleMultiInputItem.java @ 9481:787fc085459b
TSV introduced; uinfo.inundationWMS-Config
author | gernotbelger |
---|---|
date | Wed, 12 Sep 2018 10:55:09 +0200 |
parents | 7337034eb5d5 |
children | ba0561906f81 |
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; |
9481 | 25 protected String errorForItemMsg = null; |
9270 | 26 protected final FLYSConstants MSG; |
9256
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 |
9270 | 34 public ValidationBehaviourSingleMultiInputItem(final FLYSConstants MSG) { |
35 this.MSG = MSG; | |
9256
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; |
9481 | 44 for (final String validYear : this.getValidInputs()) { |
9256
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 } |
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 return errors; |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
58 } |
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 protected final List<String> validateNumber(final String sValue) { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
61 final List<String> errors = new ArrayList<String>(); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
62 |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
63 try { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
64 Integer.parseInt(sValue); |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
65 } |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
66 catch (final NumberFormatException e) { |
9267 | 67 |
9256
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 |
9481 | 75 public final void setErrorForItemMsg(final String errorForItemMsg) { |
76 this.errorForItemMsg = errorForItemMsg; | |
77 | |
78 } | |
79 | |
80 @Override | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
81 public final void setValidInputs(final List<String> validInputs) { |
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
82 this.validInputs = validInputs; |
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 |
9481 | 86 protected final List<String> getValidInputs() { |
87 return this.validInputs; | |
9256
6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff
changeset
|
88 } |
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 } |