Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java @ 9064:28c50f5efceb
work on uinfo-vegetation-zones table
author | gernotbelger |
---|---|
date | Wed, 09 May 2018 16:31:12 +0200 |
parents | 5533aa8f8b73 |
children | cb3a91dc4e3b |
comparison
equal
deleted
inserted
replaced
9063:b6919e3c2d86 | 9064:28c50f5efceb |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.client.ui; | 9 package org.dive4elements.river.client.client.ui; |
10 | 10 |
11 import java.util.List; | |
12 | |
13 import org.dive4elements.river.client.client.Config; | |
14 import org.dive4elements.river.client.client.FLYSConstants; | |
15 import org.dive4elements.river.client.client.services.CSVExportService; | |
16 import org.dive4elements.river.client.client.services.CSVExportServiceAsync; | |
17 import org.dive4elements.river.client.shared.model.DataList; | |
18 | |
11 import com.google.gwt.core.client.GWT; | 19 import com.google.gwt.core.client.GWT; |
12 import com.google.gwt.i18n.client.NumberFormat; | 20 import com.google.gwt.i18n.client.NumberFormat; |
13 import com.google.gwt.user.client.rpc.AsyncCallback; | 21 import com.google.gwt.user.client.rpc.AsyncCallback; |
14 | |
15 import com.smartgwt.client.types.ListGridFieldType; | 22 import com.smartgwt.client.types.ListGridFieldType; |
16 import com.smartgwt.client.util.SC; | 23 import com.smartgwt.client.util.SC; |
17 import com.smartgwt.client.widgets.Canvas; | 24 import com.smartgwt.client.widgets.Canvas; |
18 import com.smartgwt.client.widgets.grid.ListGrid; | 25 import com.smartgwt.client.widgets.grid.ListGrid; |
19 import com.smartgwt.client.widgets.grid.ListGridField; | 26 import com.smartgwt.client.widgets.grid.ListGridField; |
20 import com.smartgwt.client.widgets.grid.ListGridRecord; | 27 import com.smartgwt.client.widgets.grid.ListGridRecord; |
21 import com.smartgwt.client.widgets.layout.VLayout; | 28 import com.smartgwt.client.widgets.layout.VLayout; |
22 | 29 |
23 import org.dive4elements.river.client.client.Config; | |
24 import org.dive4elements.river.client.client.FLYSConstants; | |
25 import org.dive4elements.river.client.client.services.CSVExportService; | |
26 import org.dive4elements.river.client.client.services.CSVExportServiceAsync; | |
27 import org.dive4elements.river.client.shared.model.DataList; | |
28 | |
29 import java.util.List; | |
30 | |
31 /** | 30 /** |
32 * This UIProvider creates a widget that displays calculated data in a table. | 31 * This UIProvider creates a widget that displays calculated data in a table. |
33 * | 32 * |
34 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 33 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
35 */ | 34 */ |
36 public class TableDataPanel | 35 public class TableDataPanel { |
37 { | |
38 /** The message class that provides i18n strings. */ | 36 /** The message class that provides i18n strings. */ |
39 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 37 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
40 | 38 |
41 protected CSVExportServiceAsync exportService = | 39 protected CSVExportServiceAsync exportService = GWT.create(CSVExportService.class); |
42 GWT.create(CSVExportService.class); | |
43 | 40 |
44 /** A container that will contain the location or the distance panel. */ | 41 /** A container that will contain the location or the distance panel. */ |
45 protected VLayout container; | 42 protected VLayout container; |
46 | 43 |
47 /** The export type. */ | 44 /** The export type. */ |
51 protected String uuid; | 48 protected String uuid; |
52 | 49 |
53 /** The table. */ | 50 /** The table. */ |
54 protected ListGrid dataTable; | 51 protected ListGrid dataTable; |
55 | 52 |
56 | |
57 /** | 53 /** |
58 * Creates a new TableDataPanel instance. | 54 * Creates a new TableDataPanel instance. |
59 */ | 55 */ |
60 public TableDataPanel() { | 56 public TableDataPanel() { |
61 container = new VLayout(); | 57 this.container = new VLayout(); |
62 dataTable = new ListGrid(); | 58 this.dataTable = new ListGrid(); |
63 name = ""; | 59 this.name = ""; |
64 } | 60 } |
65 | |
66 | 61 |
67 /** | 62 /** |
68 * This method creates a widget that contains a table. | 63 * This method creates a widget that contains a table. |
69 * | 64 * |
70 * @return a panel. | 65 * @return a panel. |
71 */ | 66 */ |
72 public Canvas create() { | 67 public Canvas create() { |
73 Config config = Config.getInstance(); | 68 final Config config = Config.getInstance(); |
74 String locale = config.getLocale (); | 69 final String locale = config.getLocale(); |
75 dataTable.setEmptyMessage(MESSAGES.empty_table()); | 70 this.dataTable.setEmptyMessage(this.MESSAGES.empty_table()); |
76 dataTable.setShowHeaderContextMenu(false); | 71 this.dataTable.setShowHeaderContextMenu(false); |
77 dataTable.setCanDragSelectText(true); | 72 this.dataTable.setCanDragSelectText(true); |
78 | 73 |
79 exportService.getCSV(locale, uuid, name, | 74 this.exportService.getCSV(locale, this.uuid, this.name, new AsyncCallback<List<String[]>>() { |
80 new AsyncCallback<List<String[]>>() { | 75 @Override |
81 @Override | 76 public void onFailure(final Throwable caught) { |
82 public void onFailure(Throwable caught) { | 77 GWT.log("Could not receive csv."); |
83 GWT.log("Could not receive csv."); | 78 SC.warn(caught.getMessage()); |
84 SC.warn(caught.getMessage()); | 79 } |
85 } | |
86 | 80 |
87 @Override | 81 @Override |
88 public void onSuccess(List<String[]> l) { | 82 public void onSuccess(final List<String[]> l) { |
89 GWT.log("Recieved csv with " + l.size() + " lines."); | 83 GWT.log("Recieved csv with " + l.size() + " lines."); |
90 setData(l); | 84 setData(l); |
91 } | |
92 } | 85 } |
93 ); | 86 }); |
94 | 87 |
95 container.addMember(dataTable); | 88 this.container.addMember(this.dataTable); |
96 | 89 |
97 return container; | 90 return this.container; |
98 } | 91 } |
99 | 92 |
100 | 93 public void setName(final String name) { |
101 public void setName(String name) { | 94 this.name = name; |
102 this.name = name; | |
103 } | 95 } |
104 | 96 |
105 public void setUuid(String uuid) { | 97 public void setUuid(final String uuid) { |
106 this.uuid = uuid; | 98 this.uuid = uuid; |
107 } | 99 } |
108 | 100 |
109 | 101 public Canvas createOld(final DataList dataList) { |
110 public Canvas createOld(DataList dataList) { | |
111 return null; | 102 return null; |
112 } | 103 } |
113 | 104 |
114 | 105 protected Canvas createWidget(final DataList data) { |
115 protected Canvas createWidget(DataList data) { | |
116 return null; | 106 return null; |
117 } | 107 } |
118 | |
119 | 108 |
120 /** | 109 /** |
121 * This method sets the data to a dynamic table. | 110 * This method sets the data to a dynamic table. |
122 * | 111 * |
123 * @param list List of String[] containing the data. | 112 * @param list |
113 * List of String[] containing the data. | |
124 */ | 114 */ |
125 public void setData(List<String[]> list) { | 115 public void setData(final List<String[]> list) { |
126 if (list == null || list.size() < 2) { | 116 if (list == null || list.size() < 2) { |
127 dataTable.setEmptyMessage(MESSAGES.error_no_calc_result()); | 117 this.dataTable.setEmptyMessage(this.MESSAGES.error_no_calc_result()); |
128 dataTable.redraw(); | 118 this.dataTable.redraw(); |
129 return; | 119 return; |
130 } | 120 } |
131 | 121 |
132 Config config = Config.getInstance(); | 122 final Config config = Config.getInstance(); |
133 String locale = config.getLocale(); | 123 final String locale = config.getLocale(); |
134 | 124 |
135 NumberFormat nf; | 125 NumberFormat nf; |
136 if (locale.equals("de")) { | 126 if (locale.equals("de")) { |
137 nf = NumberFormat.getFormat("#,##"); | 127 nf = NumberFormat.getFormat("#,##"); |
138 } | 128 } else { |
139 else { | |
140 nf = NumberFormat.getFormat("#.##"); | 129 nf = NumberFormat.getFormat("#.##"); |
141 } | 130 } |
142 | 131 |
143 String[] header = list.get(0); | 132 final String[] header = list.get(0); |
144 String[] displayField = new String[header.length]; | 133 final String[] displayField = new String[header.length]; |
145 | 134 |
146 ListGridField[] fields = new ListGridField[header.length]; | 135 final ListGridField[] fields = new ListGridField[header.length]; |
147 | 136 |
148 for(int i = 0; i < header.length; i++) { | 137 for (int i = 0; i < header.length; i++) { |
149 ListGridField f = new ListGridField(String.valueOf(i)); | 138 final ListGridField f = new ListGridField(String.valueOf(i)); |
150 fields[i] = f; | 139 fields[i] = f; |
151 f.setTitle(header[i]); | 140 f.setTitle(header[i]); |
152 | 141 |
153 try { | 142 try { |
154 /* Try to determine the type with the first | 143 /* |
155 * non empty element. */ | 144 * Try to determine the type with the first |
145 * non empty element. | |
146 */ | |
156 for (int j = 1; j < list.size(); j++) { | 147 for (int j = 1; j < list.size(); j++) { |
157 if (!list.get(j)[i].isEmpty()) { | 148 if (!list.get(j)[i].isEmpty()) { |
158 nf.parse(list.get(j)[i]); | 149 nf.parse(list.get(j)[i]); |
159 f.setType(ListGridFieldType.FLOAT); | 150 f.setType(ListGridFieldType.FLOAT); |
160 break; | 151 break; |
161 } | 152 } |
162 } | 153 } |
163 } | 154 } |
164 catch (NumberFormatException nfe) { | 155 catch (final NumberFormatException nfe) { |
165 f.setType(ListGridFieldType.TEXT); | 156 f.setType(ListGridFieldType.TEXT); |
166 } | 157 } |
167 | 158 |
168 // To keep server-side formatting and i18n also of | 159 // To keep server-side formatting and i18n also of |
169 // float values, we will store the value once formatted 'as is' | 160 // float values, we will store the value once formatted 'as is' |
173 f.setDisplayField(displayField[i]); | 164 f.setDisplayField(displayField[i]); |
174 f.setValueField(String.valueOf(i)); | 165 f.setValueField(String.valueOf(i)); |
175 f.setSortByDisplayField(false); | 166 f.setSortByDisplayField(false); |
176 } | 167 } |
177 | 168 |
178 dataTable.setFields(fields); | 169 this.dataTable.setFields(fields); |
179 | 170 |
180 for(int i = 1; i < list.size(); i++) { | 171 for (int i = 1; i < list.size(); i++) { |
181 String[] sItem = list.get(i); | 172 final String[] sItem = list.get(i); |
182 ListGridRecord r = new ListGridRecord(); | 173 final ListGridRecord r = new ListGridRecord(); |
183 for(int j = 0; j < sItem.length; j++) { | 174 for (int j = 0; j < sItem.length; j++) { |
184 // See above, display 'as is' from server, but keep value | 175 // See above, display 'as is' from server, but keep value |
185 // in machine-usable way (float), to allow numeric sorting. | 176 // in machine-usable way (float), to allow numeric sorting. |
186 r.setAttribute(displayField[j], sItem[j]); | 177 r.setAttribute(displayField[j], sItem[j]); |
187 if (fields[j].getType() == ListGridFieldType.TEXT) { | 178 if (fields[j].getType() == ListGridFieldType.TEXT) { |
188 r.setAttribute(String.valueOf(j), sItem[j]); | 179 r.setAttribute(String.valueOf(j), sItem[j]); |
189 } | 180 } else { |
190 else { | |
191 try { | 181 try { |
192 r.setAttribute(String.valueOf(j), nf.parse(sItem[j])); | 182 r.setAttribute(String.valueOf(j), nf.parse(sItem[j])); |
193 } | 183 } |
194 catch (NumberFormatException nfe) { | 184 catch (final NumberFormatException nfe) { |
195 r.setAttribute(String.valueOf(j), sItem[j]); | 185 r.setAttribute(String.valueOf(j), sItem[j]); |
196 } | 186 } |
197 } | 187 } |
198 } | 188 } |
199 dataTable.addData(r); | 189 this.dataTable.addData(r); |
200 } | 190 } |
201 } | 191 } |
202 } | 192 } |
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |