comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/AutoIntegerPanel.java @ 791:9b1499a65aaa

Finished the panel that allows integers and the string 'auto'. flys-client/trunk@2298 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 07 Jul 2011 10:33:29 +0000
parents 3fa8583434b2
children 40269a176cd2
comparison
equal deleted inserted replaced
790:3fa8583434b2 791:9b1499a65aaa
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4 4
5 import com.smartgwt.client.widgets.Canvas; 5 import com.smartgwt.client.widgets.Canvas;
6 import com.smartgwt.client.widgets.Label; 6 import com.smartgwt.client.widgets.Label;
7 import com.smartgwt.client.widgets.form.validator.Validator;
8 import com.smartgwt.client.widgets.form.validator.CustomValidator;
7 import com.smartgwt.client.widgets.layout.VLayout; 9 import com.smartgwt.client.widgets.layout.VLayout;
8 10
9 import de.intevation.flys.client.shared.model.Data; 11 import de.intevation.flys.client.shared.model.Data;
10 import de.intevation.flys.client.shared.model.DataItem;
11 import de.intevation.flys.client.shared.model.DefaultData;
12 import de.intevation.flys.client.shared.model.DefaultDataItem;
13 import de.intevation.flys.client.shared.model.DataList; 12 import de.intevation.flys.client.shared.model.DataList;
14 13
15 import de.intevation.flys.client.client.FLYSConstants; 14 import de.intevation.flys.client.client.FLYSConstants;
16 15
17 16
18 /** 17 /**
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 18 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
20 */ 19 */
21 public class AutoIntegerPanel extends TextProvider { 20 public class AutoIntegerPanel extends TextProvider {
21
22 public static final String FIELD_NAME = "integer_field";
23
22 24
23 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); 25 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class);
24 26
25 protected String dataName; 27 protected String dataName;
26 28
29 public Canvas create(DataList dataList) { 31 public Canvas create(DataList dataList) {
30 Data data = dataList.get(0); 32 Data data = dataList.get(0);
31 this.dataName = data.getLabel(); 33 this.dataName = data.getLabel();
32 34
33 Canvas label = new Label(data.getDescription()); 35 Canvas label = new Label(data.getDescription());
34 Canvas form = createForm(MSG.uesk_profile_distance()); 36 Canvas form = createForm(getTitle());
35 Canvas submit = getNextButton(); 37 Canvas submit = getNextButton();
36 38
37 VLayout layout = new VLayout(); 39 VLayout layout = new VLayout();
38 layout.setHeight(35); 40 layout.setHeight(35);
39 label.setHeight(35); 41 label.setHeight(35);
45 47
46 return layout; 48 return layout;
47 } 49 }
48 50
49 51
52 protected String getTitle() {
53 return MSG.uesk_profile_distance();
54 }
55
56
50 @Override 57 @Override
51 protected Data[] getData() { 58 protected String getDataName() {
52 GWT.log("+++ RETURN DATA FOR STATE: " + dataName + " +++"); 59 return dataName;
53 String value = "TODO:FIND VALUE"; 60 }
54 DataItem item = new DefaultDataItem(dataName, dataName, value); 61
55 return new Data[] { new DefaultData( 62
56 dataName, null, null, new DataItem[] { item }) }; 63 @Override
64 protected String getValueAsString() {
65 String v = (String) form.getValue(getFieldName());
66 return v.toLowerCase();
67 }
68
69
70 @Override
71 protected Validator getValidator() {
72 Validator v = new AutoIntegerValidator();
73 v.setValidateOnChange(false);
74
75 return v;
76 }
77
78
79 public class AutoIntegerValidator extends CustomValidator {
80 @Override
81 protected boolean condition(Object value) {
82 String v = (String) value;
83
84 if (v == null || v.length() == 0) {
85 return false;
86 }
87
88 if (v.trim().equalsIgnoreCase("auto")) {
89 return true;
90 }
91
92 try {
93 Integer anInt = Integer.parseInt(v);
94
95 return true;
96 }
97 catch (NumberFormatException nfe) {
98 return false;
99 }
100 }
57 } 101 }
58 } 102 }
59 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org