Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SuperVegZonesTablePanel.java @ 9069:1ffd38826175
access uinfo.vegetationzones+inundation_duration
author | gernotbelger |
---|---|
date | Tue, 15 May 2018 12:00:26 +0200 |
parents | a5cf8d7bff3c |
children |
rev | line source |
---|---|
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; | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
37 public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
38 public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; |
9068 | 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()) { | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
120 if (dataItem.getStringValue() != null && dataItem.getStringValue().contains(TABLE_ROW_SEPARATOR)) { |
9068 | 121 |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
122 final String[] rows = dataItem.getStringValue().split(TABLE_ROW_SEPARATOR); |
9068 | 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 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
163 final String[] entries = strItems[0].getLabel().split(VegetationzonesTablePanel.TABLE_ROW_SEPARATOR); |
9068 | 164 for (final String entry : entries) { |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
165 final String[] vals = entry.split(VegetationzonesTablePanel.TABLE_CELL_SEPARATOR); |
9068 | 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 = ""; | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
181 // TODO: move to messages |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
182 d = d + "Zonaler Wald" + TABLE_CELL_SEPARATOR + "0" + TABLE_CELL_SEPARATOR + "5" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
183 d = d + "Hartholzaue, trocken" + TABLE_CELL_SEPARATOR + "5" + TABLE_CELL_SEPARATOR + "40" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
184 d = d + "Hartholzaue, feucht" + TABLE_CELL_SEPARATOR + "40" + TABLE_CELL_SEPARATOR + "80" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
185 d = d + "Silberweidenwald" + TABLE_CELL_SEPARATOR + "80" + TABLE_CELL_SEPARATOR + "140" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
186 d = d + "Weidengebüsch" + TABLE_CELL_SEPARATOR + "140" + TABLE_CELL_SEPARATOR + "200" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
187 d = d + "Uferröhricht" + TABLE_CELL_SEPARATOR + "200" + TABLE_CELL_SEPARATOR + "260" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
188 d = d + "Uferpioniere" + TABLE_CELL_SEPARATOR + "260" + TABLE_CELL_SEPARATOR + "320" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
189 d = d + "Vegetationslos" + TABLE_CELL_SEPARATOR + "320" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR; |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
190 d = d + "Wasserfläche" + TABLE_CELL_SEPARATOR + "365" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR; |
9068 | 191 |
192 final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key | |
193 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); | |
194 return data.toArray(new Data[data.size()]); | |
195 } | |
196 | |
197 @Override | |
198 protected final Data[] getData() { | |
199 final List<Data> data = new ArrayList<Data>(); | |
200 | |
201 final ListGridRecord[] lgr = this.elements.getRecords(); | |
202 if (lgr.length == 0) { | |
203 return getDummyData();// new Data[0]; // return getDummyData(); | |
204 } | |
205 String d = ""; | |
206 for (final ListGridRecord element : lgr) { | |
207 final Record r = element; | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
208 d += r.getAttribute("vegzone") + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from") |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
209 + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to"); |
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
210 d += VegetationzonesTablePanel.TABLE_ROW_SEPARATOR; |
9068 | 211 } |
212 | |
213 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key | |
214 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); | |
215 return data.toArray(new Data[data.size()]); | |
216 } | |
217 | |
218 public final ListGridRecord createEntry(final String row) { | |
219 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
220 if (row.contains(TABLE_CELL_SEPARATOR)) { |
9068 | 221 |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9068
diff
changeset
|
222 final String[] vals = row.split(TABLE_CELL_SEPARATOR); |
9068 | 223 if (vals.length == 3) { |
224 final String vegzone = vals[0]; | |
225 final String from = vals[1]; | |
226 final String to = vals[2]; | |
227 | |
228 if (vegzone == null || from == null || to == null) { | |
229 return null; | |
230 } | |
231 | |
232 final ListGridRecord r = new ListGridRecord(); | |
233 r.setAttribute("vegzone", vegzone); | |
234 r.setAttribute("from", from); | |
235 r.setAttribute("to", to); | |
236 return r; | |
237 | |
238 } | |
239 | |
240 } | |
241 return null; | |
242 } | |
243 | |
244 } |