Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadSQTiPanel.java @ 8231:dded480e17c9
(issue1448) Add Panel for new sq_ti_select state
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 08 Sep 2014 16:24:16 +0200 |
parents | |
children | b6371be363b1 |
comparison
equal
deleted
inserted
replaced
8230:f54c4b858213 | 8231:dded480e17c9 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.client.client.ui.minfo; | |
10 | |
11 import java.util.ArrayList; | |
12 import java.util.List; | |
13 | |
14 import com.google.gwt.core.client.GWT; | |
15 import com.google.gwt.user.client.rpc.AsyncCallback; | |
16 import com.smartgwt.client.data.Record; | |
17 import com.smartgwt.client.types.ListGridFieldType; | |
18 import com.smartgwt.client.types.SelectionAppearance; | |
19 import com.smartgwt.client.types.SelectionStyle; | |
20 import com.smartgwt.client.util.SC; | |
21 import com.smartgwt.client.widgets.Canvas; | |
22 import com.smartgwt.client.widgets.Label; | |
23 import com.smartgwt.client.widgets.grid.ListGrid; | |
24 import com.smartgwt.client.widgets.grid.ListGridField; | |
25 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
26 import com.smartgwt.client.widgets.layout.HLayout; | |
27 import com.smartgwt.client.widgets.layout.VLayout; | |
28 | |
29 import org.dive4elements.river.client.client.Config; | |
30 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; | |
31 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; | |
32 import org.dive4elements.river.client.client.ui.PeriodPanel; | |
33 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
34 import org.dive4elements.river.client.shared.model.Data; | |
35 import org.dive4elements.river.client.shared.model.DataItem; | |
36 import org.dive4elements.river.client.shared.model.DataList; | |
37 import org.dive4elements.river.client.shared.model.DefaultData; | |
38 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
39 import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; | |
40 import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; | |
41 | |
42 /** Show input to select an official epoch. */ | |
43 public class SedLoadSQTiPanel | |
44 extends SedLoadOffEpochPanel | |
45 { | |
46 /** Creates the helper grid in which off epochs can be selected. */ | |
47 @Override | |
48 protected Canvas createHelper() { | |
49 sedLoadTable = new ListGrid(); | |
50 sedLoadTable.setShowHeaderContextMenu(false); | |
51 sedLoadTable.setWidth100(); | |
52 sedLoadTable.setShowRecordComponents(true); | |
53 sedLoadTable.setShowRecordComponentsByCell(true); | |
54 sedLoadTable.setHeight100(); | |
55 sedLoadTable.setEmptyMessage(MSG.empty_table()); | |
56 sedLoadTable.setCanReorderFields(false); | |
57 sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX); | |
58 sedLoadTable.setSelectionType(SelectionStyle.SINGLE); | |
59 | |
60 ListGridField date = new ListGridField("sq_date", MSG.year()); | |
61 date.setType(ListGridFieldType.TEXT); | |
62 date.setWidth(100); | |
63 | |
64 sedLoadTable.setFields(date); | |
65 return sedLoadTable; | |
66 } | |
67 | |
68 /** Get data via listgrid selection. */ | |
69 @Override | |
70 public Data[] getData() { | |
71 List<Data> data = new ArrayList<Data>(); | |
72 | |
73 ListGridRecord[] lgr = sedLoadTable.getSelectedRecords(); | |
74 if (lgr.length == 0) { | |
75 GWT.log("returning empty data."); | |
76 return new Data[0]; | |
77 } | |
78 String d = ""; | |
79 for (int i = 0; i < lgr.length; i++) { | |
80 /* Should only be one item as this is single selection */ | |
81 Record r = (Record) lgr[i]; | |
82 d = r.getAttribute("sq_ti_id"); | |
83 GWT.log("Got attribute sq_ti_id : " + d); | |
84 } | |
85 DataItem item = new DefaultDataItem("sq_ti_id", "sq_ti_id", d); | |
86 data.add(new DefaultData( | |
87 "sq_ti_id", | |
88 null, | |
89 null, | |
90 new DataItem[] { item })); | |
91 return data.toArray(new Data[data.size()]); | |
92 } | |
93 | |
94 /** Fetch load info from service and populate table. */ | |
95 @Override | |
96 protected void fetchSedimentLoadData() { | |
97 Config config = Config.getInstance(); | |
98 String locale = config.getLocale (); | |
99 | |
100 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
101 DataList[] data = adescr.getOldData(); | |
102 | |
103 double[] km = artifact.getArtifactDescription().getKMRange(); | |
104 String river = artifact.getArtifactDescription().getRiver(); | |
105 | |
106 sedLoadInfoService.getSedimentLoadInfo(locale, river, "sq_time_intervals", km[0], km[1], "", | |
107 new AsyncCallback<SedimentLoadInfoObject[]>() { | |
108 public void onFailure(Throwable caught) { | |
109 GWT.log("Could not receive sediment load informations."); | |
110 SC.warn(caught.getMessage()); | |
111 } | |
112 | |
113 public void onSuccess(SedimentLoadInfoObject[] sedLoad) { | |
114 int num = sedLoad != null ? sedLoad.length :0; | |
115 GWT.log("Received " + num + " sediment load informations."); | |
116 | |
117 if (num == 0) { | |
118 return; | |
119 } | |
120 | |
121 addSedimentLoadInfo(sedLoad); | |
122 } | |
123 } | |
124 ); | |
125 } | |
126 } | |
127 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |