Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java @ 9256:6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
author | gernotbelger |
---|---|
date | Fri, 13 Jul 2018 12:04:21 +0200 |
parents | f1be005f0c46 |
children | 49c0b687d22f |
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; |
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 |
9064 | 107 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
|
108 return null; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
109 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
110 |
9064 | 111 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
|
112 return null; |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
114 |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
115 /** |
4184
03de5c424f95
Fix warnings and minor TODOs in flys-client.
Christian Lins <christian.lins@intevation.de>
parents:
1486
diff
changeset
|
116 * 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
|
117 * |
9064 | 118 * @param list |
119 * 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
|
120 */ |
9167 | 121 |
9064 | 122 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
|
123 if (list == null || list.size() < 2) { |
9064 | 124 this.dataTable.setEmptyMessage(this.MESSAGES.error_no_calc_result()); |
125 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
|
126 return; |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
127 } |
d59dcaf52796
Improved error handling if no calculation result data was found.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
906
diff
changeset
|
128 |
9064 | 129 final Config config = Config.getInstance(); |
130 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
|
131 |
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 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
|
133 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
|
134 nf = NumberFormat.getFormat("#,##"); |
9064 | 135 } 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
|
136 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
|
137 } |
9171 | 138 final Map<String, List<String[]>> tabData = getTabData(list); |
9167 | 139 if (tabData.size() == 1) { |
9171 | 140 createTable(this.dataTable, tabData.get(tabData.keySet().iterator().next()), nf, 0); |
9167 | 141 |
142 } else if (tabData.size() > 1) { | |
143 | |
9171 | 144 final int index = 0; |
145 for (final String key : tabData.keySet()) { | |
146 final List<String[]> items = tabData.get(key); | |
9167 | 147 |
148 final ListGrid table = new ListGrid(); | |
149 | |
9171 | 150 createTable(table, items, nf, index); |
9167 | 151 final Tab tab = new Tab(); |
9171 | 152 tab.setTitle(key); |
9167 | 153 tab.setPane(table); |
154 this.tabSet.addTab(tab); | |
155 } | |
156 this.tabSet.selectTab(0); | |
157 this.container.removeChild(this.dataTable); | |
158 this.container.addChild(this.tabSet); | |
159 this.tabSet.setWidth100(); | |
160 this.tabSet.setHeight100(); | |
161 } | |
162 } | |
163 | |
164 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
|
165 |
9064 | 166 final String[] header = list.get(0); |
167 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
|
168 |
9064 | 169 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
|
170 |
9064 | 171 for (int i = 0; i < header.length; i++) { |
172 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
|
173 fields[i] = f; |
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
174 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
|
175 |
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
176 try { |
9064 | 177 /* |
178 * Try to determine the type with the first | |
9167 | 179 * non empty element. -> WARUM??! OK, nur Formatierung/Sortierung |
9064 | 180 */ |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 f.setType(ListGridFieldType.FLOAT); |
9167 | 185 |
8632
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
186 break; |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
187 } |
5533aa8f8b73
(issue1608) Determine field type with the first non empty element
Andre Heinecke <andre.heinecke@intevation.de>
parents:
7617
diff
changeset
|
188 } |
906
39acba4b5f0b
Added formatter for numeric columns that converts the decimal separator.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
879
diff
changeset
|
189 } |
9064 | 190 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
|
191 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
|
192 } |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
193 |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
194 // 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
|
195 // 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
|
196 // 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
|
197 // sorting on it. |
9167 | 198 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
|
199 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
|
200 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
|
201 f.setSortByDisplayField(false); |
9167 | 202 } |
203 dataTableTab.setFields(fields); | |
259
50a95db68e66
Build a dynamic table for the CSV data.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
256
diff
changeset
|
204 |
9167 | 205 for (int i = 1; i < list.size(); i++) { // index bei 1, da erster Eintrag Header ist |
206 | |
9064 | 207 final String[] sItem = list.get(i); |
9167 | 208 final Record r = new Record(); |
9064 | 209 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
|
210 // 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
|
211 // 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
|
212 r.setAttribute(displayField[j], sItem[j]); |
9167 | 213 // 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
|
214 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
|
215 r.setAttribute(String.valueOf(j), sItem[j]); |
9064 | 216 } else { |
7617
89c1fcd6db52
Avoid certain exception, added todo about issues with implementation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7616
diff
changeset
|
217 try { |
9167 | 218 final Float valueFloatSortable = (float) nf.parse(sItem[j]); |
219 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
|
220 } |
9064 | 221 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
|
222 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
|
223 } |
7602
c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
7601
diff
changeset
|
224 } |
9167 | 225 |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
226 } |
9167 | 227 |
228 dataTableTab.addData(r); | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
229 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
230 } |
9167 | 231 |
9171 | 232 private Map<String, List<String[]>> getTabData(final List<String[]> raw) { |
233 // Condition: tableTitle must be first | |
234 final Map<String, List<String[]>> tabs = new TreeMap<String, List<String[]>>(); // auto-sort | |
9167 | 235 |
9171 | 236 if (raw.get(0)[0].startsWith(this.MESSAGES.export_csv_title())) { |
237 // Bedingung für Tabs | |
238 int lastIndex = 0; | |
239 String lastTableTitle = ""; | |
240 | |
241 for (int i = 0; i < raw.size(); i++) { | |
242 | |
243 final String[] row = raw.get(i); | |
244 if (row[0].startsWith(this.MESSAGES.export_csv_title())) { | |
245 | |
246 if (i > 0) { | |
247 tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), (i))); // toIndex exclusive (without | |
248 // tabTitle-Line of the next tab, which is | |
249 // stored in the current row (raw.get(i)); | |
250 // fromIndex | |
251 // inclusive -> | |
252 // without tabTitle from the past tab -> | |
253 // lastindex+1 | |
254 } | |
255 lastTableTitle = row[0].replace(this.MESSAGES.export_csv_title(), ""); | |
256 lastIndex = i; | |
257 } | |
258 | |
259 if (i == (raw.size() - 1)) { | |
260 tabs.put(makeKeyTitle(lastTableTitle, tabs.size()), raw.subList((lastIndex + 1), i + 1)); | |
261 // last result-tab: | |
262 // toIndex exclusive -> last i + 1 | |
263 // fromIndex inclusive: lastInde +1 -> no title-line included | |
264 } | |
265 | |
9167 | 266 } |
9171 | 267 } else { |
268 // plainOld Table, no TABS | |
269 tabs.put("", raw); | |
9167 | 270 } |
271 | |
272 return tabs; | |
273 } | |
9171 | 274 |
275 private String makeKeyTitle(final String title, final int index) { | |
276 return new StringBuilder().append("(").append((index + 1)).append(") ").append(title).toString(); | |
277 } | |
256
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
278 } |
5e1c1b7d6516
Added table and service for calculation output to UI.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
279 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |