annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AutoIntegerPanel.java @ 5861:172338b1407f

GWT client: Added copyright header.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:30:15 +0200
parents 5aa05a7a34b7
children ea9eef426962
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.client.ui;
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import com.google.gwt.core.client.GWT;
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import com.smartgwt.client.widgets.Canvas;
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import com.smartgwt.client.widgets.Label;
4131
360e22afb98b Cosmetics, warnings and minor TODOs.
Christian Lins <christian.lins@intevation.de>
parents: 874
diff changeset
15 import com.smartgwt.client.widgets.form.validator.CustomValidator;
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
16 import com.smartgwt.client.widgets.form.validator.Validator;
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import com.smartgwt.client.widgets.layout.VLayout;
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
19 import org.dive4elements.river.client.client.FLYSConstants;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
20 import org.dive4elements.river.client.shared.model.Data;
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
21 import org.dive4elements.river.client.shared.model.DataList;
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 /**
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 */
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 public class AutoIntegerPanel extends TextProvider {
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
4131
360e22afb98b Cosmetics, warnings and minor TODOs.
Christian Lins <christian.lins@intevation.de>
parents: 874
diff changeset
29 private static final long serialVersionUID = -6525461829035465820L;
360e22afb98b Cosmetics, warnings and minor TODOs.
Christian Lins <christian.lins@intevation.de>
parents: 874
diff changeset
30
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
31 public static final String FIELD_NAME = "integer_field";
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
32
874
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
33 public static final String FIELD_DEFAULT_VALUE = "auto";
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
34
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
35
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 protected String dataName;
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 @Override
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public Canvas create(DataList dataList) {
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 Data data = dataList.get(0);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 this.dataName = data.getLabel();
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 Canvas label = new Label(data.getDescription());
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
47 Canvas form = createForm(getTitle());
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 Canvas submit = getNextButton();
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 VLayout layout = new VLayout();
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 layout.setHeight(35);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 label.setHeight(35);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 layout.addMember(label);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 layout.addMember(form);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 layout.addMember(submit);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 layout.setMembersMargin(10);
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
794
40269a176cd2 Set default values in the BooleanPanel, TextProvider and AutoIntegerPanel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 791
diff changeset
59 initDefaultValues(dataList);
40269a176cd2 Set default values in the BooleanPanel, TextProvider and AutoIntegerPanel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 791
diff changeset
60
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 return layout;
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 }
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
874
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
65 @Override
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
66 protected void initDefaultValues(DataList dataList) {
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
67 super.initDefaultValues(dataList);
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
68
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
69 String def = getValueAsString();
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
70
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
71 if (def == null || def.length() == 0) {
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
72 form.setValue(getFieldName(), FIELD_DEFAULT_VALUE);
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
73 }
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
74 }
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
75
d900ab031dfe Set the default value of the AutoInteger panel to 'auto' if no other value is set.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 794
diff changeset
76
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
77 protected String getTitle() {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
78 return MSG.uesk_profile_distance();
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
79 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
80
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
81
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 @Override
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
83 protected String getDataName() {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
84 return dataName;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
85 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
86
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
87
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
88 @Override
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
89 protected String getValueAsString() {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
90 String v = (String) form.getValue(getFieldName());
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
91 return v.toLowerCase();
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
92 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
93
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
94
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
95 @Override
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
96 protected Validator getValidator() {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
97 Validator v = new AutoIntegerValidator();
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
98 v.setValidateOnChange(false);
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
99
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
100 return v;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
101 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
102
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
103
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
104 public class AutoIntegerValidator extends CustomValidator {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
105 @Override
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
106 protected boolean condition(Object value) {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
107 String v = (String) value;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
108
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
109 if (v == null || v.length() == 0) {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
110 return false;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
111 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
112
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
113 if (v.trim().equalsIgnoreCase("auto")) {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
114 return true;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
115 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
116
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
117 try {
4131
360e22afb98b Cosmetics, warnings and minor TODOs.
Christian Lins <christian.lins@intevation.de>
parents: 874
diff changeset
118 Integer.parseInt(v);
791
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
119 return true;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
120 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
121 catch (NumberFormatException nfe) {
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
122 return false;
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
123 }
9b1499a65aaa Finished the panel that allows integers and the string 'auto'.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 790
diff changeset
124 }
787
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 }
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 }
4e0b73b7113b Added new UI providers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org