# HG changeset patch # User Felix Wolfsteller # Date 1327681585 0 # Node ID 41abc345d2f186255e83987e3b12fc4fed1ef562 # Parent af29d43cf4da63cd6bfcc5da1c2f7f7481d7452a Added dummy handling for new boolean property of each point. flys-client/trunk@3810 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r af29d43cf4da -r 41abc345d2f1 flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Jan 27 15:43:02 2012 +0000 +++ b/flys-client/ChangeLog Fri Jan 27 16:26:25 2012 +0000 @@ -1,3 +1,15 @@ +2012-01-27 Felix Wolfsteller + + * src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java: + Added dummy handling for new boolean 'active' flag of each point. + Refactoring. + + * src/main/java/de/intevation/flys/client/client/FLYSConstants.java, + src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties, + src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties: + Added translations for manual points related words. + 2012-01-27 Felix Wolfsteller * src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java: diff -r af29d43cf4da -r 41abc345d2f1 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Jan 27 15:43:02 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Fri Jan 27 16:26:25 2012 +0000 @@ -740,5 +740,7 @@ String points(); String editpoints(); + + String selection(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r af29d43cf4da -r 41abc345d2f1 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Jan 27 15:43:02 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Fri Jan 27 16:26:25 2012 +0000 @@ -386,3 +386,4 @@ standby = Creating Artifact ... please wait. points = Points editpoints = Edit Points +selection = Selection diff -r af29d43cf4da -r 41abc345d2f1 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Jan 27 15:43:02 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Fri Jan 27 16:26:25 2012 +0000 @@ -386,4 +386,5 @@ standby = Erstelle Parameterisierung ... bitte warten. points = Punktthema editpoints = Eintr\u00e4ge editieren +selection = Selektion diff -r af29d43cf4da -r 41abc345d2f1 flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties --- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Jan 27 15:43:02 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Fri Jan 27 16:26:25 2012 +0000 @@ -386,4 +386,5 @@ standby = Creating Artifact ... please wait. points = Points editpoints = Edit Points +selection = Selection diff -r af29d43cf4da -r 41abc345d2f1 flys-client/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:43:02 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java Fri Jan 27 16:26:25 2012 +0000 @@ -1,6 +1,7 @@ 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.JSONParser; import com.google.gwt.json.client.JSONString; @@ -151,75 +152,7 @@ // TODO refactor. accept.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { - if(isDialogValid()) { - // Feed JSON-encoded content of listgrid. - String jsonString = ""; - int idx = 0; - JSONArray list = new JSONArray(); - - for(ListGridRecord record : listGrid.getRecords()) { - if (record instanceof PointRecord) { - JSONArray data = new JSONArray(); - - PointRecord point = (PointRecord) record; - data.set(0, new JSONNumber(point.getX())); - data.set(1, new JSONNumber(point.getY())); - data.set(2, new JSONString(point.getName())); - - list.set(idx, data); - idx++; - } - else { - JSONArray data = new JSONArray(); - - 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(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); - idx++; - } - } - - // Feed list.toString to respective artifact. - Data[] feedData = new Data[] { - DefaultData.createSimpleStringData(POINT_DATA, - list.toString()) - }; - feedService.feed( - Config.getInstance().getLocale(), - new DefaultArtifact(uuid, "TODO:hash"), - feedData, - new AsyncCallback() { - public void onFailure(Throwable caught) { - GWT.log("Could not feed artifact with points."); - SC.warn(MSG.getString(caught.getMessage())); - enable(); - } - public void onSuccess(Artifact fartifact) { - GWT.log("Successfully set points "); - redrawRequestHandler.onRedrawRequest( - new RedrawRequestEvent()); - destroy(); - } - }); - } - else { - GWT.log("Dialog not valid"); - SC.warn(MSG.error_dialog_not_valid()); - } + okClicked(); } }); @@ -237,11 +170,7 @@ listGrid.setCanEdit(true); listGrid.setShowHeaderContextMenu(false); - // 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(PointRecord.ATTRIBUTE_X, "X"); - xField.setType(ListGridFieldType.FLOAT); - xField.setCellFormatter(new CellFormatter() { + CellFormatter doubleFormat = new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if(value != null) { NumberFormat nf = NumberFormat.getFormat("#.##"); @@ -253,9 +182,19 @@ } else { return null; } - }}); + }}; + + // 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(PointRecord.ATTRIBUTE_X, "X"); + xField.setType(ListGridFieldType.FLOAT); + xField.setCellFormatter(doubleFormat); + ListGridField yField = new ListGridField(PointRecord.ATTRIBUTE_Y, "Y"); yField.setType(ListGridFieldType.FLOAT); + yField.setCellFormatter(doubleFormat); + ListGridField nameField = new ListGridField(PointRecord.ATTRIBUTE_NAME, MSG.pointname()); final ListGridField removeField = @@ -270,7 +209,11 @@ setWidth(25); }}; - listGrid.setFields(new ListGridField[] {xField, yField, + ListGridField activeField = new ListGridField( + PointRecord.ATTRIBUTE_ACTIVE, MSG.selection()); + activeField.setType(ListGridFieldType.BOOLEAN); + + listGrid.setFields(new ListGridField[] {activeField, xField, yField, nameField, removeField}); listGrid.addRecordClickHandler(new RecordClickHandler() { @@ -321,12 +264,102 @@ } + /** Create JSON representation of the points present in the list grid. */ + protected JSONArray jsonArrayFromListGrid() { + JSONArray list = new JSONArray(); + int idx = 0; + + for(ListGridRecord record : listGrid.getRecords()) { + if (record instanceof PointRecord) { + JSONArray data = new JSONArray(); + + PointRecord point = (PointRecord) record; + 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())); + + list.set(idx, data); + idx++; + } + else { + JSONArray data = new JSONArray(); + + 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(record. + getAttributeAsDouble(PointRecord.ATTRIBUTE_X))); + data.set(1, new JSONNumber(record. + getAttributeAsDouble(PointRecord.ATTRIBUTE_Y))); + data.set(2, new JSONString(nameString)); + data.set(3, JSONBoolean.getInstance(record.getAttributeAsBoolean( + PointRecord.ATTRIBUTE_ACTIVE))); + + list.set(idx, data); + idx++; + } + } + return list; + } + + + /** + * Called when OK Button was clicked. Then, if entered values are valid, + * fire a RedrawRequest and destroy. + */ + protected void okClicked() { + if(isDialogValid()) { + // Feed JSON-encoded content of listgrid. + JSONArray list = jsonArrayFromListGrid(); + + Data[] feedData = new Data[] { + DefaultData.createSimpleStringData(POINT_DATA, + list.toString()) + }; + + feedService.feed( + Config.getInstance().getLocale(), + new DefaultArtifact(uuid, "TODO:hash"), + feedData, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Could not feed artifact with points."); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + public void onSuccess(Artifact fartifact) { + GWT.log("Successfully set points "); + redrawRequestHandler.onRedrawRequest( + new RedrawRequestEvent()); + destroy(); + } + }); + } + else { + // TODO i18n? + GWT.log("Dialog not valid"); + SC.warn(MSG.error_dialog_not_valid()); + } + } + + /** 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); - return new PointRecord(x.doubleValue(), y.doubleValue(), s.stringValue()); + 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()); } @@ -379,7 +412,8 @@ private PointRecord() {;} - public PointRecord(double x, double y, String name) { + public PointRecord(boolean b, double x, double y, String name) { + setActive(b); setName(name); setX(x); setY(y);