9066
|
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.client.ui.PanelHelper; |
|
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.smartgwt.client.data.Record; |
|
23 import com.smartgwt.client.widgets.Canvas; |
|
24 import com.smartgwt.client.widgets.Label; |
|
25 import com.smartgwt.client.widgets.form.fields.TextItem; |
|
26 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; |
|
27 import com.smartgwt.client.widgets.form.validator.IsStringValidator; |
|
28 import com.smartgwt.client.widgets.grid.ListGrid; |
|
29 import com.smartgwt.client.widgets.grid.ListGridField; |
|
30 import com.smartgwt.client.widgets.grid.ListGridRecord; |
|
31 import com.smartgwt.client.widgets.layout.HLayout; |
|
32 import com.smartgwt.client.widgets.layout.VLayout; |
|
33 |
|
34 public class VegetationzonesTablePanel extends AbstractUIProvider { |
|
35 private static final long serialVersionUID = 1L; |
|
36 |
|
37 protected ListGrid elements; |
|
38 private TextItem vegzone; |
|
39 private TextItem start; |
|
40 private TextItem end; |
|
41 private ListGrid table; |
|
42 |
|
43 private static final String datakey = "vegzones"; |
|
44 |
|
45 public Canvas createWidget(final DataList data) { |
|
46 |
|
47 final VLayout root = new VLayout(); |
|
48 final HLayout input = new HLayout(); |
|
49 final VLayout tableLayout = new VLayout(); |
|
50 |
|
51 this.elements = new ListGrid(); |
|
52 |
|
53 final Label title = new Label(data.get(0).getDescription()); |
|
54 title.setHeight("35px"); // orig:25 |
|
55 |
|
56 this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator()); |
|
57 this.start = PanelHelper.createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator()); |
|
58 this.end = PanelHelper.createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator()); |
|
59 |
|
60 final Label sel = new Label(this.MSG.select()); |
|
61 sel.setHeight(25); |
|
62 this.elements.setWidth(450); // 185 |
|
63 this.elements.setHeight(500); // 120 |
|
64 this.elements.setShowHeaderContextMenu(false); |
|
65 this.elements.setCanReorderFields(false); |
|
66 this.elements.setCanSort(false); |
|
67 this.elements.setCanEdit(false); |
|
68 final ListGridField vegzone = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label()); |
|
69 final ListGridField from = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from()); |
|
70 final ListGridField to = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to()); |
|
71 vegzone.setWidth(285); |
|
72 from.setWidth(70); |
|
73 to.setWidth(70); |
|
74 |
|
75 for (final Data dataItem : data.getAll()) { |
|
76 createEntry(dataItem); |
|
77 } |
|
78 |
|
79 this.elements.setFields(vegzone, from, to); |
|
80 |
|
81 tableLayout.addMember(this.elements); |
|
82 root.addMember(title); |
|
83 root.addMember(input); |
|
84 root.addMember(tableLayout); |
|
85 root.addMember(PanelHelper.getSpacer(10)); |
|
86 |
|
87 return root; |
|
88 } |
|
89 |
|
90 private void createEntry(final Data data) { |
|
91 |
|
92 if (data.getItems() != null) { |
|
93 for (final DataItem dataItem : data.getItems()) { |
|
94 if (dataItem.getStringValue() != null) { |
|
95 if (dataItem.getStringValue().contains(",")) { |
|
96 final String[] vals = dataItem.getStringValue().split(","); |
|
97 if (vals.length == 3) { |
|
98 final String vegzone = vals[0]; |
|
99 final String from = vals[1]; |
|
100 final String to = vals[2]; |
|
101 |
|
102 if (vegzone == null || from == null || to == null) { |
|
103 return; |
|
104 } |
|
105 |
|
106 final ListGridRecord r = new ListGridRecord(); |
|
107 r.setAttribute("vegzone", vegzone); |
|
108 r.setAttribute("from", from); |
|
109 r.setAttribute("to", to); |
|
110 this.elements.addData(r); |
|
111 |
|
112 } |
|
113 } |
|
114 } |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 @Override |
|
120 public Canvas createOld(final DataList dataList) { // TODO: Veg-Table übersichtlich oben anzeigen, irgendwie abkürzen (etwa "20 Einträge") |
|
121 final HLayout layout = new HLayout(); |
|
122 layout.setWidth("400px"); |
|
123 final VLayout vLayout = new VLayout(); |
|
124 vLayout.setWidth(130); |
|
125 final Label label = new Label(dataList.getLabel()); |
|
126 label.setWidth("200px"); |
|
127 label.setHeight(25); |
|
128 |
|
129 final List<Data> items = dataList.getAll(); |
|
130 final Data str = getData(items, datakey); |
|
131 final DataItem[] strItems = str.getItems(); |
|
132 |
|
133 final String[] entries = strItems[0].getLabel().split(";"); |
|
134 for (final String entry : entries) { |
|
135 final String[] vals = entry.split(","); |
|
136 final Label dateLabel = new Label(vals[0] + " TODO: MAKE SELECTED ENTRIES VEGZONE FOR ARTIFACT" + vals[1]); |
|
137 dateLabel.setHeight(20); |
|
138 vLayout.addMember(dateLabel); |
|
139 } |
|
140 final Canvas back = getBackButton(dataList.getState()); |
|
141 layout.addMember(label); |
|
142 layout.addMember(vLayout); |
|
143 layout.addMember(back); |
|
144 |
|
145 return layout; |
|
146 } |
|
147 |
|
148 @Override |
|
149 public Canvas create(final DataList data) { |
|
150 final VLayout layout = new VLayout(); |
|
151 final Canvas helper = createHelper(); |
|
152 this.helperContainer.addMember(helper); |
|
153 |
|
154 final Canvas submit = getNextButton(); |
|
155 // if (data.size() == 0) { // TODO: GET DATA |
|
156 |
|
157 data.add(getDummyData()); |
|
158 |
|
159 // } |
|
160 final Canvas widget = createWidget(data); |
|
161 |
|
162 layout.addMember(widget); |
|
163 layout.addMember(submit); // TODO: SUBMIT |
|
164 |
|
165 // fetchSedimentLoadData(); //TODO: feed from database... |
|
166 |
|
167 return layout; |
|
168 } |
|
169 |
|
170 private Canvas createHelper() { |
|
171 this.table = new ListGrid(); |
|
172 this.table.setShowHeaderContextMenu(false); |
|
173 this.table.setWidth100(); |
|
174 this.table.setShowRecordComponents(true); |
|
175 this.table.setShowRecordComponentsByCell(true); |
|
176 this.table.setHeight100(); |
|
177 this.table.setEmptyMessage(this.MSG.empty_table()); |
|
178 this.table.setCanReorderFields(false); |
|
179 |
|
180 /* Input support pins */ |
|
181 // final String baseUrl = GWT.getHostPageBaseURL(); |
|
182 // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); |
|
183 // pinFrom.setWidth(300); |
|
184 // pinFrom.setType(ListGridFieldType.ICON); |
|
185 // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); |
|
186 // |
|
187 // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); |
|
188 // pinTo.setType(ListGridFieldType.ICON); |
|
189 // pinTo.setWidth(300); |
|
190 // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); |
|
191 // |
|
192 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
193 // @Override |
|
194 // public void onRecordClick(final RecordClickEvent e) { |
|
195 // final Record r = e.getRecord(); |
|
196 // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date?? |
|
197 // } |
|
198 // }); |
|
199 // |
|
200 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
201 // @Override |
|
202 // public void onRecordClick(final RecordClickEvent e) { |
|
203 // final Record r = e.getRecord(); |
|
204 // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date")); |
|
205 // } |
|
206 // }); |
|
207 // |
|
208 // pinTo.addRecordClickHandler(new RecordClickHandler() { |
|
209 // @Override |
|
210 // public void onRecordClick(final RecordClickEvent e) { |
|
211 // final Record r = e.getRecord(); |
|
212 // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date")); |
|
213 // } |
|
214 // }); |
|
215 // |
|
216 // final ListGridField date = new ListGridField("date", this.MSG.year()); |
|
217 // date.setType(ListGridFieldType.TEXT); |
|
218 // date.setWidth(100); |
|
219 // |
|
220 // final ListGridField descr = new ListGridField("description", this.MSG.description()); |
|
221 // descr.setType(ListGridFieldType.TEXT); |
|
222 // descr.setWidth("*"); |
|
223 // |
|
224 // this.table.setFields(pinFrom, pinTo, date, descr); |
|
225 return this.table; |
|
226 } |
|
227 |
|
228 @Override |
|
229 protected Data[] getData() { |
|
230 final List<Data> data = new ArrayList<Data>(); |
|
231 |
|
232 final ListGridRecord[] lgr = this.elements.getRecords(); |
|
233 if (lgr.length == 0) { |
|
234 return getDummyData();// return new Data[0]; |
|
235 } |
|
236 String d = ""; |
|
237 for (final ListGridRecord element : lgr) { |
|
238 final Record r = element; |
|
239 d += r.getAttribute("vegzone") + "," + r.getAttribute("from") + "," + r.getAttribute("to"); |
|
240 d += ";"; |
|
241 } |
|
242 |
|
243 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key |
|
244 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); |
|
245 return data.toArray(new Data[data.size()]); |
|
246 } |
|
247 |
|
248 private Data[] getDummyData() { |
|
249 final List<Data> data = new ArrayList<Data>(); |
|
250 String d = ""; |
|
251 d = d + "Zonaler Wald" + "," + "0" + "," + "5"; |
|
252 final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key |
|
253 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); |
|
254 return data.toArray(new Data[data.size()]); |
|
255 } |
|
256 |
|
257 } |