9068
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.client.client.ui.uinfo; |
|
11 |
|
12 import java.util.ArrayList; |
|
13 import java.util.List; |
|
14 |
|
15 import org.dive4elements.river.client.client.ui.AbstractUIProvider; |
|
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.grid.ListGrid; |
|
27 import com.smartgwt.client.widgets.grid.ListGridRecord; |
|
28 import com.smartgwt.client.widgets.layout.HLayout; |
|
29 import com.smartgwt.client.widgets.layout.VLayout; |
|
30 |
|
31 /** |
|
32 * @author Domenico Nardi Tironi |
|
33 * |
|
34 */ |
|
35 public abstract class SuperVegZonesTablePanel extends AbstractUIProvider { |
|
36 private static final long serialVersionUID = 1L; |
|
37 public static final String tableCellSeparator = "tableCellSeparator"; |
|
38 public static final String tableRowSeparator = "tableRowSeparator"; |
|
39 |
|
40 protected static final String datakey = "vegzones"; |
|
41 |
|
42 protected final ListGrid elements = new ListGrid(); |
|
43 protected TextItem vegzone; |
|
44 protected TextItem start; |
|
45 protected TextItem end; |
|
46 private ListGrid table; |
|
47 |
|
48 final protected VLayout root = new VLayout(); |
|
49 final protected HLayout input = new HLayout(); |
|
50 final protected VLayout tableLayout = new VLayout(); |
|
51 |
|
52 public SuperVegZonesTablePanel() { |
|
53 |
|
54 } |
|
55 |
|
56 protected final Canvas createHelper() { |
|
57 this.table = new ListGrid(); |
|
58 this.table.setShowHeaderContextMenu(false); |
|
59 this.table.setWidth100(); |
|
60 this.table.setShowRecordComponents(true); |
|
61 this.table.setShowRecordComponentsByCell(true); |
|
62 this.table.setHeight100(); |
|
63 this.table.setEmptyMessage(this.MSG.empty_table()); |
|
64 this.table.setCanReorderFields(false); |
|
65 |
|
66 /* Input support pins */ |
|
67 // final String baseUrl = GWT.getHostPageBaseURL(); |
|
68 // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from()); |
|
69 // pinFrom.setWidth(300); |
|
70 // pinFrom.setType(ListGridFieldType.ICON); |
|
71 // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen()); |
|
72 // |
|
73 // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to()); |
|
74 // pinTo.setType(ListGridFieldType.ICON); |
|
75 // pinTo.setWidth(300); |
|
76 // pinTo.setCellIcon(baseUrl + this.MSG.markerRed()); |
|
77 // |
|
78 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
79 // @Override |
|
80 // public void onRecordClick(final RecordClickEvent e) { |
|
81 // final Record r = e.getRecord(); |
|
82 // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date?? |
|
83 // } |
|
84 // }); |
|
85 // |
|
86 // pinFrom.addRecordClickHandler(new RecordClickHandler() { |
|
87 // @Override |
|
88 // public void onRecordClick(final RecordClickEvent e) { |
|
89 // final Record r = e.getRecord(); |
|
90 // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date")); |
|
91 // } |
|
92 // }); |
|
93 // |
|
94 // pinTo.addRecordClickHandler(new RecordClickHandler() { |
|
95 // @Override |
|
96 // public void onRecordClick(final RecordClickEvent e) { |
|
97 // final Record r = e.getRecord(); |
|
98 // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date")); |
|
99 // } |
|
100 // }); |
|
101 // |
|
102 // final ListGridField date = new ListGridField("date", this.MSG.year()); |
|
103 // date.setType(ListGridFieldType.TEXT); |
|
104 // date.setWidth(100); |
|
105 // |
|
106 // final ListGridField descr = new ListGridField("description", this.MSG.description()); |
|
107 // descr.setType(ListGridFieldType.TEXT); |
|
108 // descr.setWidth("*"); |
|
109 // |
|
110 // this.table.setFields(pinFrom, pinTo, date, descr); |
|
111 return this.table; |
|
112 } |
|
113 |
|
114 public abstract Canvas createWidget(final DataList data); |
|
115 |
|
116 protected final void addDataInit(final DataList data) { |
|
117 for (final Data dataItemContainer : data.getAll()) { |
|
118 if (dataItemContainer.getItems() != null) { |
|
119 for (final DataItem dataItem : dataItemContainer.getItems()) { |
|
120 if (dataItem.getStringValue() != null && dataItem.getStringValue().contains(tableRowSeparator)) { |
|
121 |
|
122 final String[] rows = dataItem.getStringValue().split(tableRowSeparator); |
|
123 for (final String row : rows) { |
|
124 this.elements.addData(createEntry(row)); |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 @Override |
|
133 public final Canvas create(final DataList data) { |
|
134 final VLayout layout = new VLayout(); |
|
135 final Canvas helper = createHelper(); |
|
136 this.helperContainer.addMember(helper); |
|
137 |
|
138 final Canvas submit = getNextButton(); |
|
139 final Canvas widget = createWidget(data); |
|
140 |
|
141 layout.addMember(widget); |
|
142 layout.addMember(submit); // TODO: SUBMIT |
|
143 |
|
144 // fetchSedimentLoadData(); //TODO: feed from database... |
|
145 |
|
146 return layout; |
|
147 } |
|
148 |
|
149 @Override |
|
150 public Canvas createOld(final DataList dataList) { |
|
151 final HLayout layout = new HLayout(); |
|
152 layout.setWidth("400px"); |
|
153 final VLayout vLayout = new VLayout(); |
|
154 vLayout.setWidth(130); |
|
155 final Label label = new Label(dataList.getLabel()); |
|
156 label.setWidth("200px"); |
|
157 label.setHeight(25); |
|
158 |
|
159 final List<Data> items = dataList.getAll(); |
|
160 final Data str = getData(items, datakey); |
|
161 final DataItem[] strItems = str.getItems(); |
|
162 |
|
163 final String[] entries = strItems[0].getLabel().split(VegetationzonesTablePanel.tableRowSeparator); |
|
164 for (final String entry : entries) { |
|
165 final String[] vals = entry.split(VegetationzonesTablePanel.tableCellSeparator); |
|
166 final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")"); |
|
167 dateLabel.setHeight(20); |
|
168 vLayout.addMember(dateLabel); |
|
169 } |
|
170 final Canvas back = getBackButton(dataList.getState()); |
|
171 layout.addMember(label); |
|
172 layout.addMember(vLayout); |
|
173 layout.addMember(back); |
|
174 |
|
175 return layout; |
|
176 } |
|
177 |
|
178 protected static final Data[] getDummyData() { |
|
179 final List<Data> data = new ArrayList<Data>(); |
|
180 String d = ""; |
|
181 d = d + "Zonaler Wald" + tableCellSeparator + "0" + tableCellSeparator + "5" + tableRowSeparator; |
|
182 d = d + "Hartholzaue, trocken" + tableCellSeparator + "5" + tableCellSeparator + "40" + tableRowSeparator; |
|
183 d = d + "Hartholzaue, feucht" + tableCellSeparator + "40" + tableCellSeparator + "80" + tableRowSeparator; |
|
184 d = d + "Silberweidenwald" + tableCellSeparator + "80" + tableCellSeparator + "140" + tableRowSeparator; |
|
185 d = d + "Weidengebüsch" + tableCellSeparator + "140" + tableCellSeparator + "200" + tableRowSeparator; |
|
186 d = d + "Uferröhricht" + tableCellSeparator + "200" + tableCellSeparator + "260" + tableRowSeparator; |
|
187 d = d + "Uferpioniere" + tableCellSeparator + "260" + tableCellSeparator + "320" + tableRowSeparator; |
|
188 d = d + "Vegetationslos" + tableCellSeparator + "320" + tableCellSeparator + "365" + tableRowSeparator; |
|
189 d = d + "Wasserfläche" + tableCellSeparator + "365" + tableCellSeparator + "365" + tableRowSeparator; |
|
190 |
|
191 final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key |
|
192 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); |
|
193 return data.toArray(new Data[data.size()]); |
|
194 } |
|
195 |
|
196 @Override |
|
197 protected final Data[] getData() { |
|
198 final List<Data> data = new ArrayList<Data>(); |
|
199 |
|
200 final ListGridRecord[] lgr = this.elements.getRecords(); |
|
201 if (lgr.length == 0) { |
|
202 return getDummyData();// new Data[0]; // return getDummyData(); |
|
203 } |
|
204 String d = ""; |
|
205 for (final ListGridRecord element : lgr) { |
|
206 final Record r = element; |
|
207 d += r.getAttribute("vegzone") + VegetationzonesTablePanel.tableCellSeparator + r.getAttribute("from") |
|
208 + VegetationzonesTablePanel.tableCellSeparator + r.getAttribute("to"); |
|
209 d += VegetationzonesTablePanel.tableRowSeparator; |
|
210 } |
|
211 |
|
212 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key |
|
213 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); |
|
214 return data.toArray(new Data[data.size()]); |
|
215 } |
|
216 |
|
217 public final ListGridRecord createEntry(final String row) { |
|
218 |
|
219 if (row.contains(tableCellSeparator)) { |
|
220 |
|
221 final String[] vals = row.split(tableCellSeparator); |
|
222 if (vals.length == 3) { |
|
223 final String vegzone = vals[0]; |
|
224 final String from = vals[1]; |
|
225 final String to = vals[2]; |
|
226 |
|
227 if (vegzone == null || from == null || to == null) { |
|
228 return null; |
|
229 } |
|
230 |
|
231 final ListGridRecord r = new ListGridRecord(); |
|
232 r.setAttribute("vegzone", vegzone); |
|
233 r.setAttribute("from", from); |
|
234 r.setAttribute("to", to); |
|
235 return r; |
|
236 |
|
237 } |
|
238 |
|
239 } |
|
240 return null; |
|
241 } |
|
242 |
|
243 } |