Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/FloodInfrastructurePanel.java @ 9611:8ed6c45136fa
#20 UI
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 09 Oct 2019 15:58:46 +0200 |
parents | |
children | 02ca823ec9c6 |
comparison
equal
deleted
inserted
replaced
9610:020d4a595205 | 9611:8ed6c45136fa |
---|---|
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.sinfo; | |
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.DatacageWidget; | |
17 import org.dive4elements.river.client.client.ui.DatacageWidgetData; | |
18 import org.dive4elements.river.client.client.ui.PanelHelper; | |
19 import org.dive4elements.river.client.shared.model.Data; | |
20 import org.dive4elements.river.client.shared.model.DataItem; | |
21 import org.dive4elements.river.client.shared.model.DataList; | |
22 import org.dive4elements.river.client.shared.model.DefaultData; | |
23 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
24 import org.dive4elements.river.client.shared.model.User; | |
25 import org.dive4elements.river.client.shared.model.VegetationZoneServerClientXChange; | |
26 | |
27 import com.google.gwt.core.client.GWT; | |
28 import com.smartgwt.client.types.ListGridFieldType; | |
29 import com.smartgwt.client.util.SC; | |
30 import com.smartgwt.client.widgets.Button; | |
31 import com.smartgwt.client.widgets.Canvas; | |
32 import com.smartgwt.client.widgets.Label; | |
33 import com.smartgwt.client.widgets.events.ClickEvent; | |
34 import com.smartgwt.client.widgets.events.ClickHandler; | |
35 import com.smartgwt.client.widgets.form.DynamicForm; | |
36 import com.smartgwt.client.widgets.form.fields.ColorItem; | |
37 import com.smartgwt.client.widgets.grid.ListGrid; | |
38 import com.smartgwt.client.widgets.grid.ListGridField; | |
39 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
40 import com.smartgwt.client.widgets.grid.events.CellSavedEvent; | |
41 import com.smartgwt.client.widgets.grid.events.CellSavedHandler; | |
42 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
43 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
44 import com.smartgwt.client.widgets.layout.HLayout; | |
45 import com.smartgwt.client.widgets.layout.Layout; | |
46 import com.smartgwt.client.widgets.layout.VLayout; | |
47 import com.smartgwt.client.widgets.tree.TreeNode; | |
48 | |
49 /** | |
50 * @author Domenico Nardi Tironi | |
51 * | |
52 */ | |
53 public class FloodInfrastructurePanel extends AbstractUIProvider { | |
54 private static final long serialVersionUID = 1L; | |
55 | |
56 private static final String datakey = "flood_infrastructure"; | |
57 final protected List<ListGridRecord> records = new ArrayList<ListGridRecord>(); | |
58 private ListGrid elements = new ListGrid(); | |
59 | |
60 private final User m_user; | |
61 | |
62 public FloodInfrastructurePanel(final User user) { | |
63 this.m_user = user; | |
64 } | |
65 | |
66 protected final ListGrid createTable(final Layout root, final DataList data, final String width, final boolean editable) { | |
67 | |
68 final Label title = new Label(data.get(0).getDescription()); | |
69 title.setHeight("35px"); | |
70 | |
71 this.elements.setWidth(width); | |
72 this.elements.setHeight(300); | |
73 this.elements.setShowHeaderContextMenu(false); | |
74 this.elements.setCanReorderFields(false); | |
75 this.elements.setCanSort(true); | |
76 this.elements.setSortField("to"); | |
77 this.elements.setCanResizeFields(false); | |
78 | |
79 this.elements.setCanEdit(editable); | |
80 | |
81 final ListGridField internalNumber = new ListGridField("number", "number"); // valid only if no data is to be added | |
82 internalNumber.setCanSort(false); | |
83 internalNumber.setHidden(true); | |
84 | |
85 final ListGridField infrstrField = new ListGridField("infrstr", "Infrastruktur BWaStr");// this.MSG.uinfo_vegetation_zones_label()); | |
86 infrstrField.setType(ListGridFieldType.TEXT); | |
87 infrstrField.setWidth("*"); // 245 | |
88 infrstrField.setCanSort(false); | |
89 infrstrField.setCanDragResize(true); | |
90 infrstrField.setCanEdit(true); // neue Anforderung - doch nicht? ??? | |
91 | |
92 final ListGridField fromField = new ListGridField("type", "Typ/Bezeichnung"); // VegZonePanelHelper.createIntTableField("from", | |
93 // this.MSG.uinfo_vegetation_zones_from(), true, | |
94 // getNormalizer(), getValidator() | |
95 // ); | |
96 fromField.addCellSavedHandler(new CellSavedHandler() { | |
97 @Override | |
98 public void onCellSaved(final CellSavedEvent event) { | |
99 // updateValidationMsgLabel(); | |
100 } | |
101 }); | |
102 | |
103 fromField.setCanEdit(false); | |
104 | |
105 final ListGridField removeField = PanelHelper.createRemoveField(this.elements, GWT.getHostPageBaseURL() + this.MSG.removeFeature()); | |
106 this.elements.addRecordClickHandler(new RecordClickHandler() { // adding another custom record-Remove-Handler which is not included in the | |
107 // Panelhelper TODO: MERGE WITH SupraRegionalPanel!! | |
108 @Override | |
109 public void onRecordClick(final RecordClickEvent event) { | |
110 if (event.getField().getName().equals(removeField.getName())) { | |
111 // updateValidationMsgLabel(); | |
112 } | |
113 } | |
114 }); | |
115 this.elements.setFields(infrstrField, fromField, removeField); | |
116 | |
117 root.setWidth(width); | |
118 root.addMember(title); | |
119 root.addMember(this.elements); | |
120 root.addMember(PanelHelper.getSpacer(3)); | |
121 root.addMember(PanelHelper.getSpacer(3)); | |
122 return this.elements; | |
123 | |
124 } | |
125 | |
126 @Override | |
127 public final VLayout create(final DataList data) { | |
128 final VLayout layout = new VLayout(); | |
129 | |
130 final Canvas helper = createHelper(data); | |
131 if (helper != null) | |
132 this.helperContainer.addMember(helper); | |
133 | |
134 final Canvas submit = getNextButton(); | |
135 | |
136 final VLayout root = new VLayout(); | |
137 root.setWidth(450); | |
138 createWidget(root, data); | |
139 | |
140 layout.addMember(root); | |
141 layout.addMember(submit); | |
142 | |
143 // updateValidationMsgLabel();// init Text | |
144 | |
145 return layout; | |
146 } | |
147 | |
148 protected Canvas createHelper(final DataList dataList) { | |
149 | |
150 final DatacageWidgetData data = new DatacageWidgetData(this.artifact, this.m_user, "uinfo.inundation_duration.vegZoneSelect", "load-system:true", | |
151 false); | |
152 | |
153 final DatacageWidget datacage = new DatacageWidget(data); | |
154 | |
155 final Button plusBtn = new Button("Hinzufügen"); // this.MSG.uinfo_inundation_duration_set_vegetation_zone() | |
156 plusBtn.addClickHandler(new ClickHandler() { | |
157 @Override | |
158 public void onClick(final ClickEvent event) { | |
159 handlePlusClicked(datacage); | |
160 } | |
161 }); | |
162 | |
163 final VLayout helperLayout = new VLayout(); | |
164 helperLayout.addMember(datacage); | |
165 helperLayout.addMember(plusBtn); | |
166 | |
167 return helperLayout; | |
168 } | |
169 | |
170 private void handlePlusClicked(final DatacageWidget datacage) { | |
171 final List<TreeNode> selection = datacage.getPlainSelection(); | |
172 if (selection == null || selection.isEmpty()) { | |
173 SC.say("VegetationzonesTablePanel.this.MSG.warning()"); | |
174 return; | |
175 } | |
176 | |
177 final TreeNode selectedNode = selection.get(0); | |
178 | |
179 /* | |
180 * the encoded veg-zones is either in 'data' or 'ids'. We need both, because we have the cases of stadnard vegzones and | |
181 * user-defined vegzones. | |
182 */ | |
183 final String dataAttribute = selectedNode.getAttribute("data"); | |
184 final String idsAttribute = selectedNode.getAttribute("ids"); | |
185 final String vegZoneData = (dataAttribute == null || dataAttribute.trim().length() == 0) ? idsAttribute : dataAttribute; | |
186 | |
187 // for (final ListGridRecord r : this.elements.getRecords()) { | |
188 // this.elements.removeData(r); | |
189 // } | |
190 // final List<VegetationZoneServerClientXChange> rows = VegetationZoneServerClientXChange.parse(data); | |
191 // for (final VegetationZoneServerClientXChange row : rows) { | |
192 // this.elements.addData(createEntry(row)); | |
193 // } | |
194 | |
195 } | |
196 | |
197 public final ListGridRecord createEntry(final VegetationZoneServerClientXChange row) { | |
198 | |
199 final String vegzone = row.getZoneName(); | |
200 final Integer from = row.getMin_day_overflow(); | |
201 final Integer to = row.getMax_day_overflow(); | |
202 final String colorStr = row.getHexColor(); | |
203 | |
204 if (vegzone == null) | |
205 return null; | |
206 | |
207 final ListGridRecord r = new ListGridRecord(); | |
208 r.setAttribute("vegzone", vegzone); | |
209 r.setAttribute("from", from); | |
210 r.setAttribute("to", to); | |
211 r.setAttribute("color", colorStr); | |
212 r.setAttribute("number", this.records.size()); | |
213 this.records.add(r); | |
214 return r; | |
215 | |
216 } | |
217 | |
218 public void createWidget(final Layout root, final DataList data) { | |
219 | |
220 this.elements = createTable(root, data, "420", true); | |
221 | |
222 // this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), "*"); | |
223 // this.vegzone.setColSpan(4); | |
224 // this.start = PanelHelper.createIntegerItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), | |
225 // "*"); | |
226 // this.end = PanelHelper.createIntegerItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), "*"); | |
227 final VLayout fields = new VLayout(); | |
228 | |
229 final ColorItem colorPicker = new ColorItem(); | |
230 colorPicker.setTitle(this.MSG.uinfo_vegetation_zone_color()); | |
231 | |
232 colorPicker.setShowTitle(true); | |
233 colorPicker.setShowValueIconOnly(false); | |
234 colorPicker.setShowPickerIcon(true); | |
235 colorPicker.setColSpan(2); | |
236 colorPicker.setWidth(110); | |
237 | |
238 final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific | |
239 | |
240 final DynamicForm form1 = new DynamicForm(); | |
241 | |
242 form1.setNumCols(5); // für Layout untereinander muss 2 eingestellt werden | |
243 // form1.setFields(this.vegzone, this.start, this.end, colorPicker); | |
244 | |
245 fields.addMember(form1); | |
246 root.addMember(fields); | |
247 root.addMember(PanelHelper.getSpacer(10)); | |
248 } | |
249 | |
250 @Override | |
251 public Canvas createOld(final DataList dataList) { | |
252 final HLayout layout = new HLayout(); | |
253 layout.setWidth("400px"); | |
254 final VLayout vLayout = new VLayout(); | |
255 vLayout.setWidth(130); | |
256 final Label label = new Label(dataList.getLabel()); | |
257 label.setWidth("200px"); | |
258 label.setHeight("25px"); | |
259 | |
260 final List<Data> items = dataList.getAll(); | |
261 final Data str = getData(items, datakey); | |
262 final DataItem[] strItems = str.getItems(); | |
263 | |
264 // for (final VegetationZoneServerClientXChange entry : entries) { | |
265 final Label dateLabel = new Label("zone ( asfd - asdf )"); | |
266 dateLabel.setHeight("20px"); | |
267 vLayout.addMember(dateLabel); | |
268 | |
269 final Canvas back = getBackButton(dataList.getState()); | |
270 layout.addMember(label); | |
271 layout.addMember(vLayout); | |
272 layout.addMember(back); | |
273 | |
274 return layout; | |
275 } | |
276 | |
277 @Override | |
278 protected final Data[] getData() { | |
279 final List<Data> data = new ArrayList<Data>(); | |
280 | |
281 final ListGridRecord[] lgr = this.elements.getRecords(); | |
282 if (lgr.length == 0) { | |
283 // return new Data[0]; // TODO: Klären, ob Vegetationszonen-Auswahl Pflicht ist, ob es ein Fallback geben soll usw. | |
284 } | |
285 | |
286 final DataItem item = new DefaultDataItem(datakey, null, "VegetationZoneServerClientXChange.parseListToDataString(getZones(lgr))"); // DATA-key | |
287 data.add(new DefaultData(datakey, null, null, new DataItem[] { item })); | |
288 return data.toArray(new Data[data.size()]); | |
289 } | |
290 | |
291 } |