Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java @ 9167:cb3a91dc4e3b
Result-Tabs (for collisions)
author | gernotbelger |
---|---|
date | Wed, 20 Jun 2018 18:25:58 +0200 |
parents | 28c50f5efceb |
children | f1be005f0c46 |
rev | line source |
---|---|
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
9 package org.dive4elements.river.client.client.ui; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 |
9167 | 11 import java.util.ArrayList; |
9064 | 12 import java.util.List; |
13 | |
14 import org.dive4elements.river.client.client.Config; | |
15 import org.dive4elements.river.client.client.FLYSConstants; | |
16 import org.dive4elements.river.client.client.services.CSVExportService; | |
17 import org.dive4elements.river.client.client.services.CSVExportServiceAsync; | |
18 import org.dive4elements.river.client.shared.model.DataList; | |
19 | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 import com.google.gwt.core.client.GWT; |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
21 import com.google.gwt.i18n.client.NumberFormat; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 import com.google.gwt.user.client.rpc.AsyncCallback; |
9167 | 23 import com.smartgwt.client.data.Record; |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
24 import com.smartgwt.client.types.ListGridFieldType; |
550
605debcbb6a0
Adjusted the return values of the CSVExportService, so that GWT can handle those values better.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
284
diff
changeset
|
25 import com.smartgwt.client.util.SC; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 import com.smartgwt.client.widgets.Canvas; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 import com.smartgwt.client.widgets.grid.ListGrid; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 import com.smartgwt.client.widgets.grid.ListGridField; |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
29 import com.smartgwt.client.widgets.layout.VLayout; |
9167 | 30 import com.smartgwt.client.widgets.tab.Tab; |
31 import com.smartgwt.client.widgets.tab.TabSet; | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 /** |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 * This UIProvider creates a widget that displays calculated data in a table. |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 * |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 */ |
9064 | 38 public class TableDataPanel { |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
39 /** The message class that provides i18n strings. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 |
9064 | 42 protected CSVExportServiceAsync exportService = GWT.create(CSVExportService.class); |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
44 /** A container that will contain the location or the distance panel. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 protected VLayout container; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
47 /** The export type. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 protected String name; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
50 /** The UUID of the collection. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 protected String uuid; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
53 /** The table. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 protected ListGrid dataTable; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 |
9167 | 56 private final TabSet tabSet; |
57 | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 /** |
7616
9fc549a7f5cb
Fix doc/debug.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7602
diff
changeset
|
59 * Creates a new TableDataPanel instance. |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 */ |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 public TableDataPanel() { |
9064 | 62 this.container = new VLayout(); |
63 this.dataTable = new ListGrid(); | |
9167 | 64 this.tabSet = new TabSet(); |
9064 | 65 this.name = ""; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 /** |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
69 * This method creates a widget that contains a table. |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 * |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 * @return a panel. |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 */ |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 public Canvas create() { |
9064 | 74 final Config config = Config.getInstance(); |
75 final String locale = config.getLocale(); | |
76 this.dataTable.setEmptyMessage(this.MESSAGES.empty_table()); | |
77 this.dataTable.setShowHeaderContextMenu(false); | |
78 this.dataTable.setCanDragSelectText(true); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 |
9064 | 80 this.exportService.getCSV(locale, this.uuid, this.name, new AsyncCallback<List<String[]>>() { |
81 @Override | |
82 public void onFailure(final Throwable caught) { | |
83 GWT.log("Could not receive csv."); | |
84 SC.warn(caught.getMessage()); | |
85 } | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 |
9064 | 87 @Override |
88 public void onSuccess(final List<String[]> l) { | |
89 GWT.log("Recieved csv with " + l.size() + " lines."); | |
90 setData(l); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
91 } |
9064 | 92 }); |
93 this.container.addMember(this.dataTable); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 |
9064 | 95 return this.container; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 |
9064 | 98 public void setName(final String name) { |
99 this.name = name; | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 |
9064 | 102 public void setUuid(final String uuid) { |
103 this.uuid = uuid; | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 |
9064 | 106 public Canvas createOld(final DataList dataList) { |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 return null; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 |
9064 | 110 protected Canvas createWidget(final DataList data) { |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 return null; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
114 /** |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
115 * This method sets the data to a dynamic table. |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
116 * |
9064 | 117 * @param list |
118 * List of String[] containing the data. | |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
119 */ |
9167 | 120 |
9064 | 121 public void setData(final List<String[]> list) { |
1289
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
122 if (list == null || list.size() < 2) { |
9064 | 123 this.dataTable.setEmptyMessage(this.MESSAGES.error_no_calc_result()); |
124 this.dataTable.redraw(); | |
1289
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
125 return; |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
126 } |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
127 |
9064 | 128 final Config config = Config.getInstance(); |
129 final String locale = config.getLocale(); | |
1486
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
130 |
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
131 NumberFormat nf; |
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
132 if (locale.equals("de")) { |
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
133 nf = NumberFormat.getFormat("#,##"); |
9064 | 134 } else { |
1486
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
135 nf = NumberFormat.getFormat("#.##"); |
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
136 } |
9167 | 137 final List<List<String[]>> tabData = getTabData(list); |
138 if (tabData.size() == 1) { | |
139 createTable(this.dataTable, tabData.get(0), nf, 0); | |
140 | |
141 } else if (tabData.size() > 1) { | |
142 | |
143 for (int i = 0; i < tabData.size(); i++) { | |
144 final List<String[]> items = tabData.get(i); | |
145 | |
146 final ListGrid table = new ListGrid(); | |
147 | |
148 createTable(table, items, nf, i); | |
149 final Tab tab = new Tab(); | |
150 tab.setTitle("Ergebnis: " + i); // TODO: get Title from Server | |
151 tab.setPane(table); | |
152 this.tabSet.addTab(tab); | |
153 } | |
154 this.tabSet.selectTab(0); | |
155 this.container.removeChild(this.dataTable); | |
156 this.container.addChild(this.tabSet); | |
157 this.tabSet.setWidth100(); | |
158 this.tabSet.setHeight100(); | |
159 } | |
160 } | |
161 | |
162 private void createTable(final ListGrid dataTableTab, final List<String[]> list, final NumberFormat nf, final int tabNumber) { | |
1486
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
163 |
9064 | 164 final String[] header = list.get(0); |
165 final String[] displayField = new String[header.length]; | |
1289
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
166 |
9064 | 167 final ListGridField[] fields = new ListGridField[header.length]; |
1486
efdb4fe5a69e
Improved the TableDataPanel (for displaying calculation results) to support CSV exports with more than 5 columns.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1425
diff
changeset
|
168 |
9064 | 169 for (int i = 0; i < header.length; i++) { |
170 final ListGridField f = new ListGridField(String.valueOf(i)); | |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
171 fields[i] = f; |
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
172 f.setTitle(header[i]); |
906
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
173 |
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
174 try { |
9064 | 175 /* |
176 * Try to determine the type with the first | |
9167 | 177 * non empty element. -> WARUM??! OK, nur Formatierung/Sortierung |
9064 | 178 */ |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
179 for (int j = 1; j < list.size(); j++) { |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
180 if (!list.get(j)[i].isEmpty()) { |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
181 nf.parse(list.get(j)[i]); |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
182 f.setType(ListGridFieldType.FLOAT); |
9167 | 183 |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
184 break; |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
185 } |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
186 } |
906
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
187 } |
9064 | 188 catch (final NumberFormatException nfe) { |
906
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
189 f.setType(ListGridFieldType.TEXT); |
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
190 } |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
191 |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
192 // To keep server-side formatting and i18n also of |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
193 // float values, we will store the value once formatted 'as is' |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
194 // to be displayed and once as e.g. float to allow functions like |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
195 // sorting on it. |
9167 | 196 displayField[i] = "$" + i + "_displayField"; |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
197 f.setDisplayField(displayField[i]); |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
198 f.setValueField(String.valueOf(i)); |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
199 f.setSortByDisplayField(false); |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
200 |
9167 | 201 } |
202 dataTableTab.setFields(fields); | |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
203 |
9167 | 204 for (int i = 1; i < list.size(); i++) { // index bei 1, da erster Eintrag Header ist |
205 | |
9064 | 206 final String[] sItem = list.get(i); |
9167 | 207 final Record r = new Record(); |
9064 | 208 for (int j = 0; j < sItem.length; j++) { |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
209 // See above, display 'as is' from server, but keep value |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
210 // in machine-usable way (float), to allow numeric sorting. |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
211 r.setAttribute(displayField[j], sItem[j]); |
9167 | 212 // r.setAttribute(String.valueOf(j), sItem[j]); |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
213 if (fields[j].getType() == ListGridFieldType.TEXT) { |
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
214 r.setAttribute(String.valueOf(j), sItem[j]); |
9064 | 215 } else { |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
216 try { |
9167 | 217 final Float valueFloatSortable = (float) nf.parse(sItem[j]); |
218 r.setAttribute(String.valueOf(j), valueFloatSortable); | |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
219 } |
9064 | 220 catch (final NumberFormatException nfe) { |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
221 r.setAttribute(String.valueOf(j), sItem[j]); |
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
222 } |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
223 } |
9167 | 224 |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
225 } |
9167 | 226 |
227 dataTableTab.addData(r); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
228 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
229 } |
9167 | 230 |
231 private List<List<String[]>> getTabData(final List<String[]> raw) { | |
232 final List<List<String[]>> tabs = new ArrayList<List<String[]>>(); | |
233 String[] compare = raw.get(0); | |
234 int lastIndex = 0; | |
235 | |
236 for (int i = 0; i < raw.size(); i++) { | |
237 final String[] row = raw.get(i); | |
238 if (compare.length != row.length) { | |
239 tabs.add(raw.subList(lastIndex, i)); | |
240 lastIndex = i; | |
241 } | |
242 | |
243 if (i == (raw.size() - 1)) { | |
244 tabs.add(raw.subList(lastIndex, i + 1)); // toIndex exclusive, fromIndex inclusive | |
245 } | |
246 compare = row; | |
247 } | |
248 | |
249 return tabs; | |
250 } | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
251 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
252 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |