changeset 1562:af29d43cf4da

Added basic validation, improved editing function, minor refac. flys-client/trunk@3808 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 27 Jan 2012 15:43:02 +0000
parents 3cf3cd8dd92d
children 41abc345d2f1
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java
diffstat 2 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Fri Jan 27 15:24:04 2012 +0000
+++ b/flys-client/ChangeLog	Fri Jan 27 15:43:02 2012 +0000
@@ -1,3 +1,9 @@
+2012-01-27  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java:
+	  Added basic validation and improved editing function to manual point
+	  editor. Minor refac.
+
 2012-01-27  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java	Fri Jan 27 15:24:04 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java	Fri Jan 27 15:43:02 2012 +0000
@@ -21,6 +21,8 @@
 import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
 import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
 import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.google.gwt.i18n.client.NumberFormat;
 
 import com.smartgwt.client.widgets.form.DynamicForm;
 
@@ -170,17 +172,20 @@
                         else {
                             JSONArray data = new JSONArray();
 
-                            // TODO better get double directly (via cell-formatter etc)
-                            // TODO finalize the X, Y etc.
-                            String xString = record.getAttributeAsString("X");
-                            String yString = record.getAttributeAsString("Y");
                             String nameString = record.getAttributeAsString("name");
+                            // Apply default name if none set.
                             if (nameString == null || nameString.equals("")) {
+                                String xString = record.getAttributeAsString(
+                                    PointRecord.ATTRIBUTE_X);
+                                String yString = record.getAttributeAsString(
+                                    PointRecord.ATTRIBUTE_Y);
                                 nameString = xString + "/" + yString;
                             }
 
-                            data.set(0, new JSONNumber(Double.valueOf(xString)));
-                            data.set(1, new JSONNumber(Double.valueOf(yString)));
+                            data.set(0, new JSONNumber(record.
+                                getAttributeAsDouble(PointRecord.ATTRIBUTE_X)));
+                            data.set(1, new JSONNumber(record.
+                                getAttributeAsDouble(PointRecord.ATTRIBUTE_Y)));
                             data.set(2, new JSONString(nameString));
 
                             list.set(idx, data);
@@ -234,11 +239,24 @@
 
         // TODO X and Y Header depend on the current chart and axis (e.g. W[nn+m])
         // collection.getSettings(outputName).getSettings -> Propertie -> "axis" -> "label"
-        ListGridField xField = new ListGridField("X", "X");
+        ListGridField xField = new ListGridField(PointRecord.ATTRIBUTE_X, "X");
         xField.setType(ListGridFieldType.FLOAT);
-        ListGridField yField = new ListGridField("Y", "Y");
+        xField.setCellFormatter(new CellFormatter() {
+            public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
+                if(value != null) {
+                    NumberFormat nf = NumberFormat.getFormat("#.##");
+                    try {
+                        return nf.format(((Number) value).doubleValue());
+                    } catch (Exception e) {
+                        return value.toString();
+                    }
+                } else {
+                   return null;
+                }
+            }});
+        ListGridField yField = new ListGridField(PointRecord.ATTRIBUTE_Y, "Y");
         yField.setType(ListGridFieldType.FLOAT);
-        ListGridField nameField = new ListGridField("name",
+        ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME,
             MSG.pointname());
         final ListGridField removeField  =
             new ListGridField("_removeRecord", MSG.removepoint()){{

http://dive4elements.wald.intevation.org