Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/CollisionLoadEpochPanel.java @ 9076:22d8928895a1
dynamic input table epochSelect
author | gernotbelger |
---|---|
date | Tue, 22 May 2018 11:58:30 +0200 |
parents | 766890addcb2 |
children | fc02833dbcc1 |
comparison
equal
deleted
inserted
replaced
9075:89740fe82196 | 9076:22d8928895a1 |
---|---|
9 package org.dive4elements.river.client.client.ui.sinfo; | 9 package org.dive4elements.river.client.client.ui.sinfo; |
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 |
14 import org.dive4elements.river.client.client.Config; | |
15 import org.dive4elements.river.client.client.FLYSConstants; | 14 import org.dive4elements.river.client.client.FLYSConstants; |
16 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; | 15 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; |
17 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; | 16 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; |
18 import org.dive4elements.river.client.client.ui.AbstractUIProvider; | 17 import org.dive4elements.river.client.client.ui.AbstractUIProvider; |
19 import org.dive4elements.river.client.shared.model.ArtifactDescription; | 18 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel; |
19 import org.dive4elements.river.client.client.ui.FromToTableHelperPanel.IColumnClickHandler; | |
20 import org.dive4elements.river.client.shared.model.Data; | 20 import org.dive4elements.river.client.shared.model.Data; |
21 import org.dive4elements.river.client.shared.model.DataItem; | 21 import org.dive4elements.river.client.shared.model.DataItem; |
22 import org.dive4elements.river.client.shared.model.DataList; | 22 import org.dive4elements.river.client.shared.model.DataList; |
23 import org.dive4elements.river.client.shared.model.DefaultData; | 23 import org.dive4elements.river.client.shared.model.DefaultData; |
24 import org.dive4elements.river.client.shared.model.DefaultDataItem; | 24 import org.dive4elements.river.client.shared.model.DefaultDataItem; |
25 import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; | |
26 import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; | |
27 | 25 |
28 import com.google.gwt.core.client.GWT; | 26 import com.google.gwt.core.client.GWT; |
29 import com.google.gwt.user.client.rpc.AsyncCallback; | |
30 import com.smartgwt.client.data.Record; | 27 import com.smartgwt.client.data.Record; |
31 import com.smartgwt.client.types.ListGridFieldType; | 28 import com.smartgwt.client.types.ListGridFieldType; |
32 import com.smartgwt.client.util.SC; | |
33 import com.smartgwt.client.widgets.Button; | 29 import com.smartgwt.client.widgets.Button; |
34 import com.smartgwt.client.widgets.Canvas; | 30 import com.smartgwt.client.widgets.Canvas; |
35 import com.smartgwt.client.widgets.Label; | 31 import com.smartgwt.client.widgets.Label; |
36 import com.smartgwt.client.widgets.events.ClickEvent; | 32 import com.smartgwt.client.widgets.events.ClickEvent; |
37 import com.smartgwt.client.widgets.events.ClickHandler; | 33 import com.smartgwt.client.widgets.events.ClickHandler; |
53 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 49 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
54 | 50 |
55 protected ListGrid elements; | 51 protected ListGrid elements; |
56 private TextItem start; | 52 private TextItem start; |
57 private TextItem end; | 53 private TextItem end; |
58 private ListGrid sedLoadTable; // TODO: Datenquelle für Collision richtig wählen! Sediment komplett eliminieren | 54 |
59 | 55 protected List<String> validYears = new ArrayList<String>(); |
60 protected List<String> validYears; | |
61 | 56 |
62 public Canvas createWidget(final DataList data) { | 57 public Canvas createWidget(final DataList data) { |
63 final HLayout input = new HLayout(); | 58 final HLayout input = new HLayout(); |
64 final VLayout root = new VLayout(); | 59 final VLayout root = new VLayout(); |
65 final VLayout grid = new VLayout(); | 60 final VLayout grid = new VLayout(); |
178 } | 173 } |
179 | 174 |
180 @Override | 175 @Override |
181 public Canvas create(final DataList data) { | 176 public Canvas create(final DataList data) { |
182 final VLayout layout = new VLayout(); | 177 final VLayout layout = new VLayout(); |
183 final Canvas helper = createHelper(); | |
184 this.helperContainer.addMember(helper); | |
185 | |
186 final Canvas submit = getNextButton(); | 178 final Canvas submit = getNextButton(); |
187 final Canvas widget = createWidget(data); | 179 final Canvas widget = createWidget(data); |
188 | 180 |
189 layout.addMember(widget); | 181 layout.addMember(widget); |
190 layout.addMember(submit); | 182 layout.addMember(submit); |
191 | 183 |
192 fetchSedimentLoadData(); | 184 final IColumnClickHandler fromHandler = createHandler(this.start); |
193 | 185 final IColumnClickHandler toHandler = createHandler(this.end); |
186 | |
187 final FromToTableHelperPanel helper = new FromToTableHelperPanel(data, "epochs", this.MSG, fromHandler, toHandler); | |
188 this.validYears = helper.getKeycolEntries(); | |
189 final Canvas table = helper.getTable(); | |
190 | |
191 this.helperContainer.addMember(table); | |
194 return layout; | 192 return layout; |
195 } | 193 } |
196 | 194 |
197 private Canvas createHelper() { | 195 private IColumnClickHandler createHandler(final TextItem field) { |
198 this.sedLoadTable = new ListGrid(); | 196 final IColumnClickHandler handler = new IColumnClickHandler() { |
199 this.sedLoadTable.setShowHeaderContextMenu(false); | 197 |
200 this.sedLoadTable.setWidth100(); | |
201 this.sedLoadTable.setShowRecordComponents(true); | |
202 this.sedLoadTable.setShowRecordComponentsByCell(true); | |
203 this.sedLoadTable.setHeight100(); | |
204 this.sedLoadTable.setEmptyMessage(this.MSG.empty_table()); | |
205 this.sedLoadTable.setCanReorderFields(false); | |
206 | |
207 /* Input support pins */ | |
208 final String baseUrl = GWT.getHostPageBaseURL(); | |
209 final ListGridField pinFrom = new ListGridField("fromIcon", this.MESSAGES.from()); | |
210 pinFrom.setWidth(30); | |
211 pinFrom.setType(ListGridFieldType.ICON); | |
212 pinFrom.setCellIcon(baseUrl + this.MESSAGES.markerGreen()); | |
213 | |
214 final ListGridField pinTo = new ListGridField("toIcon", this.MESSAGES.to()); | |
215 pinTo.setType(ListGridFieldType.ICON); | |
216 pinTo.setWidth(30); | |
217 pinTo.setCellIcon(baseUrl + this.MESSAGES.markerRed()); | |
218 | |
219 pinFrom.addRecordClickHandler(new RecordClickHandler() { | |
220 @Override | 198 @Override |
221 public void onRecordClick(final RecordClickEvent e) { | 199 public void columnClicked(final String value) { |
222 final Record r = e.getRecord(); | 200 field.setValue(value); |
223 CollisionLoadEpochPanel.this.start.setValue(r.getAttribute("date")); | 201 } |
224 } | 202 }; |
225 }); | 203 |
226 | 204 return handler; |
227 pinTo.addRecordClickHandler(new RecordClickHandler() { | |
228 @Override | |
229 public void onRecordClick(final RecordClickEvent e) { | |
230 final Record r = e.getRecord(); | |
231 CollisionLoadEpochPanel.this.end.setValue(r.getAttribute("date")); | |
232 } | |
233 }); | |
234 | |
235 final ListGridField date = new ListGridField("date", this.MSG.year()); | |
236 date.setType(ListGridFieldType.TEXT); | |
237 date.setWidth(100); | |
238 | |
239 final ListGridField descr = new ListGridField("description", this.MSG.description()); | |
240 descr.setType(ListGridFieldType.TEXT); | |
241 descr.setWidth("*"); | |
242 | |
243 this.sedLoadTable.setFields(pinFrom, pinTo, date, descr); | |
244 return this.sedLoadTable; | |
245 } | 205 } |
246 | 206 |
247 @Override | 207 @Override |
248 protected Data[] getData() { | 208 protected Data[] getData() { |
249 final List<Data> data = new ArrayList<Data>(); | 209 final List<Data> data = new ArrayList<Data>(); |
260 } | 220 } |
261 | 221 |
262 final DataItem item = new DefaultDataItem("epochs", null, d); | 222 final DataItem item = new DefaultDataItem("epochs", null, d); |
263 data.add(new DefaultData("epochs", null, null, new DataItem[] { item })); | 223 data.add(new DefaultData("epochs", null, null, new DataItem[] { item })); |
264 return data.toArray(new Data[data.size()]); | 224 return data.toArray(new Data[data.size()]); |
265 } | |
266 | |
267 protected void fetchSedimentLoadData() { | |
268 final Config config = Config.getInstance(); | |
269 final String locale = config.getLocale(); | |
270 | |
271 final ArtifactDescription adescr = this.artifact.getArtifactDescription(); | |
272 final DataList[] data = adescr.getOldData(); | |
273 | |
274 final double[] km = this.artifact.getArtifactDescription().getKMRange(); | |
275 final String river = this.artifact.getArtifactDescription().getRiver(); | |
276 | |
277 String sq_ti_id = ""; | |
278 this.validYears = new ArrayList<String>(data.length); | |
279 for (final DataList element : data) { | |
280 final Data str = getData(element.getAll(), "sq_ti_id"); | |
281 if (str != null) { | |
282 final DataItem[] strItems = str.getItems(); | |
283 sq_ti_id = strItems[0].getStringValue(); | |
284 break; | |
285 } | |
286 } | |
287 | |
288 if (sq_ti_id.isEmpty()) { | |
289 GWT.log("Failed to find sq time interval id in data."); | |
290 } | |
291 | |
292 this.sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], sq_ti_id, new AsyncCallback<SedimentLoadInfoObject[]>() { | |
293 @Override | |
294 public void onFailure(final Throwable caught) { | |
295 GWT.log("Could not recieve sediment load informations."); | |
296 SC.warn(CollisionLoadEpochPanel.this.MSG.getString(caught.getMessage())); | |
297 } | |
298 | |
299 @Override | |
300 public void onSuccess(final SedimentLoadInfoObject[] sedLoad) { | |
301 final int num = sedLoad != null ? sedLoad.length : 0; | |
302 GWT.log("Recieved " + num + " sediment load informations."); | |
303 | |
304 if (num == 0) { | |
305 return; | |
306 } | |
307 | |
308 addSedimentLoadInfo(sedLoad); | |
309 } | |
310 }); | |
311 } | |
312 | |
313 protected void addSedimentLoadInfo(final SedimentLoadInfoObject[] sedLoad) { | |
314 for (final SedimentLoadInfoObject sl : sedLoad) { | |
315 final SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); | |
316 this.sedLoadTable.addData(rec); | |
317 this.validYears.add(rec.getDate()); | |
318 } | |
319 } | 225 } |
320 | 226 |
321 /* | 227 /* |
322 * Validate the epoch input. We do this here and not in an overridden | 228 * Validate the epoch input. We do this here and not in an overridden |
323 * validate method as we want to validate before an epoch is added | 229 * validate method as we want to validate before an epoch is added |