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