Mercurial > dive4elements > river
changeset 3859:62332fa199bf
Work on "Date" support for ManualPointsEditor.
flys-client/trunk@5621 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Thu, 27 Sep 2012 14:09:24 +0000 |
parents | 87e7571970e6 |
children | b32e8353c30e |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java flys-client/src/main/java/de/intevation/flys/client/shared/model/MapMode.java flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java |
diffstat | 6 files changed, 132 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/ChangeLog Thu Sep 27 14:09:24 2012 +0000 @@ -1,3 +1,14 @@ +2012-09-27 Christian Lins <christian.lins@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java, + src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java, + src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java, + src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java: + Add "Date" support for Manual Points editor (not finished yet). + + * src/main/java/de/intevation/flys/client/shared/model/MapMode.java: + Add comment. + 2012-09-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/client/shared/model/MapMode.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Thu Sep 27 14:09:24 2012 +0000 @@ -72,6 +72,8 @@ /** The listGrid showing point entries. */ protected ListGrid listGrid; + protected ListGridFieldType fieldTypeX = ListGridFieldType.FLOAT; + /** Service handle to clone and add artifacts to collection. */ LoadArtifactServiceAsync loadArtifactService = GWT.create( de.intevation.flys.client.client.services.LoadArtifactService.class); @@ -170,52 +172,6 @@ listGrid.setCanEdit(true); listGrid.setShowHeaderContextMenu(false); - CellFormatter doubleFormat = new CellFormatter() { - public String format(Object value, ListGridRecord record, int rowNum, int colNum) { - if(value != null) { - NumberFormat nf = NumberFormat.getDecimalFormat(); - try { - double d = Double.valueOf(value.toString()).doubleValue(); - return nf.format(d); - } catch (Exception e) { - return value.toString(); - } - } else { - return null; - } - }}; - - CellEditValueParser cevp = new CellEditValueParser() { - public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { - if (value == null) - return null; - 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) { - if (value == null) { - return ""; - } - 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"; @@ -226,6 +182,7 @@ if(axes != null) { for (Property p: axes) { PropertyGroup pg = (PropertyGroup)p; + GWT.log(pg.toString()); StringProperty id = (StringProperty)pg.getPropertyByName("id"); if(id.getValue().equals("X")) { @@ -240,18 +197,29 @@ } } } + + CellFormatter format = createCellFormatter(); + CellEditValueParser cevp = createCellEditValueParser(); + CellEditValueFormatter cevf = createCellEditValueFormatter(); + ListGridField xField = - new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); - xField.setType(ListGridFieldType.FLOAT); - xField.setCellFormatter(doubleFormat); - xField.setEditValueParser(cevp); - xField.setEditValueFormatter(cevf); - + new ListGridField(PointRecord.ATTRIBUTE_X, xAxis); + if(xAxis.equalsIgnoreCase("date") || xAxis.equalsIgnoreCase("Datum")) { + // FIXME: This is a hack for the special axis with Date type + xField.setType(ListGridFieldType.DATE); + this.fieldTypeX = ListGridFieldType.DATE; + } + else { + xField.setType(ListGridFieldType.FLOAT); + xField.setCellFormatter(format); + xField.setEditValueParser(cevp); + xField.setEditValueFormatter(cevf); + } ListGridField yField = new ListGridField(PointRecord.ATTRIBUTE_Y, yAxis); yField.setType(ListGridFieldType.FLOAT); - yField.setCellFormatter(doubleFormat); + yField.setCellFormatter(format); yField.setEditValueParser(cevp); yField.setEditValueFormatter(cevf); @@ -326,6 +294,61 @@ } + protected CellFormatter createCellFormatter() { + return new CellFormatter() { + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + if(value != null) { + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } catch (Exception e) { + return value.toString(); + } + } else { + return null; + } + }}; + } + + + protected CellEditValueParser createCellEditValueParser() { + return new CellEditValueParser() { + public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) + return null; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(value.toString()); + return (new Double(d)).toString(); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + } + + + protected CellEditValueFormatter createCellEditValueFormatter() { + return new CellEditValueFormatter() { + public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) { + return ""; + } + NumberFormat nf = NumberFormat.getDecimalFormat(); + try { + double d = Double.valueOf(value.toString()).doubleValue(); + return nf.format(d); + } + catch(NumberFormatException nfe) { + return value; + } + } + }; + } + + /** Create JSON representation of the points present in the list grid. */ protected JSONArray jsonArrayFromListGrid() { JSONArray list = new JSONArray(); @@ -357,8 +380,13 @@ nameString = xString + "/" + yString; } - data.set(0, new JSONNumber(record. - getAttributeAsDouble(PointRecord.ATTRIBUTE_X))); + if(fieldTypeX.equals(ListGridFieldType.DATE)) { + data.set(0, new JSONString(record.getAttribute(PointRecord.ATTRIBUTE_X))); + } + else { + 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)); @@ -471,8 +499,6 @@ protected static final String ATTRIBUTE_NAME = "name"; protected static final String ATTRIBUTE_ACTIVE = "active"; - private PointRecord() {;} - public PointRecord(boolean b, double x, double y, String name) { setActive(b); setName(name); @@ -518,9 +544,14 @@ protected boolean isDialogValid() { boolean valid = true; for (ListGridRecord record : listGrid.getRecords()) { - if (record.getAttributeAsDouble(PointRecord.ATTRIBUTE_X) == null - || record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) { - return false; + try { + if (record.getAttribute(PointRecord.ATTRIBUTE_X) == null + || record.getAttribute(PointRecord.ATTRIBUTE_Y) == null) { + return false; + } + } + catch(IllegalArgumentException ex) { + } } if (listGrid.hasErrors()) {
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleProperty.java Thu Sep 27 14:09:24 2012 +0000 @@ -1,10 +1,10 @@ package de.intevation.flys.client.shared.model; +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + import java.util.HashMap; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.core.client.GWT; - /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ @@ -74,6 +74,7 @@ return nf.format(dv); } + @Override public Object clone() { DoubleProperty clone = new DoubleProperty(this.getName(), this.getValue()); @@ -82,5 +83,4 @@ } return clone; } - }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapMode.java Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/MapMode.java Thu Sep 27 14:09:24 2012 +0000 @@ -12,6 +12,9 @@ */ public class MapMode extends DefaultOutputMode { + /** + * Default constructor required for serialization. + */ public MapMode() { }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertyGroup.java Thu Sep 27 14:09:24 2012 +0000 @@ -1,9 +1,10 @@ package de.intevation.flys.client.shared.model; +import java.util.ArrayList; import java.util.List; -import java.util.ArrayList; /** + * A group of properties. * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public class PropertyGroup implements Property, Cloneable { @@ -14,7 +15,6 @@ protected List<Property> properties; public PropertyGroup() { - } public PropertyGroup(String name) { @@ -51,7 +51,7 @@ return null; } - + @Override public Object clone() { PropertyGroup clone = new PropertyGroup(this.getName()); List<Property> cloneList = new ArrayList<Property>(); @@ -61,4 +61,20 @@ clone.setProperties(cloneList); return clone; } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder(); + + for(Property p : properties) { + buf.append(p.getName()); + buf.append("="); + if(p instanceof PropertySetting) { + buf.append(((PropertySetting)p).getValue().toString()); + } + buf.append(" "); + } + + return buf.toString(); + } }
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Sep 27 09:39:12 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/PropertySetting.java Thu Sep 27 14:09:24 2012 +0000 @@ -1,7 +1,8 @@ package de.intevation.flys.client.shared.model; +import java.util.ArrayList; import java.util.HashMap; -import java.util.ArrayList; +import java.util.List; /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> @@ -63,11 +64,11 @@ return attributes.get(key); } - public ArrayList<String> getAttributeList() { + public List<String> getAttributeList() { return new ArrayList<String>(attributes.keySet()); } - + @Override public Object clone() { PropertySetting clone = new PropertySetting(this.getName(), this.getValue().toString());