annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/ValidationBehaviourSingleMultiInputItem.java @ 9559:ba0561906f81

Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
author gernotbelger
date Wed, 24 Oct 2018 18:40:38 +0200
parents 787fc085459b
children
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
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
25 protected String errorForItemMsg = null;
9270
7337034eb5d5 multiple whitespace input fix
gernotbelger
parents: 9267
diff changeset
26 protected final FLYSConstants MSG;
9559
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
27 private final String appendStringForCreateOld;
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
28
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
29 public ValidationBehaviourSingleMultiInputItem(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
30 this.validInputs = validInputs;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
31 this.errorForItemMsg = errorForItemMsg;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
32 this.MSG = MSG; // etwas unglücklich...
9559
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
33 this.appendStringForCreateOld = "";
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
34 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
35
9559
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
36 public ValidationBehaviourSingleMultiInputItem(final String appendStringForCreateOld, final FLYSConstants MSG) {
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
37 this.appendStringForCreateOld = appendStringForCreateOld;
9270
7337034eb5d5 multiple whitespace input fix
gernotbelger
parents: 9267
diff changeset
38 this.MSG = MSG;
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
39 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
40
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
41 protected final List<String> validateSingleInput(final String sValue) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
42 final List<String> errors = new ArrayList<String>();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
43 // String filtered = "";
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
44 // int goodValues = 0;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
45 errors.addAll(validateNumber(sValue));
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
46 boolean isGood = false;
9481
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
47 for (final String validYear : this.getValidInputs()) {
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
48 /* No list contains for strings? */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
49 if (sValue.equals(validYear)) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
50 isGood = true;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
51 break;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
52 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
53 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
54 if (!isGood) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
55 String tmp = this.errorForItemMsg;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
56 tmp = tmp.replace("$1", sValue);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
57 errors.add(tmp);
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 return errors;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
61 }
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 protected final List<String> validateNumber(final String sValue) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
64 final List<String> errors = new ArrayList<String>();
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 try {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
67 Integer.parseInt(sValue);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
68 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
69 catch (final NumberFormatException e) {
9267
c7e5285d434f bundu bezugswst work
gernotbelger
parents: 9256
diff changeset
70
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
71 errors.add(this.MSG.wrongFormat() + ": " + sValue);
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 return errors;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
75 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
76
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
77 @Override
9481
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
78 public final void setErrorForItemMsg(final String errorForItemMsg) {
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
79 this.errorForItemMsg = errorForItemMsg;
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
80
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
81 }
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
82
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
83 @Override
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
84 public final void setValidInputs(final List<String> validInputs) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
85 this.validInputs = validInputs;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
86
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
87 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
88
9481
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
89 protected final List<String> getValidInputs() {
787fc085459b TSV introduced; uinfo.inundationWMS-Config
gernotbelger
parents: 9270
diff changeset
90 return this.validInputs;
9256
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
9559
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
93 @Override
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
94 public String appendStringForCreateOld() {
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
95 return this.appendStringForCreateOld;
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
96 }
ba0561906f81 Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents: 9481
diff changeset
97
9256
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
98 }

http://dive4elements.wald.intevation.org