comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/AbstractVegZonesTablePanel.java @ 9070:611a523fc42f

VegetationZoneAccessHelper, VegetationTablePanels verbessert
author gernotbelger
date Tue, 15 May 2018 18:04:36 +0200
parents gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/SuperVegZonesTablePanel.java@1ffd38826175
children 41f4bc83aa7a
comparison
equal deleted inserted replaced
9069:1ffd38826175 9070:611a523fc42f
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.client.ui.PanelHelper;
17 import org.dive4elements.river.client.shared.model.Data;
18 import org.dive4elements.river.client.shared.model.DataItem;
19 import org.dive4elements.river.client.shared.model.DataList;
20 import org.dive4elements.river.client.shared.model.DefaultData;
21 import org.dive4elements.river.client.shared.model.DefaultDataItem;
22
23 import com.smartgwt.client.data.Record;
24 import com.smartgwt.client.types.Alignment;
25 import com.smartgwt.client.widgets.Canvas;
26 import com.smartgwt.client.widgets.Label;
27 import com.smartgwt.client.widgets.form.fields.TextItem;
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 /**
35 * @author Domenico Nardi Tironi
36 *
37 */
38 public abstract class AbstractVegZonesTablePanel extends AbstractUIProvider {
39 private static final long serialVersionUID = 1L;
40 public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
41 public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
42
43 protected static final String datakey = "vegzones";
44
45 protected final ListGrid elements = new ListGrid();
46 protected TextItem vegzone;
47 protected TextItem start;
48 protected TextItem end;
49 private ListGrid table;
50
51 protected ListGridField vegzoneField;// = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
52 protected ListGridField fromField;// = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
53 protected ListGridField toField;// = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
54
55 final protected VLayout root = new VLayout();
56 final protected HLayout input = new HLayout();
57 final protected VLayout tableLayout = new VLayout();
58
59 protected final void createTable(final DataList data, final int width) {
60 data.add(VegetationzonesTablePanel.getDummyData()); // TODO: GET REAL DATA!
61
62 final Label title = new Label(data.get(0).getDescription());
63 title.setHeight("35px"); // orig:25
64
65 this.elements.setWidth(width); // 185
66 this.elements.setHeight(300); //
67 this.elements.setShowHeaderContextMenu(false);
68 this.elements.setCanReorderFields(false);
69 this.elements.setCanSort(false);
70 this.elements.setCanEdit(false);
71 this.vegzoneField = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
72 this.fromField = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
73 this.toField = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
74 this.vegzoneField.setWidth(245);
75 this.fromField.setWidth(80);
76 this.toField.setWidth(80);
77 this.fromField.setAlign(Alignment.RIGHT);
78 this.toField.setAlign(Alignment.RIGHT);
79
80 addDataInit(data);
81
82 this.root.addMember(title);
83 this.tableLayout.addMember(this.elements);
84 this.root.addMember(this.input);
85 this.root.addMember(this.tableLayout);
86 this.root.addMember(PanelHelper.getSpacer(10));
87
88 }
89
90 protected final Canvas createHelper() {
91 this.table = new ListGrid();
92 this.table.setShowHeaderContextMenu(false);
93 this.table.setWidth100();
94 this.table.setShowRecordComponents(true);
95 this.table.setShowRecordComponentsByCell(true);
96 this.table.setHeight100();
97 this.table.setEmptyMessage(this.MSG.empty_table());
98 this.table.setCanReorderFields(false);
99
100 /* Input support pins */
101 // final String baseUrl = GWT.getHostPageBaseURL();
102 // final ListGridField pinFrom = new ListGridField("fromIcon", this.MSG.uinfo_vegetation_zones_from());
103 // pinFrom.setWidth(300);
104 // pinFrom.setType(ListGridFieldType.ICON);
105 // pinFrom.setCellIcon(baseUrl + this.MSG.markerGreen());
106 //
107 // final ListGridField pinTo = new ListGridField("toIcon", this.MSG.uinfo_vegetation_zones_to());
108 // pinTo.setType(ListGridFieldType.ICON);
109 // pinTo.setWidth(300);
110 // pinTo.setCellIcon(baseUrl + this.MSG.markerRed());
111 //
112 // pinFrom.addRecordClickHandler(new RecordClickHandler() {
113 // @Override
114 // public void onRecordClick(final RecordClickEvent e) {
115 // final Record r = e.getRecord();
116 // VegetationzonesTableEditPanel.this.vegzone.setValue(r.getAttribute("date")); // date??
117 // }
118 // });
119 //
120 // pinFrom.addRecordClickHandler(new RecordClickHandler() {
121 // @Override
122 // public void onRecordClick(final RecordClickEvent e) {
123 // final Record r = e.getRecord();
124 // VegetationzonesTableEditPanel.this.start.setValue(r.getAttribute("date"));
125 // }
126 // });
127 //
128 // pinTo.addRecordClickHandler(new RecordClickHandler() {
129 // @Override
130 // public void onRecordClick(final RecordClickEvent e) {
131 // final Record r = e.getRecord();
132 // VegetationzonesTableEditPanel.this.end.setValue(r.getAttribute("date"));
133 // }
134 // });
135 //
136 // final ListGridField date = new ListGridField("date", this.MSG.year());
137 // date.setType(ListGridFieldType.TEXT);
138 // date.setWidth(100);
139 //
140 // final ListGridField descr = new ListGridField("description", this.MSG.description());
141 // descr.setType(ListGridFieldType.TEXT);
142 // descr.setWidth("*");
143 //
144 // this.table.setFields(pinFrom, pinTo, date, descr);
145 return this.table;
146 }
147
148 public abstract Canvas createWidget(final DataList data);
149
150 private final void addDataInit(final DataList data) {
151 for (final Data dataItemContainer : data.getAll()) {
152 if (dataItemContainer.getItems() != null) {
153 for (final DataItem dataItem : dataItemContainer.getItems()) {
154 if (dataItem.getStringValue() != null && dataItem.getStringValue().contains(TABLE_ROW_SEPARATOR)) {
155
156 final String[] rows = dataItem.getStringValue().split(TABLE_ROW_SEPARATOR);
157 for (final String row : rows) {
158 this.elements.addData(createEntry(row));
159 }
160 }
161 }
162 }
163 }
164 }
165
166 @Override
167 public final Canvas create(final DataList data) {
168 final VLayout layout = new VLayout();
169 final Canvas helper = createHelper();
170 this.helperContainer.addMember(helper);
171
172 final Canvas submit = getNextButton();
173 final Canvas widget = createWidget(data);
174
175 layout.addMember(widget);
176 layout.addMember(submit); // TODO: SUBMIT
177
178 // fetchSedimentLoadData(); //TODO: feed from database...
179
180 return layout;
181 }
182
183 @Override
184 public Canvas createOld(final DataList dataList) {
185 final HLayout layout = new HLayout();
186 layout.setWidth("400px");
187 final VLayout vLayout = new VLayout();
188 vLayout.setWidth(130);
189 final Label label = new Label(dataList.getLabel());
190 label.setWidth("200px");
191 label.setHeight(25);
192
193 final List<Data> items = dataList.getAll();
194 final Data str = getData(items, datakey);
195 final DataItem[] strItems = str.getItems();
196
197 final String[] entries = strItems[0].getLabel().split(VegetationzonesTablePanel.TABLE_ROW_SEPARATOR);
198 for (final String entry : entries) {
199 final String[] vals = entry.split(VegetationzonesTablePanel.TABLE_CELL_SEPARATOR);
200 final Label dateLabel = new Label(vals[0] + " (" + vals[1] + "-" + vals[2] + ")");
201 dateLabel.setHeight(20);
202 vLayout.addMember(dateLabel);
203 }
204 final Canvas back = getBackButton(dataList.getState());
205 layout.addMember(label);
206 layout.addMember(vLayout);
207 layout.addMember(back);
208
209 return layout;
210 }
211
212 protected static final Data[] getDummyData() {
213 final List<Data> data = new ArrayList<Data>();
214
215 // TODO: move to messages
216 final String d = "Zonaler Wald" + TABLE_CELL_SEPARATOR + "0" + TABLE_CELL_SEPARATOR + "5" + TABLE_ROW_SEPARATOR//
217 + "Hartholzaue, trocken" + TABLE_CELL_SEPARATOR + "5" + TABLE_CELL_SEPARATOR + "40" + TABLE_ROW_SEPARATOR//
218 + "Hartholzaue, feucht" + TABLE_CELL_SEPARATOR + "40" + TABLE_CELL_SEPARATOR + "80" + TABLE_ROW_SEPARATOR//
219 + "Silberweidenwald" + TABLE_CELL_SEPARATOR + "80" + TABLE_CELL_SEPARATOR + "140" + TABLE_ROW_SEPARATOR//
220 + "Weidengebüsch" + TABLE_CELL_SEPARATOR + "140" + TABLE_CELL_SEPARATOR + "200" + TABLE_ROW_SEPARATOR//
221 + "Uferröhricht" + TABLE_CELL_SEPARATOR + "200" + TABLE_CELL_SEPARATOR + "260" + TABLE_ROW_SEPARATOR//
222 + "Uferpioniere" + TABLE_CELL_SEPARATOR + "260" + TABLE_CELL_SEPARATOR + "320" + TABLE_ROW_SEPARATOR//
223 + "Vegetationslos" + TABLE_CELL_SEPARATOR + "320" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR//
224 + "Wasserfläche" + TABLE_CELL_SEPARATOR + "365" + TABLE_CELL_SEPARATOR + "365" + TABLE_ROW_SEPARATOR;//
225
226 final DataItem item = new DefaultDataItem(datakey, "entryDescription", d); // DATA-key
227 data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
228 return data.toArray(new Data[data.size()]);
229 }
230
231 @Override
232 protected final Data[] getData() {
233 final List<Data> data = new ArrayList<Data>();
234
235 final ListGridRecord[] lgr = this.elements.getRecords();
236 if (lgr.length == 0) {
237 return getDummyData();// new Data[0]; // return getDummyData();
238 }
239 String d = "";
240 for (final ListGridRecord element : lgr) {
241 final Record r = element;
242 d += r.getAttribute("vegzone") + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("from")
243 + VegetationzonesTablePanel.TABLE_CELL_SEPARATOR + r.getAttribute("to");
244 d += VegetationzonesTablePanel.TABLE_ROW_SEPARATOR;
245 }
246
247 final DataItem item = new DefaultDataItem(datakey, null, d); // DATA-key
248 data.add(new DefaultData(datakey, null, null, new DataItem[] { item }));
249 return data.toArray(new Data[data.size()]);
250 }
251
252 public final ListGridRecord createEntry(final String row) {
253
254 if (row.contains(TABLE_CELL_SEPARATOR)) {
255
256 final String[] vals = row.split(TABLE_CELL_SEPARATOR);
257 if (vals.length == 3) {
258 final String vegzone = vals[0];
259 final String from = vals[1];
260 final String to = vals[2];
261
262 if (vegzone == null || from == null || to == null) {
263 return null;
264 }
265
266 final ListGridRecord r = new ListGridRecord();
267 r.setAttribute("vegzone", vegzone);
268 r.setAttribute("from", from);
269 r.setAttribute("to", to);
270 return r;
271
272 }
273
274 }
275 return null;
276 }
277
278 }

http://dive4elements.wald.intevation.org