comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/stationinfo/GaugeListGrid.java @ 8303:519023ce3500

Updated the client to build a default artifact for gauge discharge curve. * Removed code for special gauge discharge artifact * Updated GaugeListGrid in info panel to create a the new project * Updated i18n
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 22 Sep 2014 17:08:48 +0200
parents f7f86f4e4c8d
children 5e38e2924c07
comparison
equal deleted inserted replaced
8302:8578babdb2c8 8303:519023ce3500
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 com.google.gwt.core.client.GWT; 14 import com.google.gwt.core.client.GWT;
15 import com.google.gwt.user.client.rpc.AsyncCallback;
16 import com.smartgwt.client.util.SC;
15 import com.smartgwt.client.widgets.Canvas; 17 import com.smartgwt.client.widgets.Canvas;
16 import com.smartgwt.client.widgets.grid.ListGridField; 18 import com.smartgwt.client.widgets.grid.ListGridField;
17 import com.smartgwt.client.widgets.grid.ListGridRecord; 19 import com.smartgwt.client.widgets.grid.ListGridRecord;
18 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; 20 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
19 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; 21 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
20 22
23 import org.dive4elements.river.client.client.Config;
21 import org.dive4elements.river.client.client.FLYS; 24 import org.dive4elements.river.client.client.FLYS;
25 import org.dive4elements.river.client.client.services.AdvanceService;
26 import org.dive4elements.river.client.client.services.AdvanceServiceAsync;
27 import org.dive4elements.river.client.client.services.ArtifactService;
28 import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
29 import org.dive4elements.river.client.client.services.CreateCollectionService;
30 import org.dive4elements.river.client.client.services.CreateCollectionServiceAsync;
31 import org.dive4elements.river.client.client.services.StepForwardService;
32 import org.dive4elements.river.client.client.services.StepForwardServiceAsync;
33 import org.dive4elements.river.client.client.ui.CollectionView;
34 import org.dive4elements.river.client.shared.model.Artifact;
35 import org.dive4elements.river.client.shared.model.Collection;
22 import org.dive4elements.river.client.shared.model.Data; 36 import org.dive4elements.river.client.shared.model.Data;
23 import org.dive4elements.river.client.shared.model.DataItem; 37 import org.dive4elements.river.client.shared.model.DataItem;
24 import org.dive4elements.river.client.shared.model.DataList; 38 import org.dive4elements.river.client.shared.model.DataList;
39 import org.dive4elements.river.client.shared.model.DefaultData;
40 import org.dive4elements.river.client.shared.model.DefaultDataItem;
25 import org.dive4elements.river.client.shared.model.GaugeInfo; 41 import org.dive4elements.river.client.shared.model.GaugeInfo;
26 import org.dive4elements.river.client.shared.model.RiverInfo; 42 import org.dive4elements.river.client.shared.model.RiverInfo;
27 43
28 44
29 /** 45 /**
30 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> 46 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
31 */ 47 */
32 public class GaugeListGrid extends InfoListGrid implements RecordClickHandler { 48 public class GaugeListGrid extends InfoListGrid implements RecordClickHandler {
33 49
34 private static final int ABFLUSSTAFEL_COLUMN = 6; 50 private static final int ABFLUSSTAFEL_COLUMN = 6;
51
52 /** The ArtifactService used to communicate with the Artifact server. */
53 protected ArtifactServiceAsync artifactService =
54 GWT.create(ArtifactService.class);
55
56 /** The StepForwardService used to put data into an existing artifact. */
57 protected StepForwardServiceAsync forwardService =
58 GWT.create(StepForwardService.class);
59
60 /** The ArtifactService used to communicate with the Artifact server. */
61 protected CreateCollectionServiceAsync createCollectionService =
62 GWT.create(CreateCollectionService.class);
63
64 /** The StepForwardService used to put data into an existing artifact. */
65 protected AdvanceServiceAsync advanceService =
66 GWT.create(AdvanceService.class);
35 67
36 public GaugeListGrid(FLYS flys) { 68 public GaugeListGrid(FLYS flys) {
37 super(flys); 69 super(flys);
38 //TODO i18n!!! 70 //TODO i18n!!!
39 ListGridField nfield = new ListGridField("name", "Pegel"); 71 ListGridField nfield = new ListGridField("name", "Pegel");
310 * When clicked on the gauge discharge link, open new Gauge Discharge 342 * When clicked on the gauge discharge link, open new Gauge Discharge
311 * Curve view. 343 * Curve view.
312 */ 344 */
313 @Override 345 @Override
314 public void onRecordClick(RecordClickEvent event) { 346 public void onRecordClick(RecordClickEvent event) {
315 GaugeRecord gauge = (GaugeRecord)event.getRecord(); 347 final GaugeRecord gauge = (GaugeRecord)event.getRecord();
316 flys.newGaugeDischargeCurve(gauge.getRiverName(), 348 Config config = Config.getInstance();
317 gauge.getOfficialNumber()); 349 final String locale = config.getLocale();
350 createCollectionService.create(
351 locale,
352 flys.getCurrentUser().identifier(),
353 new AsyncCallback<Collection>() {
354 @Override
355 public void onFailure(Throwable caught) {
356 GWT.log("Could not create the new collection.");
357 SC.warn(FLYS.getExceptionString(MSG, caught));
358 }
359
360 @Override
361 public void onSuccess(Collection collection) {
362 GWT.log("Successfully created a new collection.");
363 createArtifact(collection, locale, gauge);
364 }
365 }
366 );
367 }
368
369 private void createArtifact(
370 final Collection collection,
371 final String locale,
372 final GaugeRecord gauge
373 ) {
374 artifactService.create(
375 locale, "gaugedischargecurve", null,
376 new AsyncCallback<Artifact>() {
377 @Override
378 public void onFailure(Throwable caught) {
379 GWT.log("Could not create the new artifact.");
380 SC.warn(FLYS.getExceptionString(MSG, caught));
381 }
382
383 @Override
384 public void onSuccess(Artifact artifact) {
385 GWT.log("Successfully created a new artifact.");
386
387 DataItem riverItem = new DefaultDataItem(
388 "river",
389 "river",
390 gauge.getRiverName());
391 Data river = new DefaultData(
392 "river",
393 null,
394 null,
395 new DataItem[]{riverItem});
396
397 DataItem refItem = new DefaultDataItem(
398 "reference_gauge",
399 "reference_gauge",
400 gauge.getOfficialNumber().toString());
401 Data ref = new DefaultData(
402 "reference_gauge",
403 null,
404 null,
405 new DataItem[]{refItem});
406
407 DataItem locItem = new DefaultDataItem(
408 "ld_locations",
409 "ld_locations",
410 gauge.getStation().toString());
411 Data loc = new DefaultData(
412 "ld_locations",
413 null,
414 null,
415 new DataItem[]{locItem});
416
417 DataItem nameItem = new DefaultDataItem(
418 "gauge_name",
419 "gauge_name",
420 gauge.getName());
421 Data name = new DefaultData(
422 "gauge_name",
423 null,
424 null,
425 new DataItem[]{nameItem});
426
427 Data[] data = new Data[]{river, ref, loc, name};
428 forwardService.go(locale, artifact, data,
429 new AsyncCallback<Artifact>() {
430 @Override
431 public void onFailure(Throwable caught) {
432 GWT.log("Could not feed the artifact.");
433 SC.warn(caught.getMessage());
434 }
435
436 @Override
437 public void onSuccess(Artifact artifact) {
438 GWT.log("Successfully feed the artifact.");
439 CollectionView view = new CollectionView(
440 flys,
441 collection,
442 artifact);
443 flys.getWorkspace().addView(
444 collection.identifier(),
445 view);
446 view.addArtifactToCollection(artifact);
447 }
448 });
449 }
450 });
318 } 451 }
319 452
320 @Override 453 @Override
321 public String getCellCSSText(ListGridRecord record, int rowNum, 454 public String getCellCSSText(ListGridRecord record, int rowNum,
322 int colNum) { 455 int colNum) {

http://dive4elements.wald.intevation.org