9064
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.client.client.ui.uinfo; |
|
10 |
|
11 import java.util.ArrayList; |
|
12 import java.util.List; |
|
13 |
|
14 import org.dive4elements.river.client.client.ui.AbstractUIProvider; |
|
15 import org.dive4elements.river.client.shared.model.Data; |
|
16 import org.dive4elements.river.client.shared.model.DataItem; |
|
17 import org.dive4elements.river.client.shared.model.DataList; |
|
18 import org.dive4elements.river.client.shared.model.DefaultData; |
|
19 import org.dive4elements.river.client.shared.model.DefaultDataItem; |
|
20 |
|
21 import com.google.gwt.core.client.GWT; |
|
22 import com.smartgwt.client.data.Record; |
|
23 import com.smartgwt.client.types.ListGridFieldType; |
|
24 import com.smartgwt.client.widgets.Button; |
|
25 import com.smartgwt.client.widgets.Canvas; |
|
26 import com.smartgwt.client.widgets.Label; |
|
27 import com.smartgwt.client.widgets.events.ClickEvent; |
|
28 import com.smartgwt.client.widgets.events.ClickHandler; |
|
29 import com.smartgwt.client.widgets.form.DynamicForm; |
|
30 import com.smartgwt.client.widgets.form.fields.TextItem; |
|
31 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; |
|
32 import com.smartgwt.client.widgets.form.validator.IsStringValidator; |
|
33 import com.smartgwt.client.widgets.form.validator.Validator; |
|
34 import com.smartgwt.client.widgets.grid.ListGrid; |
|
35 import com.smartgwt.client.widgets.grid.ListGridField; |
|
36 import com.smartgwt.client.widgets.grid.ListGridRecord; |
|
37 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; |
|
38 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; |
|
39 import com.smartgwt.client.widgets.layout.HLayout; |
|
40 import com.smartgwt.client.widgets.layout.VLayout; |
|
41 |
|
42 public class VegetationzonesTable extends AbstractUIProvider { |
|
43 private static final long serialVersionUID = 1L; |
|
44 |
|
45 protected ListGrid elements; |
|
46 private TextItem vegzone; |
|
47 private TextItem start; |
|
48 private TextItem end; |
|
49 private ListGrid table; |
|
50 |
|
51 private TextItem createItem(final String identifier, final String title, final int width, final Validator... validator) { |
|
52 final TextItem item = new TextItem(identifier, title); |
|
53 item.setWidth(width); |
|
54 item.setWrapTitle(false); |
|
55 item.setValidators(validator);// eigentlich überflüssig, oder? |
|
56 return item; |
|
57 } |
|
58 |
|
59 public Canvas createWidget(final DataList data) { |
|
60 |
|
61 final VLayout root = new VLayout(); |
|
62 final HLayout input = new HLayout(); |
|
63 final VLayout tableLayout = new VLayout(); |
|
64 final HLayout fields = new HLayout(); |
|
65 final HLayout fields2 = new HLayout(); |
|
66 final VLayout spacer = new VLayout(); |
|
67 spacer.setHeight(10); |
|
68 |
|
69 final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific |
|
70 this.elements = new ListGrid(); |
|
71 |
|
72 final Label title = new Label(data.get(0).getDescription()); |
|
73 title.setHeight("35px"); // orig:25 |
|
74 |
|
75 this.vegzone = createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator()); |
|
76 this.start = createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator()); |
|
77 this.end = createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator()); |
|
78 |
|
79 final DynamicForm form1 = new DynamicForm(); |
|
80 final DynamicForm form2 = new DynamicForm(); |
|
81 form2.setNumCols(5); |
|
82 form1.setNumCols(7); |
|
83 form1.setFields(this.vegzone); |
|
84 form2.setFields(this.start, this.end); |
|
85 |
|
86 add.addClickHandler(new ClickHandler() { |
|
87 @Override |
|
88 public void onClick(final ClickEvent ce) { |
|
89 final String v1 = VegetationzonesTable.this.start.getValueAsString(); |
|
90 final String v2 = VegetationzonesTable.this.end.getValueAsString(); |
|
91 final String v3 = VegetationzonesTable.this.vegzone.getValueAsString(); |
|
92 if (v1 == null || v2 == null || v3 == null) { |
|
93 return; |
|
94 } |
|
95 |
|
96 final ListGridRecord r = new ListGridRecord(); |
|
97 r.setAttribute("vegzone", v3); |
|
98 r.setAttribute("from", v1); |
|
99 r.setAttribute("to", v2); |
|
100 VegetationzonesTable.this.elements.addData(r); |
|
101 } |
|
102 }); |
|
103 |
|
104 final Label sel = new Label(this.MSG.select()); |
|
105 sel.setHeight(25); |
|
106 this.elements.setWidth(450); // 185 |
|
107 this.elements.setHeight(500); // 120 |
|
108 this.elements.setShowHeaderContextMenu(false); |
|
109 this.elements.setCanReorderFields(false); |
|
110 this.elements.setCanSort(false); |
|
111 this.elements.setCanEdit(false); |
|
112 final ListGridField vegzone = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); |
|
113 final ListGridField from = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); |
|
114 final ListGridField to = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); |
|
115 vegzone.setWidth(285); |
|
116 from.setWidth(70); |
|
117 to.setWidth(70); |
|
118 |
|
119 final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") { |
|
120 { |
|
121 setType(ListGridFieldType.ICON); |
|
122 setIcon(GWT.getHostPageBaseURL() + VegetationzonesTable.this.MSG.removeFeature()); |
|
123 setCanEdit(false); |
|
124 setCanFilter(false); |
|
125 setCanSort(false); |
|
126 setCanGroupBy(false); |
|
127 setCanFreeze(false); |
|
128 setWidth(25); |
|
129 } |
|
130 }; |
|
131 |
|
132 this.elements.addRecordClickHandler(new RecordClickHandler() { |
|
133 @Override |
|
134 public void onRecordClick(final RecordClickEvent event) { |
|
135 // Just handle remove-clicks |
|
136 if (!event.getField().getName().equals(removeField.getName())) { |
|
137 return; |
|
138 } |
|
139 event.getViewer().removeData(event.getRecord()); |
|
140 } |
|
141 }); |
|
142 |
|
143 this.elements.setFields(vegzone, from, to, removeField); |
|
144 |
|
145 fields.addMember(form1); |
|
146 fields2.addMember(form2); |
|
147 // fields2.addMember(add); |
|
148 |
|
149 tableLayout.addMember(this.elements); |
|
150 root.addMember(title); |
|
151 root.addMember(input); |
|
152 root.addMember(tableLayout); |
|
153 root.addMember(spacer); |
|
154 root.addMember(fields); |
|
155 root.addMember(fields2); |
|
156 root.addMember(spacer); |
|
157 root.addMember(add); |
|
158 root.addMember(spacer); |
|
159 root.addMember(spacer); |
|
160 |
|
161 return root; |
|
162 } |
|
163 |
|
164 @Override |
|
165 public Canvas createOld(final DataList dataList) { |
|
166 final HLayout layout = new HLayout(); |
|
167 layout.setWidth("400px"); |
|
168 final VLayout vLayout = new VLayout(); |
|
169 vLayout.setWidth(130); |
|
170 final Label label = new Label(dataList.getLabel()); |
|
171 label.setWidth("200px"); |
|
172 label.setHeight(25); |
|
173 |
|
174 final List<Data> items = dataList.getAll(); |
|
175 final Data str = getData(items, "vegzones"); |
|
176 final DataItem[] strItems = str.getItems(); |
|
177 |
|
178 final String[] entries = strItems[0].getLabel().split(";"); |
|
179 for (final String entry : entries) { |
|
180 final String[] vals = entry.split(","); |
|
181 final Label dateLabel = new Label(vals[0] + " - " + vals[1]); |
|
182 dateLabel.setHeight(20); |
|
183 vLayout.addMember(dateLabel); |
|
184 } |
|
185 final Canvas back = getBackButton(dataList.getState()); |
|
186 layout.addMember(label); |
|
187 layout.addMember(vLayout); |
|
188 layout.addMember(back); |
|
189 |
|
190 return layout; |
|
191 } |
|
192 |
|
193 @Override |
|
194 public Canvas create(final DataList data) { |
|
195 final VLayout layout = new VLayout(); |
|
196 final Canvas helper = createHelper(); |
|
197 this.helperContainer.addMember(helper); |
|
198 |
|
199 final Canvas submit = getNextButton(); |
|
200 final Canvas widget = createWidget(data); |
|
201 |
|
202 layout.addMember(widget); |
|
203 layout.addMember(submit); // TODO: SUBMIT |
|
204 |
|
205 // fetchSedimentLoadData(); //TODO: feed from database... |
|
206 |
|
207 return layout; |
|
208 } |
|
209 |
|
210 private Canvas createHelper() { |
|
211 this.table = new ListGrid(); |
|
212 this.table.setShowHeaderContextMenu(false); |
|
213 this.table.setWidth100(); |
|
214 this.table.setShowRecordComponents(true); |
|
215 this.table.setShowRecordComponentsByCell(true); |
|
216 this.table.setHeight100(); |
|
217 this.table.setEmptyMessage(this.MSG.empty_table()); |
|
218 this.table.setCanReorderFields(false); |
|
219 |
|
220 /* Input support pins */ |
|
221 // final String baseUrl = GWT.getHostPageBaseURL(); |
|
222 // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); |
|
223 // pinFrom.setWidth(300); |
|
224 // pinFrom.setType(ListGridFieldType.ICON); |
|
225 // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); |
|
226 // |
|
227 // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); |
|
228 // pinTo.setType(ListGridFieldType.ICON); |
|
229 // pinTo.setWidth(300); |
|
230 // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); |
|
231 // |
|
232 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
233 // @Override |
|
234 // public void onRecordClick(final RecordClickEvent e) { |
|
235 // final Record r = e.getRecord(); |
|
236 // VegetationzonesTable.this.vegzone.setValue(r.getAttribute("date")); // date?? |
|
237 // } |
|
238 // }); |
|
239 // |
|
240 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
241 // @Override |
|
242 // public void onRecordClick(final RecordClickEvent e) { |
|
243 // final Record r = e.getRecord(); |
|
244 // VegetationzonesTable.this.start.setValue(r.getAttribute("date")); |
|
245 // } |
|
246 // }); |
|
247 // |
|
248 // pinTo.addRecordClickHandler(new RecordClickHandler() { |
|
249 // @Override |
|
250 // public void onRecordClick(final RecordClickEvent e) { |
|
251 // final Record r = e.getRecord(); |
|
252 // VegetationzonesTable.this.end.setValue(r.getAttribute("date")); |
|
253 // } |
|
254 // }); |
|
255 // |
|
256 // final ListGridField date = new ListGridField("date", this.MSG.year()); |
|
257 // date.setType(ListGridFieldType.TEXT); |
|
258 // date.setWidth(100); |
|
259 // |
|
260 // final ListGridField descr = new ListGridField("description", this.MSG.description()); |
|
261 // descr.setType(ListGridFieldType.TEXT); |
|
262 // descr.setWidth("*"); |
|
263 // |
|
264 // this.table.setFields(pinFrom, pinTo, date, descr); |
|
265 return this.table; |
|
266 } |
|
267 |
|
268 @Override |
|
269 protected Data[] getData() { |
|
270 final List<Data> data = new ArrayList<Data>(); |
|
271 |
|
272 final ListGridRecord[] lgr = this.elements.getRecords(); |
|
273 if (lgr.length == 0) { |
|
274 return new Data[0]; |
|
275 } |
|
276 String d = ""; |
|
277 for (final ListGridRecord element : lgr) { |
|
278 final Record r = element; |
|
279 d += r.getAttribute("vegzone") + "," + r.getAttribute("from") + "," + r.getAttribute("to"); |
|
280 d += ";"; |
|
281 } |
|
282 |
|
283 final DataItem item = new DefaultDataItem("vegzones", null, d); // DATA-key |
|
284 data.add(new DefaultData("vegzones", null, null, new DataItem[] { item })); |
|
285 return data.toArray(new Data[data.size()]); |
|
286 } |
|
287 |
|
288 } |