changeset 906:39acba4b5f0b

Added formatter for numeric columns that converts the decimal separator. (Issue200) flys-client/trunk@2758 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 15 Sep 2011 14:48:31 +0000
parents 478a571f1f94
children 24d15c2e0da3
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java flys-client/src/main/java/de/intevation/flys/client/client/ui/range/RangeTable.java
diffstat 6 files changed, 160 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/ChangeLog	Thu Sep 15 14:48:31 2011 +0000
@@ -1,3 +1,15 @@
+2011-09-15  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue200
+
+	* src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java,
+	  src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java,
+	  src/main/java/de/intevation/flys/client/client/ui/range/RangeTable.java,
+	  src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java:
+	  Added formatter for numeric columns that converts the decimal
+	  separator.
+
 2011-09-15  Ingo Weinzierl <ingo@intevation.de>
 
 	Refactored the HTTP related code for Collections and Artifacts out to helper
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java	Thu Sep 15 14:48:31 2011 +0000
@@ -21,6 +21,8 @@
 import com.smartgwt.client.widgets.layout.VLayout;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.CellFormatter;
 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
 import com.smartgwt.client.widgets.grid.events.CellClickHandler;
@@ -258,10 +260,47 @@
         ddescr.setType(ListGridFieldType.TEXT);
         ddescr.setWidth("*");
         ListGridField from = new ListGridField("from", MESSAGES.from());
-        from.setType(ListGridFieldType.FLOAT);
+        from.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
+
         from.setWidth("12%");
         ListGridField to = new ListGridField("to", MESSAGES.to());
         to.setType(ListGridFieldType.FLOAT);
+        to.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
+
         to.setWidth("12%");
         ListGridField dside = new ListGridField("riverside",
                 MESSAGES.riverside());
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java	Thu Sep 15 14:48:31 2011 +0000
@@ -16,8 +16,11 @@
 import com.smartgwt.client.widgets.layout.VLayout;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.CellFormatter;
 
 import com.smartgwt.client.data.Criteria;
 import com.smartgwt.client.data.Record;
@@ -163,7 +166,26 @@
         lside.setWidth("10%");
 
         ListGridField loc = new ListGridField("from", MESSAGES.location());
+        loc.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
         loc.setType(ListGridFieldType.FLOAT);
+
         loc.setWidth("10%");
 
         ListGridField bottom =
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/TableDataPanel.java	Thu Sep 15 14:48:31 2011 +0000
@@ -4,6 +4,7 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
@@ -11,6 +12,7 @@
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
 import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.types.ListGridFieldType;
 
 import de.intevation.flys.client.shared.model.DataList;
 
@@ -115,11 +117,30 @@
      */
     public void setData(List list) {
         String[] header = (String[])list.get(0);
+        String[] firstValues = (String[])list.get(1);
         ListGridField[] fields = new ListGridField[header.length];
         for(int i = 0; i < header.length; i++) {
             ListGridField f = new ListGridField(String.valueOf(i));
             fields[i] = f;
             f.setTitle(header[i]);
+
+            Config config = Config.getInstance();
+            String locale = config.getLocale();
+            try {
+                NumberFormat nf;
+                if (locale.equals("de")) {
+                    nf = NumberFormat.getFormat("#,##");
+                }
+                else {
+                    nf = NumberFormat.getFormat("#.##");
+                }
+                nf.parse(firstValues[i]);
+                f.setType(ListGridFieldType.FLOAT);
+            }
+            catch (NumberFormatException nfe) {
+                f.setType(ListGridFieldType.TEXT);
+            }
+
         }
 
         if (header.length == 2) {
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/LocationsTable.java	Thu Sep 15 14:48:31 2011 +0000
@@ -1,11 +1,15 @@
 package de.intevation.flys.client.client.ui.range;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.types.SelectionStyle;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import com.smartgwt.client.widgets.grid.CellFormatter;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.FLYSImages;
@@ -55,6 +59,25 @@
 
         ListGridField loc = new ListGridField("from", MSG.locations());
         loc.setType(ListGridFieldType.FLOAT);
+        loc.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
+
         loc.setWidth("12%");
 
         ListGridField bottom = new ListGridField("bottom", MSG.bottom_edge());
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/RangeTable.java	Thu Sep 15 12:55:36 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/range/RangeTable.java	Thu Sep 15 14:48:31 2011 +0000
@@ -1,11 +1,14 @@
 package de.intevation.flys.client.client.ui.range;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.types.SelectionStyle;
 import com.smartgwt.client.widgets.grid.ListGrid;
 import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.CellFormatter;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.client.FLYSImages;
@@ -45,10 +48,49 @@
         ddescr.setWidth("*");
         ListGridField from = new ListGridField("from", MESSAGES.from());
         from.setType(ListGridFieldType.FLOAT);
+        from.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
+
         from.setWidth("12%");
 
         ListGridField to = new ListGridField("to", MESSAGES.to());
         to.setType(ListGridFieldType.FLOAT);
+        to.setCellFormatter(new CellFormatter() {
+            public String format(
+                Object value,
+                ListGridRecord record,
+                int rowNum, int colNum) {
+                    if (value == null) return null;
+                    GWT.log((String)value);
+                    try {
+                        NumberFormat nf;
+                        double v = Double.parseDouble((String)value);
+                        nf = NumberFormat.getFormat("###0.00##");
+                        return nf.format(v);
+                    }
+                    catch (Exception e) {
+                        return value.toString();
+                    }
+                }
+            }
+        );
+
         to.setWidth("12%");
 
         ListGridField dside = new ListGridField(

http://dive4elements.wald.intevation.org