changeset 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 dd612a1348d2
children fe59df5c85cc
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java
diffstat 2 files changed, 49 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Feb 07 10:03:49 2012 +0000
+++ b/flys-client/ChangeLog	Tue Feb 07 15:00:28 2012 +0000
@@ -1,3 +1,11 @@
+2012-02-07  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue 473. Manual point input is now localized.
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java:
+	  Added formatter and parser for 'X' and 'Y' values and return 'false' in
+	  'isDialogValid' if the grid contains any errors.
+
 2012-02-07  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/webapp/WEB-INF/web.xml: Reverted port 8182 to 8181 which is the
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java	Tue Feb 07 10:03:49 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java	Tue Feb 07 15:00:28 2012 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.client.client.ui.chart;
 
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONBoolean;
@@ -26,6 +28,8 @@
 import com.smartgwt.client.widgets.grid.CellFormatter;
 import com.google.gwt.i18n.client.NumberFormat;
 
+import com.smartgwt.client.widgets.grid.CellEditValueParser;
+import com.smartgwt.client.widgets.grid.CellEditValueFormatter;
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
 
@@ -178,9 +182,10 @@
         CellFormatter doubleFormat = new CellFormatter() {
             public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                 if(value != null) {
-                    NumberFormat nf = NumberFormat.getFormat("#.##");
+                    NumberFormat nf = NumberFormat.getDecimalFormat();
                     try {
-                        return nf.format(((Number) value).doubleValue());
+                        double d = Double.valueOf(value.toString()).doubleValue();
+                        return nf.format(d);
                     } catch (Exception e) {
                         return value.toString();
                     }
@@ -189,6 +194,32 @@
                 }
             }};
 
+        CellEditValueParser cevp = new CellEditValueParser() {
+            public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) {
+                try {
+                    NumberFormat nf = NumberFormat.getDecimalFormat();
+                    double d = nf.parse(value.toString());
+                    return (new Double(d)).toString();
+                }
+                catch(NumberFormatException nfe) {
+                    return value;
+                }
+            }
+        };
+
+        CellEditValueFormatter cevf = new CellEditValueFormatter() {
+            public Object format(Object value, ListGridRecord record, int rowNum, int colNum) {
+                NumberFormat nf = NumberFormat.getDecimalFormat();
+                try {
+                    double d = Double.valueOf(value.toString()).doubleValue();
+                    return nf.format(d);
+                }
+                catch(NumberFormatException nfe) {
+                    return value;
+                }
+            }
+        };
+
         // Use X and Y as default fallback.
         String xAxis = "X";
         String yAxis = "Y";
@@ -217,11 +248,16 @@
             new ListGridField(PointRecord.ATTRIBUTE_X, xAxis);
         xField.setType(ListGridFieldType.FLOAT);
         xField.setCellFormatter(doubleFormat);
+        xField.setEditValueParser(cevp);
+        xField.setEditValueFormatter(cevf);
+
 
         ListGridField yField =
             new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis);
         yField.setType(ListGridFieldType.FLOAT);
         yField.setCellFormatter(doubleFormat);
+        yField.setEditValueParser(cevp);
+        yField.setEditValueFormatter(cevf);
 
         ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME,
             MSG.pointname());
@@ -490,6 +526,9 @@
                 return false;
             }
         }
+        if (listGrid.hasErrors()) {
+            valid = false;
+        }
         return valid;
     }
 }

http://dive4elements.wald.intevation.org