comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.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/TableDataPanel.java@03de5c424f95
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.client.client.ui;
2
3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.i18n.client.NumberFormat;
5 import com.google.gwt.user.client.rpc.AsyncCallback;
6
7 import com.smartgwt.client.types.ListGridFieldType;
8 import com.smartgwt.client.util.SC;
9 import com.smartgwt.client.widgets.Canvas;
10 import com.smartgwt.client.widgets.grid.ListGrid;
11 import com.smartgwt.client.widgets.grid.ListGridField;
12 import com.smartgwt.client.widgets.grid.ListGridRecord;
13 import com.smartgwt.client.widgets.layout.VLayout;
14
15 import de.intevation.flys.client.client.Config;
16 import de.intevation.flys.client.client.FLYSConstants;
17 import de.intevation.flys.client.client.services.CSVExportService;
18 import de.intevation.flys.client.client.services.CSVExportServiceAsync;
19 import de.intevation.flys.client.shared.model.DataList;
20
21 import java.util.List;
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 protected CSVExportServiceAsync exportService =
34 GWT.create(CSVExportService.class);
35
36 /** A container that will contain the location or the distance panel. */
37 protected VLayout container;
38
39 /** The export type. */
40 protected String name;
41
42 /** The UUID of the collection. */
43 protected String uuid;
44
45 /** The table. */
46 protected ListGrid dataTable;
47
48
49 /**
50 * Creates a new LocationDistancePanel instance.
51 */
52 public TableDataPanel() {
53 container = new VLayout();
54 dataTable = new ListGrid();
55 name = "";
56 }
57
58
59 /**
60 * This method creates a widget that contains a table.
61 *
62 * @return a panel.
63 */
64 public Canvas create() {
65 Config config = Config.getInstance();
66 String locale = config.getLocale ();
67 dataTable.setEmptyMessage(MESSAGES.empty_table());
68 dataTable.setShowHeaderContextMenu(false);
69 dataTable.setCanDragSelectText(true);
70
71 exportService.getCSV(locale, uuid, name,
72 new AsyncCallback<List<String[]>>() {
73 @Override
74 public void onFailure(Throwable caught) {
75 GWT.log("Could not recieve csv.");
76 SC.warn(caught.getMessage());
77 }
78
79 @Override
80 public void onSuccess(List<String[]> l) {
81 GWT.log("Recieved csv with " + l.size() + " lines.");
82 setData(l);
83 }
84 }
85 );
86
87 container.addMember(dataTable);
88
89 return container;
90 }
91
92
93 public void setName(String name) {
94 this.name = name;
95 }
96
97 public void setUuid(String uuid) {
98 this.uuid = uuid;
99 }
100
101
102 public Canvas createOld(DataList dataList) {
103 return null;
104 }
105
106
107 protected Canvas createWidget(DataList data) {
108 return null;
109 }
110
111
112 /**
113 * This method sets the data to a dynamic table.
114 *
115 * @param list List if String[] containing the data.
116 */
117 public void setData(List<String[]> list) {
118 if (list == null || list.size() < 2) {
119 dataTable.setEmptyMessage(MESSAGES.error_no_calc_result());
120 dataTable.redraw();
121 return;
122 }
123
124 Config config = Config.getInstance();
125 String locale = config.getLocale();
126
127 NumberFormat nf;
128 if (locale.equals("de")) {
129 nf = NumberFormat.getFormat("#,##");
130 }
131 else {
132 nf = NumberFormat.getFormat("#.##");
133 }
134
135 String[] header = list.get(0);
136 String[] firstValues = list.get(1);
137
138 ListGridField[] fields = new ListGridField[header.length];
139
140 for(int i = 0; i < header.length; i++) {
141 ListGridField f = new ListGridField(String.valueOf(i));
142 fields[i] = f;
143 f.setTitle(header[i]);
144
145 try {
146 nf.parse(firstValues[i]);
147 f.setType(ListGridFieldType.FLOAT);
148 }
149 catch (NumberFormatException nfe) {
150 f.setType(ListGridFieldType.TEXT);
151 }
152 }
153
154 dataTable.setFields(fields);
155
156 for(int i = 1; i < list.size(); i++) {
157 String[] sItem = list.get(i);
158 ListGridRecord r = new ListGridRecord();
159 for(int j = 0; j < sItem.length; j++) {
160 r.setAttribute(String.valueOf(j), sItem[j]);
161 }
162 dataTable.addData(r);
163 }
164 }
165 }
166 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org