annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/Limit5SalixBehaviour.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.List;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
13
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
14 import org.dive4elements.river.client.client.FLYSConstants;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
15
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
16 import com.smartgwt.client.util.SC;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
17 import com.smartgwt.client.widgets.form.fields.TextItem;
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 /**
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
20 * @author Domenico Nardi Tironi
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 */
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
23 public class Limit5SalixBehaviour extends ValidationBehaviourSingleMultiInputItem {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
24
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
25 public Limit5SalixBehaviour(final List<String> validInputs, final String errorForItemMsg, final FLYSConstants MSG) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
26 super(validInputs, errorForItemMsg, MSG);
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
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
29 public Limit5SalixBehaviour() {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
30 super();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
31 }
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 @Override
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
34 public void appendValue(final TextItem inputItem, final String value) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
35 // APPEND = ADD to existing -> MULTI YEAR
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
36 final String oldValues = inputItem.getValueAsString();
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
37 if (oldValues != null && !oldValues.isEmpty()) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
38 final String[] oldVals = oldValues.split(" ");
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
39 if (oldVals.length < 5)
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
40 inputItem.setValue(oldValues.trim() + " " + value);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
41 else {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
42 SC.warn(this.MSG.error_limit_exceeded_salix());
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
43 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
44 }
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
45
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
46 else
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
47 inputItem.setValue(value);
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
48
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 @Override
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
52 public List<String> validate(final List<String> errors, final String inputValueString) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
53 if (inputValueString != null) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
54 final String[] values = inputValueString.trim().split(" ");
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
55 if (values.length > 5) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
56 errors.add(this.MSG.error_limit_exceeded_salix());
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 for (int i = 0; i < values.length; i++) {
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
59 if (i < 5)
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
60 errors.addAll(this.validateNumber(values[i]));
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 return errors;
6c24c857ccf9 fixation refactoring and inputItem behaviour to interfaces
gernotbelger
parents:
diff changeset
64 }
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 }

http://dive4elements.wald.intevation.org