comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/TableDataPanel.java @ 8632:5533aa8f8b73

(issue1608) Determine field type with the first non empty element
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 26 Mar 2015 17:33:55 +0100
parents 89c1fcd6db52
children 28c50f5efceb
comparison
equal deleted inserted replaced
8631:b30068e92757 8632:5533aa8f8b73
139 else { 139 else {
140 nf = NumberFormat.getFormat("#.##"); 140 nf = NumberFormat.getFormat("#.##");
141 } 141 }
142 142
143 String[] header = list.get(0); 143 String[] header = list.get(0);
144 String[] firstValues = list.get(1);
145 String[] displayField = new String[header.length]; 144 String[] displayField = new String[header.length];
146 145
147 ListGridField[] fields = new ListGridField[header.length]; 146 ListGridField[] fields = new ListGridField[header.length];
148 147
149 for(int i = 0; i < header.length; i++) { 148 for(int i = 0; i < header.length; i++) {
150 ListGridField f = new ListGridField(String.valueOf(i)); 149 ListGridField f = new ListGridField(String.valueOf(i));
151 fields[i] = f; 150 fields[i] = f;
152 f.setTitle(header[i]); 151 f.setTitle(header[i]);
153 152
154 try { 153 try {
155 nf.parse(firstValues[i]); 154 /* Try to determine the type with the first
156 f.setType(ListGridFieldType.FLOAT); 155 * non empty element. */
156 for (int j = 1; j < list.size(); j++) {
157 if (!list.get(j)[i].isEmpty()) {
158 nf.parse(list.get(j)[i]);
159 f.setType(ListGridFieldType.FLOAT);
160 break;
161 }
162 }
157 } 163 }
158 catch (NumberFormatException nfe) { 164 catch (NumberFormatException nfe) {
159 f.setType(ListGridFieldType.TEXT); 165 f.setType(ListGridFieldType.TEXT);
160 } 166 }
161
162 // TODO Numerical sorting still does not work if the first values are empty (then
163 // it defaults to TEXT, currently. Shall be fixed.
164 167
165 // To keep server-side formatting and i18n also of 168 // To keep server-side formatting and i18n also of
166 // float values, we will store the value once formatted 'as is' 169 // float values, we will store the value once formatted 'as is'
167 // to be displayed and once as e.g. float to allow functions like 170 // to be displayed and once as e.g. float to allow functions like
168 // sorting on it. 171 // sorting on it.

http://dive4elements.wald.intevation.org