comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 1604:cb3629a01126

Issue 473. Manual point input is now localized. flys-client/trunk@3952 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 07 Feb 2012 15:00:28 +0000
parents ddf43791244c
children 2eec6d55fcfa
comparison
equal deleted inserted replaced
1603:dd612a1348d2 1604:cb3629a01126
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.Map;
5 import java.util.HashMap;
4 6
5 import com.google.gwt.json.client.JSONArray; 7 import com.google.gwt.json.client.JSONArray;
6 import com.google.gwt.json.client.JSONBoolean; 8 import com.google.gwt.json.client.JSONBoolean;
7 import com.google.gwt.json.client.JSONNumber; 9 import com.google.gwt.json.client.JSONNumber;
8 import com.google.gwt.json.client.JSONParser; 10 import com.google.gwt.json.client.JSONParser;
24 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; 26 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
25 import com.smartgwt.client.types.ListGridFieldType; 27 import com.smartgwt.client.types.ListGridFieldType;
26 import com.smartgwt.client.widgets.grid.CellFormatter; 28 import com.smartgwt.client.widgets.grid.CellFormatter;
27 import com.google.gwt.i18n.client.NumberFormat; 29 import com.google.gwt.i18n.client.NumberFormat;
28 30
31 import com.smartgwt.client.widgets.grid.CellEditValueParser;
32 import com.smartgwt.client.widgets.grid.CellEditValueFormatter;
29 import com.smartgwt.client.widgets.events.ClickEvent; 33 import com.smartgwt.client.widgets.events.ClickEvent;
30 import com.smartgwt.client.widgets.events.ClickHandler; 34 import com.smartgwt.client.widgets.events.ClickHandler;
31 35
32 import com.smartgwt.client.types.Alignment; 36 import com.smartgwt.client.types.Alignment;
33 37
176 listGrid.setShowHeaderContextMenu(false); 180 listGrid.setShowHeaderContextMenu(false);
177 181
178 CellFormatter doubleFormat = new CellFormatter() { 182 CellFormatter doubleFormat = new CellFormatter() {
179 public String format(Object value, ListGridRecord record, int rowNum, int colNum) { 183 public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
180 if(value != null) { 184 if(value != null) {
181 NumberFormat nf = NumberFormat.getFormat("#.##"); 185 NumberFormat nf = NumberFormat.getDecimalFormat();
182 try { 186 try {
183 return nf.format(((Number) value).doubleValue()); 187 double d = Double.valueOf(value.toString()).doubleValue();
188 return nf.format(d);
184 } catch (Exception e) { 189 } catch (Exception e) {
185 return value.toString(); 190 return value.toString();
186 } 191 }
187 } else { 192 } else {
188 return null; 193 return null;
189 } 194 }
190 }}; 195 }};
196
197 CellEditValueParser cevp = new CellEditValueParser() {
198 public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) {
199 try {
200 NumberFormat nf = NumberFormat.getDecimalFormat();
201 double d = nf.parse(value.toString());
202 return (new Double(d)).toString();
203 }
204 catch(NumberFormatException nfe) {
205 return value;
206 }
207 }
208 };
209
210 CellEditValueFormatter cevf = new CellEditValueFormatter() {
211 public Object format(Object value, ListGridRecord record, int rowNum, int colNum) {
212 NumberFormat nf = NumberFormat.getDecimalFormat();
213 try {
214 double d = Double.valueOf(value.toString()).doubleValue();
215 return nf.format(d);
216 }
217 catch(NumberFormatException nfe) {
218 return value;
219 }
220 }
221 };
191 222
192 // Use X and Y as default fallback. 223 // Use X and Y as default fallback.
193 String xAxis = "X"; 224 String xAxis = "X";
194 String yAxis = "Y"; 225 String yAxis = "Y";
195 226
215 } 246 }
216 ListGridField xField = 247 ListGridField xField =
217 new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); 248 new ListGridField(PointRecord.ATTRIBUTE_X, xAxis);
218 xField.setType(ListGridFieldType.FLOAT); 249 xField.setType(ListGridFieldType.FLOAT);
219 xField.setCellFormatter(doubleFormat); 250 xField.setCellFormatter(doubleFormat);
251 xField.setEditValueParser(cevp);
252 xField.setEditValueFormatter(cevf);
253
220 254
221 ListGridField yField = 255 ListGridField yField =
222 new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); 256 new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis);
223 yField.setType(ListGridFieldType.FLOAT); 257 yField.setType(ListGridFieldType.FLOAT);
224 yField.setCellFormatter(doubleFormat); 258 yField.setCellFormatter(doubleFormat);
259 yField.setEditValueParser(cevp);
260 yField.setEditValueFormatter(cevf);
225 261
226 ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, 262 ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME,
227 MSG.pointname()); 263 MSG.pointname());
228 final ListGridField removeField = 264 final ListGridField removeField =
229 new ListGridField("_removeRecord", MSG.removepoint()){{ 265 new ListGridField("_removeRecord", MSG.removepoint()){{
488 if (record.getAttributeAsDouble(PointRecord.ATTRIBUTE_X) == null 524 if (record.getAttributeAsDouble(PointRecord.ATTRIBUTE_X) == null
489 || record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) { 525 || record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) {
490 return false; 526 return false;
491 } 527 }
492 } 528 }
529 if (listGrid.hasErrors()) {
530 valid = false;
531 }
493 return valid; 532 return valid;
494 } 533 }
495 } 534 }
496 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 535 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org