Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 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 | b6b2d9aad95d |
children | 65e369ac4f99 |
line wrap: on
line diff
--- 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()) {