Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/TextProvider.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/TextProvider.java@03de5c424f95 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.data.DataSource; | |
6 import com.smartgwt.client.data.DataSourceField; | |
7 import com.smartgwt.client.types.Alignment; | |
8 import com.smartgwt.client.types.FieldType; | |
9 import com.smartgwt.client.types.TitleOrientation; | |
10 import com.smartgwt.client.widgets.Canvas; | |
11 import com.smartgwt.client.widgets.Label; | |
12 import com.smartgwt.client.widgets.form.DynamicForm; | |
13 import com.smartgwt.client.widgets.form.events.ItemChangedEvent; | |
14 import com.smartgwt.client.widgets.form.events.ItemChangedHandler; | |
15 import com.smartgwt.client.widgets.form.validator.Validator; | |
16 import com.smartgwt.client.widgets.layout.HLayout; | |
17 | |
18 import de.intevation.flys.client.client.FLYSConstants; | |
19 import de.intevation.flys.client.shared.model.Data; | |
20 import de.intevation.flys.client.shared.model.DataItem; | |
21 import de.intevation.flys.client.shared.model.DataList; | |
22 import de.intevation.flys.client.shared.model.DefaultData; | |
23 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
24 | |
25 import java.util.ArrayList; | |
26 import java.util.List; | |
27 | |
28 | |
29 /** | |
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
31 */ | |
32 public class TextProvider | |
33 extends AbstractUIProvider | |
34 implements ItemChangedHandler | |
35 { | |
36 private static final long serialVersionUID = -6868303464989138497L; | |
37 | |
38 public static final String FIELD_NAME = "textprovider_inputfield"; | |
39 public static final int FORM_WIDTH = 400; | |
40 public static final int TITLE_WIDTH = 75; | |
41 | |
42 | |
43 protected static FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
44 | |
45 protected DynamicForm form; | |
46 | |
47 | |
48 @Override | |
49 public Canvas create(DataList dataList) { | |
50 Canvas form = createForm(); | |
51 | |
52 initDefaultValues(dataList); | |
53 | |
54 return form; | |
55 } | |
56 | |
57 | |
58 protected Canvas createForm() { | |
59 return createForm(null); | |
60 } | |
61 | |
62 | |
63 protected Canvas createForm(String title) { | |
64 form = new DynamicForm(); | |
65 form.addItemChangedHandler(this); | |
66 form.setTitlePrefix(""); | |
67 form.setTitleSuffix(": "); | |
68 form.setTitleAlign(Alignment.LEFT); | |
69 form.setTitleOrientation(TitleOrientation.LEFT); | |
70 form.setTitleWidth(getTitleWidth()); | |
71 form.setWidth(getFormWidth()); | |
72 | |
73 DataSourceField item = createField(); | |
74 item.setTitle(title); | |
75 | |
76 Validator validator = getValidator(); | |
77 if (validator != null) { | |
78 item.setValidators(validator); | |
79 } | |
80 | |
81 DataSource source = new DataSource(); | |
82 source.setFields(item); | |
83 | |
84 form.setDataSource(source); | |
85 | |
86 return form; | |
87 } | |
88 | |
89 | |
90 protected void initDefaultValues(DataList dataList) { | |
91 Data data = dataList.get(0); | |
92 DataItem item = data.getDefault(); | |
93 | |
94 String value = item.getStringValue(); | |
95 | |
96 form.setValue(getFieldName(), value); | |
97 } | |
98 | |
99 | |
100 protected DataSourceField createField() { | |
101 return new DataSourceField(getFieldName(), getFieldType()); | |
102 } | |
103 | |
104 | |
105 /** | |
106 * Get field name. | |
107 * @return fields name (developer-centric). | |
108 */ | |
109 protected String getFieldName() { | |
110 return FIELD_NAME; | |
111 } | |
112 | |
113 | |
114 /** | |
115 * Get field type. | |
116 * @return fields type. | |
117 */ | |
118 protected FieldType getFieldType() { | |
119 return FieldType.TEXT; | |
120 } | |
121 | |
122 | |
123 protected Validator getValidator() { | |
124 return null; | |
125 } | |
126 | |
127 | |
128 protected int getFormWidth() { | |
129 return FORM_WIDTH; | |
130 } | |
131 | |
132 | |
133 protected int getTitleWidth() { | |
134 return TITLE_WIDTH; | |
135 } | |
136 | |
137 | |
138 /** @return null. */ | |
139 protected String getDataName() { | |
140 return null; | |
141 } | |
142 | |
143 | |
144 protected String getValueAsString() { | |
145 return (String) form.getValue(getFieldName()); | |
146 } | |
147 | |
148 | |
149 @Override | |
150 public Canvas createOld(DataList dataList) { | |
151 Data data = dataList.get(0); | |
152 DataItem[] items = data.getItems(); | |
153 | |
154 HLayout layout = new HLayout(); | |
155 Label label = new Label(dataList.getLabel()); | |
156 Label value = new Label(items[0].getLabel()); | |
157 | |
158 layout.setHeight(35); | |
159 layout.setWidth(400); | |
160 label.setWidth(200); | |
161 | |
162 layout.addMember(label); | |
163 layout.addMember(value); | |
164 layout.addMember(getBackButton(dataList.getState())); | |
165 | |
166 return layout; | |
167 } | |
168 | |
169 | |
170 @Override | |
171 public List<String> validate() { | |
172 List<String> errors = new ArrayList<String>(); | |
173 | |
174 if (!form.validate()) { | |
175 errors.add(MSG.wrongFormat()); | |
176 } | |
177 | |
178 return errors; | |
179 } | |
180 | |
181 | |
182 @Override | |
183 protected Data[] getData() { | |
184 String value = getValueAsString(); | |
185 String name = getDataName(); | |
186 | |
187 DataItem item = new DefaultDataItem(name, name, value); | |
188 return new Data[] { new DefaultData( | |
189 name, null, null, new DataItem[] { item }) }; | |
190 } | |
191 | |
192 | |
193 @Override | |
194 public void onItemChanged(ItemChangedEvent event) { | |
195 form.validate(); | |
196 } | |
197 } | |
198 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |