Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java @ 256:5e1c1b7d6516
Added table and service for calculation output to UI.
flys-client/trunk@1868 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 09 May 2011 14:29:53 +0000 |
parents | |
children | 50a95db68e66 |
comparison
equal
deleted
inserted
replaced
255:e4f0bef52689 | 256:5e1c1b7d6516 |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import java.util.List; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 import com.google.gwt.user.client.rpc.AsyncCallback; | |
7 | |
8 import com.smartgwt.client.widgets.Canvas; | |
9 import com.smartgwt.client.widgets.Label; | |
10 import com.smartgwt.client.widgets.layout.VLayout; | |
11 import com.smartgwt.client.widgets.grid.ListGrid; | |
12 import com.smartgwt.client.widgets.grid.ListGridField; | |
13 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
14 | |
15 import de.intevation.flys.client.shared.model.DataList; | |
16 | |
17 import de.intevation.flys.client.client.FLYSConstants; | |
18 import de.intevation.flys.client.client.Config; | |
19 | |
20 import de.intevation.flys.client.client.services.CSVExportService; | |
21 import de.intevation.flys.client.client.services.CSVExportServiceAsync; | |
22 | |
23 /** | |
24 * This UIProvider creates a widget that displays calculated data in a table. | |
25 * | |
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
27 */ | |
28 public class TableDataPanel | |
29 { | |
30 /** The message class that provides i18n strings.*/ | |
31 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | |
32 | |
33 /** The DistanceInfoService used to retrieve locations about rivers.*/ | |
34 protected CSVExportServiceAsync exportService = | |
35 GWT.create(CSVExportService.class); | |
36 | |
37 /** A container that will contain the location or the distance panel.*/ | |
38 protected VLayout container; | |
39 | |
40 /** The export type.*/ | |
41 protected String name; | |
42 | |
43 /** The UUID of the collection */ | |
44 protected String uuid; | |
45 | |
46 /** The table*/ | |
47 protected ListGrid dataTable; | |
48 | |
49 | |
50 /** | |
51 * Creates a new LocationDistancePanel instance. | |
52 */ | |
53 public TableDataPanel() { | |
54 container = new VLayout(); | |
55 dataTable = new ListGrid(); | |
56 name = ""; | |
57 } | |
58 | |
59 | |
60 /** | |
61 * This method creates a widget that contains a table | |
62 * | |
63 * @param data The data that might be inserted.//Use this? | |
64 * | |
65 * @return a panel. | |
66 */ | |
67 public Canvas create() { | |
68 Config config = Config.getInstance(); | |
69 String url = config.getServerUrl(); | |
70 String locale = config.getLocale (); | |
71 ListGridField flusskm = new ListGridField("km", MESSAGES.river_km()); | |
72 ListGridField w = new ListGridField("w", MESSAGES.unitWNN()); | |
73 ListGridField q = new ListGridField("q", MESSAGES.wqQ()); | |
74 ListGridField desc = new ListGridField("descr", MESSAGES.description()); | |
75 | |
76 dataTable.setFields(flusskm, w, q, desc); | |
77 exportService.getCSV(url, locale, uuid, name, | |
78 new AsyncCallback<List>() { | |
79 public void onFailure(Throwable caught) { | |
80 GWT.log("Could not recieve csv."); | |
81 GWT.log(caught.getMessage()); | |
82 } | |
83 | |
84 public void onSuccess(List l) { | |
85 GWT.log("Recieved csv with " + l.size() + " lines."); | |
86 setData(l); | |
87 } | |
88 } | |
89 ); | |
90 | |
91 Label l = new Label (MESSAGES.calcTableTitle()); | |
92 l.setHeight(20); | |
93 | |
94 container.addMember(l); | |
95 container.addMember(dataTable); | |
96 | |
97 return container; | |
98 } | |
99 | |
100 | |
101 public void setName(String name) { | |
102 this.name = name; | |
103 } | |
104 | |
105 public void setUuid(String uuid) { | |
106 this.uuid = uuid; | |
107 } | |
108 | |
109 | |
110 public Canvas createOld(DataList dataList) { | |
111 return null; | |
112 } | |
113 | |
114 | |
115 protected Canvas createWidget(DataList data) { | |
116 return null; | |
117 } | |
118 | |
119 public void setData(List list){ | |
120 for(Object item: list) { | |
121 String[] sItem = (String[])item; | |
122 ListGridRecord r = new ListGridRecord(); | |
123 if (sItem.length == 3) { | |
124 r.setAttribute("km", sItem[0]); | |
125 r.setAttribute("w", sItem[1]); | |
126 r.setAttribute("q", sItem[2]); | |
127 } | |
128 dataTable.addData(r); | |
129 } | |
130 } | |
131 } | |
132 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |