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