Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadEpochPanel.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/SedLoadEpochPanel.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.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.util.SC; | |
11 import com.smartgwt.client.widgets.Button; | |
12 import com.smartgwt.client.widgets.Canvas; | |
13 import com.smartgwt.client.widgets.Label; | |
14 import com.smartgwt.client.widgets.events.ClickEvent; | |
15 import com.smartgwt.client.widgets.events.ClickHandler; | |
16 import com.smartgwt.client.widgets.form.DynamicForm; | |
17 import com.smartgwt.client.widgets.form.fields.TextItem; | |
18 import com.smartgwt.client.widgets.form.validator.IsIntegerValidator; | |
19 import com.smartgwt.client.widgets.grid.ListGrid; | |
20 import com.smartgwt.client.widgets.grid.ListGridField; | |
21 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
22 import com.smartgwt.client.widgets.grid.events.RecordClickEvent; | |
23 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; | |
24 import com.smartgwt.client.widgets.layout.HLayout; | |
25 import com.smartgwt.client.widgets.layout.VLayout; | |
26 | |
27 import org.dive4elements.river.client.client.Config; | |
28 import org.dive4elements.river.client.client.services.SedimentLoadInfoService; | |
29 import org.dive4elements.river.client.client.services.SedimentLoadInfoServiceAsync; | |
30 import org.dive4elements.river.client.client.ui.AbstractUIProvider; | |
31 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
32 import org.dive4elements.river.client.shared.model.Data; | |
33 import org.dive4elements.river.client.shared.model.DataItem; | |
34 import org.dive4elements.river.client.shared.model.DataList; | |
35 import org.dive4elements.river.client.shared.model.DefaultData; | |
36 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
37 import org.dive4elements.river.client.shared.model.SedimentLoadInfoObject; | |
38 import org.dive4elements.river.client.shared.model.SedimentLoadInfoRecord; | |
39 | |
40 | |
41 public class SedLoadEpochPanel | |
42 extends AbstractUIProvider | |
43 { | |
44 protected SedimentLoadInfoServiceAsync sedLoadInfoService = | |
45 GWT.create(SedimentLoadInfoService.class); | |
46 | |
47 protected ListGrid elements; | |
48 private TextItem start; | |
49 private TextItem end; | |
50 private ListGrid sedLoadTable; | |
51 | |
52 public Canvas createWidget(DataList data) { | |
53 HLayout input = new HLayout(); | |
54 VLayout root = new VLayout(); | |
55 VLayout grid = new VLayout(); | |
56 VLayout intFields = new VLayout(); | |
57 Button add = new Button(MSG.add_date()); | |
58 elements = new ListGrid(); | |
59 | |
60 Label title = new Label(data.get(0).getDescription()); | |
61 title.setHeight("25px"); | |
62 | |
63 DynamicForm form = new DynamicForm(); | |
64 form.setNumCols(4); | |
65 start = new TextItem(MSG.from()); | |
66 start.setWidth(60); | |
67 start.setValidators(new IsIntegerValidator()); | |
68 end = new TextItem(MSG.to()); | |
69 end.setWidth(60); | |
70 end.setValidators(new IsIntegerValidator()); | |
71 form.setFields(start, end); | |
72 add.addClickHandler(new ClickHandler() { | |
73 @Override | |
74 public void onClick(ClickEvent ce) { | |
75 String v1 = start.getValueAsString(); | |
76 String v2 = end.getValueAsString(); | |
77 //TODO: better validation. | |
78 if (v1 == null || v2 == null) { | |
79 return; | |
80 } | |
81 try { | |
82 int v1i = Integer.parseInt(v1); | |
83 int v2i = Integer.parseInt(v2); | |
84 } | |
85 catch(NumberFormatException nfe) { | |
86 return; | |
87 } | |
88 Record r = new Record(); | |
89 r.setAttribute("from", v1); | |
90 r.setAttribute("to", v2); | |
91 elements.addData(r); | |
92 } | |
93 }); | |
94 | |
95 Label sel = new Label(MSG.select()); | |
96 sel.setHeight(25); | |
97 elements.setWidth(185); | |
98 elements.setHeight(120); | |
99 elements.setShowHeaderContextMenu(false); | |
100 elements.setCanReorderFields(false); | |
101 elements.setCanSort(false); | |
102 elements.setCanEdit(false); | |
103 ListGridField from = new ListGridField("from", MSG.from()); | |
104 ListGridField to = new ListGridField("to", MSG.to()); | |
105 from.setWidth(70); | |
106 to.setWidth(70); | |
107 | |
108 final ListGridField removeField = | |
109 new ListGridField("_removeRecord", "Remove Record"){{ | |
110 setType(ListGridFieldType.ICON); | |
111 setIcon(GWT.getHostPageBaseURL() + MSG.removeFeature()); | |
112 setCanEdit(false); | |
113 setCanFilter(false); | |
114 setCanSort(false); | |
115 setCanGroupBy(false); | |
116 setCanFreeze(false); | |
117 setWidth(25); | |
118 }}; | |
119 | |
120 elements.addRecordClickHandler(new RecordClickHandler() { | |
121 @Override | |
122 public void onRecordClick(final RecordClickEvent event) { | |
123 // Just handle remove-clicks | |
124 if(!event.getField().getName().equals(removeField.getName())) { | |
125 return; | |
126 } | |
127 event.getViewer().removeData(event.getRecord()); | |
128 } | |
129 }); | |
130 | |
131 elements.setFields(from, to, removeField); | |
132 | |
133 intFields.addMember(form); | |
134 intFields.addMember(add); | |
135 grid.addMember(sel); | |
136 grid.addMember(elements); | |
137 input.addMember(intFields); | |
138 input.addMember(grid); | |
139 root.addMember(title); | |
140 root.addMember(input); | |
141 | |
142 return root; | |
143 } | |
144 | |
145 @Override | |
146 public Canvas createOld(DataList dataList) { | |
147 HLayout layout = new HLayout(); | |
148 layout.setWidth("400px"); | |
149 VLayout vLayout = new VLayout(); | |
150 vLayout.setWidth(130); | |
151 Label label = new Label(dataList.getLabel()); | |
152 label.setWidth("200px"); | |
153 label.setHeight(25); | |
154 | |
155 List<Data> items = dataList.getAll(); | |
156 Data str = getData(items, "epochs"); | |
157 DataItem[] strItems = str.getItems(); | |
158 | |
159 String[] pairs = strItems[0].getLabel().split(";"); | |
160 for (int i = 0; i < pairs.length; i++) { | |
161 String[] vals = pairs[i].split(","); | |
162 Label dateLabel = new Label(vals[0] + " - " + vals[1]); | |
163 dateLabel.setHeight(20); | |
164 vLayout.addMember(dateLabel); | |
165 } | |
166 Canvas back = getBackButton(dataList.getState()); | |
167 layout.addMember(label); | |
168 layout.addMember(vLayout); | |
169 layout.addMember(back); | |
170 | |
171 return layout; | |
172 } | |
173 | |
174 @Override | |
175 public Canvas create(DataList data) { | |
176 VLayout layout = new VLayout(); | |
177 Canvas helper = createHelper(); | |
178 this.helperContainer.addMember(helper); | |
179 | |
180 Canvas submit = getNextButton(); | |
181 Canvas widget = createWidget(data); | |
182 | |
183 layout.addMember(widget); | |
184 layout.addMember(submit); | |
185 | |
186 fetchSedimentLoadData(); | |
187 | |
188 return layout; | |
189 } | |
190 | |
191 private Canvas createHelper() { | |
192 sedLoadTable = new ListGrid(); | |
193 sedLoadTable.setShowHeaderContextMenu(false); | |
194 sedLoadTable.setWidth100(); | |
195 sedLoadTable.setShowRecordComponents(true); | |
196 sedLoadTable.setShowRecordComponentsByCell(true); | |
197 sedLoadTable.setHeight100(); | |
198 sedLoadTable.setEmptyMessage(MSG.empty_table()); | |
199 sedLoadTable.setCanReorderFields(false); | |
200 | |
201 ListGridField date = new ListGridField("date", MSG.year()); | |
202 date.setType(ListGridFieldType.TEXT); | |
203 date.setWidth(100); | |
204 | |
205 ListGridField descr = | |
206 new ListGridField("description", MSG.description()); | |
207 descr.setType(ListGridFieldType.TEXT); | |
208 descr.setWidth("*"); | |
209 | |
210 sedLoadTable.setFields(date, descr); | |
211 return sedLoadTable; | |
212 } | |
213 | |
214 @Override | |
215 protected Data[] getData() { | |
216 List<Data> data = new ArrayList<Data>(); | |
217 | |
218 ListGridRecord[] lgr = elements.getRecords(); | |
219 if (lgr.length == 0) { | |
220 return new Data[0]; | |
221 } | |
222 String d = ""; | |
223 for (int i = 0; i < lgr.length; i++) { | |
224 Record r = (Record) lgr[i]; | |
225 d += r.getAttribute("from") + "," + r.getAttribute("to"); | |
226 d += ";"; | |
227 } | |
228 | |
229 DataItem item = new DefaultDataItem("epochs", null, d); | |
230 data.add(new DefaultData( | |
231 "epochs", | |
232 null, | |
233 null, | |
234 new DataItem[] { item })); | |
235 return data.toArray(new Data[data.size()]); | |
236 } | |
237 | |
238 protected void fetchSedimentLoadData() { | |
239 Config config = Config.getInstance(); | |
240 String locale = config.getLocale (); | |
241 | |
242 ArtifactDescription adescr = artifact.getArtifactDescription(); | |
243 DataList[] data = adescr.getOldData(); | |
244 | |
245 double[] km = artifact.getArtifactDescription().getKMRange(); | |
246 String river = artifact.getArtifactDescription().getRiver(); | |
247 | |
248 sedLoadInfoService.getSedimentLoadInfo(locale, river, "single", km[0], km[1], | |
249 new AsyncCallback<SedimentLoadInfoObject[]>() { | |
250 public void onFailure(Throwable caught) { | |
251 GWT.log("Could not recieve sediment load informations."); | |
252 SC.warn(caught.getMessage()); | |
253 } | |
254 | |
255 public void onSuccess(SedimentLoadInfoObject[] sedLoad) { | |
256 int num = sedLoad != null ? sedLoad.length :0; | |
257 GWT.log("Recieved " + num + " sediment load informations."); | |
258 | |
259 if (num == 0) { | |
260 return; | |
261 } | |
262 | |
263 addSedimentLoadInfo(sedLoad); | |
264 } | |
265 } | |
266 ); | |
267 } | |
268 | |
269 | |
270 protected void addSedimentLoadInfo (SedimentLoadInfoObject[] sedLoad) { | |
271 for(SedimentLoadInfoObject sl: sedLoad) { | |
272 SedimentLoadInfoRecord rec = new SedimentLoadInfoRecord(sl); | |
273 sedLoadTable.addData(rec); | |
274 } | |
275 } | |
276 | |
277 } |