Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java @ 9353:217e8e59c386
sinfo flowdepth multiple pairs allowed; bugfix arrayOutOfRange hasTkh==false && useTkh==true
author | gernotbelger |
---|---|
date | Tue, 31 Jul 2018 17:53:41 +0200 |
parents | 0452f1c1bad3 |
children |
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 |
9064 | 11 import java.util.List; |
9171 | 12 import java.util.Map; |
13 import java.util.TreeMap; | |
9064 | 14 |
15 import org.dive4elements.river.client.client.Config; | |
16 import org.dive4elements.river.client.client.FLYSConstants; | |
17 import org.dive4elements.river.client.client.services.CSVExportService; | |
18 import org.dive4elements.river.client.client.services.CSVExportServiceAsync; | |
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; |
9314
49c0b687d22f
Fixed: some texts, such as "<MNQ", not visible in pdf export and in result table.
gernotbelger
parents:
9171
diff
changeset
|
22 import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 import com.google.gwt.user.client.rpc.AsyncCallback; |
9167 | 24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 import com.smartgwt.client.widgets.layout.VLayout; |
9167 | 31 import com.smartgwt.client.widgets.tab.Tab; |
32 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
|
33 |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 /** |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 * 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
|
36 * |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 * @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
|
38 */ |
9064 | 39 public class TableDataPanel { |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
40 /** 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
|
41 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
|
42 |
9064 | 43 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
|
44 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
45 /** 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
|
46 protected VLayout container; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
48 /** The export type. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 protected String name; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
51 /** 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
|
52 protected String uuid; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
54 /** The table. */ |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 protected ListGrid dataTable; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 |
9167 | 57 private final TabSet tabSet; |
58 | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 /** |
7616
9fc549a7f5cb
Fix doc/debug.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7602
diff
changeset
|
60 * 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
|
61 */ |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 public TableDataPanel() { |
9064 | 63 this.container = new VLayout(); |
64 this.dataTable = new ListGrid(); | |
9167 | 65 this.tabSet = new TabSet(); |
9064 | 66 this.name = ""; |
256
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 |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 /** |
810
a443dd6566b8
Minor cosmetic changes (javadoc comments).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
788
diff
changeset
|
70 * 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
|
71 * |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 * @return a panel. |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 */ |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
74 public Canvas create() { |
9064 | 75 final Config config = Config.getInstance(); |
76 final String locale = config.getLocale(); | |
77 this.dataTable.setEmptyMessage(this.MESSAGES.empty_table()); | |
78 this.dataTable.setShowHeaderContextMenu(false); | |
79 this.dataTable.setCanDragSelectText(true); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 |
9064 | 81 this.exportService.getCSV(locale, this.uuid, this.name, new AsyncCallback<List<String[]>>() { |
82 @Override | |
83 public void onFailure(final Throwable caught) { | |
84 GWT.log("Could not receive csv."); | |
85 SC.warn(caught.getMessage()); | |
86 } | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
87 |
9064 | 88 @Override |
89 public void onSuccess(final List<String[]> l) { | |
90 GWT.log("Recieved csv with " + l.size() + " lines."); | |
91 setData(l); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 } |
9064 | 93 }); |
94 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
|
95 |
9064 | 96 return this.container; |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 |
9064 | 99 public void setName(final String name) { |
100 this.name = name; | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
102 |
9064 | 103 public void setUuid(final String uuid) { |
104 this.uuid = uuid; | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
107 /** |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
108 * 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
|
109 * |
9064 | 110 * @param list |
111 * 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
|
112 */ |
9167 | 113 |
9064 | 114 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
|
115 if (list == null || list.size() < 2) { |
9064 | 116 this.dataTable.setEmptyMessage(this.MESSAGES.error_no_calc_result()); |
117 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
|
118 return; |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
119 } |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
120 |
9064 | 121 final Config config = Config.getInstance(); |
122 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
|
123 |
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
|
124 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
|
125 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
|
126 nf = NumberFormat.getFormat("#,##"); |
9064 | 127 } 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
|
128 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
|
129 } |
9171 | 130 final Map<String, List<String[]>> tabData = getTabData(list); |
9167 | 131 if (tabData.size() == 1) { |
9326 | 132 createTable(this.dataTable, tabData.get(tabData.keySet().iterator().next()), nf); |
9167 | 133 |
134 } else if (tabData.size() > 1) { | |
135 | |
9171 | 136 for (final String key : tabData.keySet()) { |
137 final List<String[]> items = tabData.get(key); | |
9167 | 138 |
139 final ListGrid table = new ListGrid(); | |
140 | |
9326 | 141 createTable(table, items, nf); |
9167 | 142 final Tab tab = new Tab(); |
9171 | 143 tab.setTitle(key); |
9167 | 144 tab.setPane(table); |
145 this.tabSet.addTab(tab); | |
146 } | |
147 this.tabSet.selectTab(0); | |
148 this.container.removeChild(this.dataTable); | |
149 this.container.addChild(this.tabSet); | |
150 this.tabSet.setWidth100(); | |
151 this.tabSet.setHeight100(); | |
152 } | |
153 } | |
154 | |
9326 | 155 private void createTable(final ListGrid dataTableTab, final List<String[]> list, final NumberFormat nf) { |
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
|
156 |
9064 | 157 final String[] header = list.get(0); |
158 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
|
159 |
9064 | 160 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
|
161 |
9064 | 162 for (int i = 0; i < header.length; i++) { |
163 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
|
164 fields[i] = f; |
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
165 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
|
166 |
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
167 try { |
9064 | 168 /* |
169 * Try to determine the type with the first | |
9167 | 170 * non empty element. -> WARUM??! OK, nur Formatierung/Sortierung |
9064 | 171 */ |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 f.setType(ListGridFieldType.FLOAT); |
9167 | 176 |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
177 break; |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
178 } |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
179 } |
906
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
180 } |
9064 | 181 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
|
182 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
|
183 } |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
184 |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
185 // 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
|
186 // 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
|
187 // 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
|
188 // sorting on it. |
9167 | 189 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
|
190 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
|
191 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
|
192 f.setSortByDisplayField(false); |
9167 | 193 } |
194 dataTableTab.setFields(fields); | |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
195 |
9167 | 196 for (int i = 1; i < list.size(); i++) { // index bei 1, da erster Eintrag Header ist |
197 | |
9064 | 198 final String[] sItem = list.get(i); |
9167 | 199 final Record r = new Record(); |
9064 | 200 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
|
201 // 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
|
202 // in machine-usable way (float), to allow numeric sorting. |
9353
217e8e59c386
sinfo flowdepth multiple pairs allowed; bugfix arrayOutOfRange hasTkh==false && useTkh==true
gernotbelger
parents:
9326
diff
changeset
|
203 final String item = sItem[j]; |
217e8e59c386
sinfo flowdepth multiple pairs allowed; bugfix arrayOutOfRange hasTkh==false && useTkh==true
gernotbelger
parents:
9326
diff
changeset
|
204 final String encodedText = SafeHtmlUtils.htmlEscapeAllowEntities(item); |
217e8e59c386
sinfo flowdepth multiple pairs allowed; bugfix arrayOutOfRange hasTkh==false && useTkh==true
gernotbelger
parents:
9326
diff
changeset
|
205 |
9314
49c0b687d22f
Fixed: some texts, such as "<MNQ", not visible in pdf export and in result table.
gernotbelger
parents:
9171
diff
changeset
|
206 r.setAttribute(displayField[j], encodedText); |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
207 if (fields[j].getType() == ListGridFieldType.TEXT) { |
9314
49c0b687d22f
Fixed: some texts, such as "<MNQ", not visible in pdf export and in result table.
gernotbelger
parents:
9171
diff
changeset
|
208 r.setAttribute(String.valueOf(j), item); |
9064 | 209 } else { |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
210 try { |
9314
49c0b687d22f
Fixed: some texts, such as "<MNQ", not visible in pdf export and in result table.
gernotbelger
parents:
9171
diff
changeset
|
211 final Float valueFloatSortable = (float) nf.parse(item); |
9167 | 212 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
|
213 } |
9064 | 214 catch (final NumberFormatException nfe) { |
9314
49c0b687d22f
Fixed: some texts, such as "<MNQ", not visible in pdf export and in result table.
gernotbelger
parents:
9171
diff
changeset
|
215 r.setAttribute(String.valueOf(j), item); |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
216 } |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
217 } |
9167 | 218 |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
219 } |
9167 | 220 |
221 dataTableTab.addData(r); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
222 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
223 } |
9167 | 224 |
9171 | 225 private Map<String, List<String[]>> getTabData(final List<String[]> raw) { |
226 // Condition: tableTitle must be first | |
227 final Map<String, List<String[]>> tabs = new TreeMap<String, List<String[]>>(); // auto-sort | |
9167 | 228 |
9171 | 229 if (raw.get(0)[0].startsWith(this.MESSAGES.export_csv_title())) { |
230 // Bedingung für Tabs | |
231 int lastIndex = 0; | |
232 String lastTableTitle = ""; | |
233 | |
234 for (int i = 0; i < raw.size(); i++) { | |
235 | |
236 final String[] row = raw.get(i); | |
237 if (row[0].startsWith(this.MESSAGES.export_csv_title())) { | |
238 | |
239 if (i > 0) { | |
240 tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), (i))); // toIndex exclusive (without | |
241 // tabTitle-Line of the next tab, which is | |
242 // stored in the current row (raw.get(i)); | |
243 // fromIndex | |
244 // inclusive -> | |
245 // without tabTitle from the past tab -> | |
246 // lastindex+1 | |
247 } | |
248 lastTableTitle = row[0].replace(this.MESSAGES.export_csv_title(), ""); | |
249 lastIndex = i; | |
250 } | |
251 | |
252 if (i == (raw.size() - 1)) { | |
253 tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), i + 1)); | |
254 // last result-tab: | |
255 // toIndex exclusive -> last i + 1 | |
256 // fromIndex inclusive: lastInde +1 -> no title-line included | |
257 } | |
258 | |
9167 | 259 } |
9171 | 260 } else { |
261 // plainOld Table, no TABS | |
262 tabs.put("", raw); | |
9167 | 263 } |
264 | |
265 return tabs; | |
266 } | |
9171 | 267 |
268 private String makeKeyTitle(final String title, final int index) { | |
269 return new StringBuilder().append("(").append((index + 1)).append(") ").append(title).toString(); | |
270 } | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
271 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
272 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |