Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadOffEpochPanel.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/minfo/SedLoadOffEpochPanel.java@abd304085bd4 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.minfo; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import com.google.gwt.core.client.GWT; | |
7 import com.google.gwt.user.client.rpc.AsyncCallback; | |
8 import com.smartgwt.client.data.Record; | |
9 import com.smartgwt.client.types.ListGridFieldType; | |
10 import com.smartgwt.client.types.SelectionAppearance; | |
11 import com.smartgwt.client.util.SC; | |
12 import com.smartgwt.client.widgets.Canvas; | |
13 import com.smartgwt.client.widgets.Label; | |
14 import com.smartgwt.client.widgets.grid.ListGrid; | |
15 import com.smartgwt.client.widgets.grid.ListGridField; | |
16 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
17 import com.smartgwt.client.widgets.layout.HLayout; | |
18 import com.smartgwt.client.widgets.layout.VLayout; | |
19 | |
20 import de.intevation.flys.client.client.Config; | |
21 import de.intevation.flys.client.client.services.SedimentLoadInfoService; | |
22 import de.intevation.flys.client.client.services.SedimentLoadInfoServiceAsync; | |
23 import de.intevation.flys.client.client.ui.PeriodPanel; | |
24 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
25 import de.intevation.flys.client.shared.model.Data; | |
26 import de.intevation.flys.client.shared.model.DataItem; | |
27 import de.intevation.flys.client.shared.model.DataList; | |
28 import de.intevation.flys.client.shared.model.DefaultData; | |
29 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
30 import de.intevation.flys.client.shared.model.SedimentLoadInfoObject; | |
31 import de.intevation.flys.client.shared.model.SedimentLoadInfoRecord; | |
32 | |
33 | |
34 public class SedLoadOffEpochPanel | |
35 extends PeriodPanel | |
36 { | |
37 protected SedimentLoadInfoServiceAsync sedLoadInfoService = | |
38 GWT.create(SedimentLoadInfoService.class); | |
39 | |
40 private ListGrid sedLoadTable; | |
41 | |
42 public Canvas createWidget(DataList data) { | |
43 VLayout root = new VLayout(); | |
44 | |
45 Label title = new Label(data.get(0).getDescription()); | |
46 title.setHeight("25px"); | |
47 | |
48 root.addMember(title); | |
49 | |
50 return root; | |
51 } | |
52 | |
53 @Override | |
54 public Canvas createOld(DataList dataList) { | |
55 HLayout layout = new HLayout(); | |
56 layout.setWidth("400px"); | |
57 VLayout vLayout = new VLayout(); | |
58 vLayout.setWidth(130); | |
59 Label label = new Label(dataList.getLabel()); | |
60 label.setWidth("200px"); | |
61 label.setHeight(25); | |
62 | |
63 List<Data> items = dataList.getAll(); | |
64 Data str = getData(items, "epochs"); | |
65 DataItem[] strItems = str.getItems(); | |
66 | |
67 String[] pairs = strItems[0].getLabel().split(";"); | |
68 for (int i = 0; i < pairs.length; i++) { | |
69 String[] vals = pairs[i].split(","); | |
70 Label dateLabel = new Label(vals[0] + " - " + vals[1]); | |
71 dateLabel.setHeight(20); | |
72 vLayout.addMember(dateLabel); | |
73 } | |
74 Canvas back = getBackButton(dataList.getState()); | |
75 layout.addMember(label); | |
76 layout.addMember(vLayout); | |
77 layout.addMember(back); | |
78 | |
79 return layout; | |
80 } | |
81 | |
82 @Override | |
83 public Canvas create(DataList data) { | |
84 VLayout layout = new VLayout(); | |
85 Canvas helper = createHelper(); | |
86 this.helperContainer.addMember(helper); | |
87 | |
88 Canvas submit = getNextButton(); | |
89 Canvas widget = createWidget(data); | |
90 | |
91 layout.addMember(widget); | |
92 layout.addMember(submit); | |
93 | |
94 fetchSedimentLoadData(); | |
95 | |
96 return layout; | |
97 } | |
98 | |
99 protected Canvas createHelper() { | |
100 sedLoadTable = new ListGrid(); | |
101 sedLoadTable.setShowHeaderContextMenu(false); | |
102 sedLoadTable.setWidth100(); | |
103 sedLoadTable.setShowRecordComponents(true); | |
104 sedLoadTable.setShowRecordComponentsByCell(true); | |
105 sedLoadTable.setHeight100(); | |
106 sedLoadTable.setEmptyMessage(MSG.empty_table()); | |
107 sedLoadTable.setCanReorderFields(false); | |
108 sedLoadTable.setSelectionAppearance(SelectionAppearance.CHECKBOX); | |
109 | |
110 ListGridField date = new ListGridField("date", MSG.year()); | |
111 date.setType(ListGridFieldType.TEXT); | |
112 date.setWidth(100); | |
113 | |
114 ListGridField descr = | |
115 new ListGridField("description", MSG.description()); | |
116 descr.setType(ListGridFieldType.TEXT); | |
117 descr.setWidth("*"); | |
118 | |
119 sedLoadTable.setFields(date, descr); | |
120 return sedLoadTable; | |
121 } | |
122 | |
123 @Override | |
124 public Data[] getData() { | |
125 List<Data> data = new ArrayList<Data>(); | |
126 | |
127 ListGridRecord[] lgr = sedLoadTable.getSelectedRecords(); | |
128 if (lgr.length == 0) { | |
129 return new Data[0]; | |
130 } | |
131 String d = ""; | |
132 for (int i = 0; i < lgr.length; i++) { | |
133 Record r = (Record) lgr[i]; | |
134 String date = r.getAttribute("date"); | |
135 String[] range = date.split(" - "); | |
136 d += range[0] + "," + range[1]; | |
137 d += ";"; | |
138 } | |
139 DataItem item = new DefaultDataItem("epochs", null, d); | |
140 data.add(new DefaultData( | |
141 "epochs", | |
142 null, | |
143 null, | |
144 new DataItem[] { item })); | |
145 return data.toArray(new Data[data.size()]); | |
146 } | |
147 | |
148 protected void fetchSedimentLoadData() { | |
149 Config config = Config.getInstance(); | |
150 String locale = config.getLocale (); | |
151 | |
152 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
153 DataList[] data = adescr.getOldData(); | |
154 | |
155 double[] km = artifact.getArtifactDescription().getKMRange(); | |
156 String river = artifact.getArtifactDescription().getRiver(); | |
157 | |
158 sedLoadInfoService.getSedimentLoadInfo(locale, river, "epoch", km[0], km[1], | |
159 new AsyncCallback<SedimentLoadInfoObject[]>() { | |
160 public void onFailure(Throwable caught) { | |
161 GWT.log("Could not recieve sediment load informations."); | |
162 SC.warn(caught.getMessage()); | |
163 } | |
164 | |
165 public void onSuccess(SedimentLoadInfoObject[] sedLoad) { | |
166 int num = sedLoad != null ? sedLoad.length :0; | |
167 GWT.log("Recieved " + num + " sediment load informations."); | |
168 | |
169 if (num == 0) { | |
170 return; | |
171 } | |
172 | |
173 addSedimentLoadInfo(sedLoad); | |
174 } | |
175 } | |
176 ); | |
177 } | |
178 | |
179 | |
180 protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { | |
181 for(SedimentLoadInfoObject sl: sedLoad) { | |
182 SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); | |
183 sedLoadTable.addData(rec); | |
184 } | |
185 } | |
186 | |
187 } |