Mercurial > dive4elements > river
changeset 3983:65e369ac4f99
ManualPointsEditor supports Date x axis values.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 29 Sep 2012 11:38:38 +0200 |
parents | f9729662f1be |
children | 89d7e97e9c9a |
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/client/ui/chart/PointRecord.java flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java |
diffstat | 4 files changed, 155 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Sep 28 20:51:41 2012 +0200 +++ b/flys-client/ChangeLog Sat Sep 29 11:38:38 2012 +0200 @@ -1,3 +1,10 @@ +2012-09-29 Christian Lins <christian.lins@intevation.de> + + * flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java, + flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java + flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PointRecord.java: + ManualPointsEditor supports Date x axis values. + 2012-09-29 Björn Ricks <bjoern.ricks@intevation.de> * src/main/java/de/intevation/flys/client/server/ArtifactServiceImpl.java,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Fri Sep 28 20:51:41 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Sat Sep 29 11:38:38 2012 +0200 @@ -1,6 +1,7 @@ package de.intevation.flys.client.client.ui.chart; import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONBoolean; @@ -47,6 +48,7 @@ import de.intevation.flys.client.shared.model.Settings; import de.intevation.flys.client.shared.model.StringProperty; +import java.util.Date; import java.util.List; @@ -153,6 +155,7 @@ cancel.addClickHandler(this); accept.addClickHandler(new ClickHandler() { + @Override public void onClick(ClickEvent e) { okClicked(); } @@ -176,7 +179,7 @@ String xAxis = "X"; String yAxis = "Y"; - // Get header text from collection settings. + // Get header text from collection settings Settings settings = this.collection.getSettings(outputModeName); List<Property> axes = settings.getSettings("axes"); if(axes != null) { @@ -205,7 +208,7 @@ ListGridField xField = 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 + // FIXME: This is a hack for Timeseries charts with Date types on the x axis xField.setType(ListGridFieldType.DATE); this.fieldTypeX = ListGridFieldType.DATE; } @@ -246,6 +249,7 @@ nameField, removeField}); listGrid.addRecordClickHandler(new RecordClickHandler() { + @Override public void onRecordClick(final RecordClickEvent event) { // Just handle remove-clicks if(!event.getField().getName().equals(removeField.getName())) { @@ -255,28 +259,28 @@ } }); - // Find the artifacts uuid. + // Find the artifacts uuid findManualPointsUUID(); CollectionItem item = collection.getItem(uuid); - // Add points to grid. + // Add points to grid if (item != null) { // TODO store this from findPointUUID instead (we touched these). String jsonData = item.getData().get(pointDataItemName); JSONArray jsonArray = (JSONArray) JSONParser.parse(jsonData); for (int i = 0; i < jsonArray.size(); i++) { JSONArray point = (JSONArray) jsonArray.get(i); - listGrid.addData(pointRecordFromJSON(point)); + listGrid.addData(PointRecord.fromJSON(point)); } } else { - // TODO proper log - System.out.println("No item found for " + uuid); + GWT.log("ManualPointsEditor: No item found for " + uuid); } IButton button = new IButton(MSG.newpoint()); button.setTop(250); button.addClickHandler(new ClickHandler() { + @Override public void onClick(ClickEvent event) { listGrid.startEditingNew(); } @@ -296,6 +300,7 @@ protected CellFormatter createCellFormatter() { return new CellFormatter() { + @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if(value != null) { NumberFormat nf = NumberFormat.getDecimalFormat(); @@ -314,6 +319,7 @@ protected CellEditValueParser createCellEditValueParser() { return new CellEditValueParser() { + @Override public Object parse(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) return null; @@ -332,6 +338,7 @@ protected CellEditValueFormatter createCellEditValueFormatter() { return new CellEditValueFormatter() { + @Override public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return ""; @@ -348,6 +355,20 @@ }; } + protected String getLocaleDateFormat() { + String loc = Config.getInstance().getLocale(); + if ("de".equals(loc)) { + return "yy.MM.yyyy"; + } + else { + return "MM/dd/yyyy"; + } + } + + protected String formatDate(Date date) { + DateTimeFormat dtf = DateTimeFormat.getFormat(getLocaleDateFormat()); + return dtf.format(date); + } /** Create JSON representation of the points present in the list grid. */ protected JSONArray jsonArrayFromListGrid() { @@ -359,7 +380,13 @@ JSONArray data = new JSONArray(); PointRecord point = (PointRecord) record; - data.set(0, new JSONNumber(point.getX())); + if(point.isTimeseriesPoint()) { + data.set(0, new JSONString(point.getXAsDate())); + GWT.log("Date: " + point.getXAsDate()); + } + else { + data.set(0, new JSONNumber(point.getX())); + } data.set(1, new JSONNumber(point.getY())); data.set(2, new JSONString(point.getName())); data.set(3, JSONBoolean.getInstance(point.isActive())); @@ -381,7 +408,9 @@ } if(fieldTypeX.equals(ListGridFieldType.DATE)) { - data.set(0, new JSONString(record.getAttribute(PointRecord.ATTRIBUTE_X))); + Date date = record.getAttributeAsDate(PointRecord.ATTRIBUTE_X); + data.set(0, new JSONString(formatDate(date))); + GWT.log("Date: " + formatDate(date)); } else { data.set(0, new JSONNumber(record. @@ -420,11 +449,13 @@ new DefaultArtifact(uuid, "TODO:hash"), feedData, new AsyncCallback<Artifact>() { + @Override public void onFailure(Throwable caught) { GWT.log("Could not feed artifact with points."); SC.warn(MSG.getString(caught.getMessage())); enable(); } + @Override public void onSuccess(Artifact fartifact) { GWT.log("Successfully set points"); redrawRequestHandler.onRedrawRequest( @@ -440,18 +471,6 @@ } - /** From a JSON-encoded point, create a PointRecord. */ - public PointRecord pointRecordFromJSON(JSONArray jsonArray) { - JSONNumber x = (JSONNumber) jsonArray.get(0); - JSONNumber y = (JSONNumber) jsonArray.get(1); - JSONString s = (JSONString) jsonArray.get(2); - JSONBoolean b = (JSONBoolean) jsonArray.get(3); - - return new PointRecord(b.booleanValue(), x.doubleValue(), - y.doubleValue(), s.stringValue()); - } - - /** Add a ManualPointArtifact to Collection. */ public void addArtifactCreateUI() { final Label standByLabel = new Label(MSG.standby()); @@ -470,9 +489,11 @@ "manualpoints", locale, new AsyncCallback<Artifact>() { + @Override public void onFailure(Throwable caught) { GWT.log("Creating manualpoint artifact failed!"); } + @Override public void onSuccess(Artifact artifact) { GWT.log("Successfully created artifact."); removeItem(standByLabel); @@ -487,59 +508,12 @@ * This method is called when the user aborts point editing. * @param event The event. */ + @Override public void onClick(ClickEvent event) { this.destroy(); } - /** Simple record to store points. */ - public class PointRecord extends ListGridRecord { - protected static final String ATTRIBUTE_X = "X"; - protected static final String ATTRIBUTE_Y = "Y"; - protected static final String ATTRIBUTE_NAME = "name"; - protected static final String ATTRIBUTE_ACTIVE = "active"; - - public PointRecord(boolean b, double x, double y, String name) { - setActive(b); - setName(name); - setX(x); - setY(y); - } - - public void setActive(boolean b) { - setAttribute(ATTRIBUTE_ACTIVE, b); - } - - public boolean isActive() { - return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); - } - - public void setName(String name) { - setAttribute(ATTRIBUTE_NAME, name); - } - - public String getName() { - return getAttributeAsString(ATTRIBUTE_NAME); - } - - public void setX(double x) { - setAttribute(ATTRIBUTE_X, x); - } - - public void setY(double y) { - setAttribute(ATTRIBUTE_Y, y); - } - - public double getX() { - return getAttributeAsDouble(ATTRIBUTE_X); - } - - public double getY() { - return getAttributeAsDouble(ATTRIBUTE_Y); - } - } - - /** Return false if x or y attribute is missing. */ protected boolean isDialogValid() { boolean valid = true;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PointRecord.java Sat Sep 29 11:38:38 2012 +0200 @@ -0,0 +1,105 @@ +package de.intevation.flys.client.client.ui.chart; + +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONBoolean; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; + +import com.smartgwt.client.widgets.grid.ListGridRecord; + +/** Simple record to store points. */ +public class PointRecord extends ListGridRecord { + protected static final String ATTRIBUTE_X = "X"; + protected static final String ATTRIBUTE_Y = "Y"; + protected static final String ATTRIBUTE_NAME = "name"; + protected static final String ATTRIBUTE_ACTIVE = "active"; + + /** From a JSON-encoded point, create a PointRecord. */ + public static PointRecord fromJSON(JSONArray jsonArray) { + JSONValue x = jsonArray.get(0); + JSONNumber y = (JSONNumber) jsonArray.get(1); + JSONString s = (JSONString) jsonArray.get(2); + JSONBoolean b = (JSONBoolean)jsonArray.get(3); + + if(x instanceof JSONNumber) { + return new PointRecord( + b.booleanValue(), ((JSONNumber)x).doubleValue(), + y.doubleValue(), s.stringValue()); + } + else { + return new PointRecord( + b.booleanValue(), ((JSONString)x).stringValue(), + y.doubleValue(), s.stringValue()); + } + } + + protected boolean isTimeseriesPoint = false; + + public PointRecord(boolean isActive, double x, double y, String name) { + setActive(isActive); + setName(name); + setX(x); + setY(y); + } + + /** + * Constructor taking the x axis value as String representing a Date value. + * @param isActive + * @param x + * @param y + * @param name + */ + public PointRecord(boolean isActive, String x, double y, String name) { + setActive(isActive); + setName(name); + setX(x); + setY(y); + + this.isTimeseriesPoint = true; + } + + public void setActive(boolean isActive) { + setAttribute(ATTRIBUTE_ACTIVE, isActive); + } + + public boolean isActive() { + return getAttributeAsBoolean(ATTRIBUTE_ACTIVE); + } + + public boolean isTimeseriesPoint() { + return this.isTimeseriesPoint; + } + + public void setName(String name) { + setAttribute(ATTRIBUTE_NAME, name); + } + + public String getName() { + return getAttributeAsString(ATTRIBUTE_NAME); + } + + public void setX(double x) { + setAttribute(ATTRIBUTE_X, x); + } + + public void setX(String date) { + setAttribute(ATTRIBUTE_X, date); + } + + public void setY(double y) { + setAttribute(ATTRIBUTE_Y, y); + } + + public double getX() { + return getAttributeAsDouble(ATTRIBUTE_X); + } + + public String getXAsDate() { + return getAttributeAsString(ATTRIBUTE_X); + } + + public double getY() { + return getAttributeAsDouble(ATTRIBUTE_Y); + } +} \ No newline at end of file
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Fri Sep 28 20:51:41 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Sat Sep 29 11:38:38 2012 +0200 @@ -11,7 +11,6 @@ import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; -import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; @@ -168,16 +167,6 @@ return false; } - protected String getLocaleDateFormat() { - String loc = Config.getInstance().getLocale(); - if ("de".equals(loc)) { - return "yy.MM.yyyy"; - } - else { - return "MM/dd/yyyy"; - } - } - @Override public void success() { List<FixEvent> list = fixInfo.getEvents();