# HG changeset patch # User Felix Wolfsteller # Date 1340811112 0 # Node ID 6461b8dbe0937693e52cddf646efd29dc549d099 # Parent 60c3751732630096536506aff6e09ffd28a7eb6a Added basic GUI for manual WSPs in cross sections. flys-client/trunk@4815 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 60c375173263 -r 6461b8dbe093 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 Wed Jun 27 06:52:54 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java Wed Jun 27 15:31:52 2012 +0000 @@ -336,6 +336,8 @@ String addPointsTooltip(); + String addWSPTooltip(); + String downloadPNGTooltip(); String downloadPDFTooltip(); @@ -913,6 +915,8 @@ String editpoints(); + String addWSP(); + String selection(); String fix_deltawt_export(); diff -r 60c375173263 -r 6461b8dbe093 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 Wed Jun 27 06:52:54 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties Wed Jun 27 15:31:52 2012 +0000 @@ -122,6 +122,7 @@ too_many_values = Only one value allowed addPointsTooltip = Add manual points +addWSPTooltip = Add manual LS downloadPNGTooltip = Download chart as PNG downloadPDFTooltip = Download chart as PDF downloadSVGTooltip = Download chart as SVG @@ -467,6 +468,7 @@ standby = Creating Artifact ... please wait. points = Points editpoints = Edit Points +addWSP = Add Manual LS selection = Selection # Reference Curves diff -r 60c375173263 -r 6461b8dbe093 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 Wed Jun 27 06:52:54 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties Wed Jun 27 15:31:52 2012 +0000 @@ -175,6 +175,7 @@ askThemeRemove = Sind Sie sicher, dass sie die gew\u00e4hlten / das gew\u00e4lte Thema l\u00f6eschen wollen? addPointsTooltip = Manuelle Punkte hinzuf\u00fcgen +addWSPTooltip = Manuelle WSP hinzuf\u00fcgen downloadPNGTooltip = Diagramm als PNG herunterladen downloadPDFTooltip = Diagramm als PDF herunterladen downloadSVGTooltip = Diagramm als SVG herunterladen @@ -467,6 +468,7 @@ standby = Erstelle Parameterisierung ... bitte warten. points = Punktthema editpoints = Eintr\u00e4ge editieren +addWSP = WSP Themen selection = Selektion # Reference Curves diff -r 60c375173263 -r 6461b8dbe093 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 Wed Jun 27 06:52:54 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties Wed Jun 27 15:31:52 2012 +0000 @@ -123,6 +123,7 @@ too_many_values = Only one value allowed addPointsTooltip = Add manual points +addWSPTooltip = Add manual LS downloadPNGTooltip = Download chart as PNG downloadPDFTooltip = Download chart as PDF downloadSVGTooltip = Download chart as SVG @@ -469,6 +470,7 @@ standby = Creating Artifact ... please wait. points = Points editpoints = Edit Points +addWSP = Add Manual LS selection = Selection # Reference Curves diff -r 60c375173263 -r 6461b8dbe093 flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Wed Jun 27 06:52:54 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartToolbar.java Wed Jun 27 15:31:52 2012 +0000 @@ -56,6 +56,8 @@ protected Button addPoints; + protected Button addWSP; + protected PanControl panControl; @@ -74,6 +76,17 @@ chartProperties = new ImgButton(); addPoints = new Button(MSG.points()); + if (this.chartTab.getMode().getName().equals("cross_section")) { + addWSP = new Button(MSG.addWSP()); + addWSP.setTooltip(MSG.addPointsTooltip()); + final ChartOutputTab finalChartTab = chartTab; + addWSP.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent ce) { + new ManualWSPEditor(finalChartTab.getView().getCollection(), + finalChartTab, finalChartTab.getMode().getName()).show(); + }}); + } + addPoints.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { openPointWindow(); @@ -233,6 +246,12 @@ addMember(panControl); addMember(chartProperties); addMember(addPoints); + + if (this.chartTab.getMode().getName().equals("cross_section")) { + // TODO i18n manual wsp + addMember(addWSP); + } + addMember(spacer); addMember(position); } diff -r 60c375173263 -r 6461b8dbe093 flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java Wed Jun 27 15:31:52 2012 +0000 @@ -0,0 +1,359 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.List; + +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +import com.smartgwt.client.util.SC; +import com.smartgwt.client.widgets.Window; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.IButton; +import com.smartgwt.client.widgets.Button; +import com.smartgwt.client.widgets.Label; +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.widgets.grid.CellEditValueParser; +import com.smartgwt.client.widgets.grid.CellEditValueFormatter; +import com.smartgwt.client.widgets.events.ClickEvent; +import com.smartgwt.client.widgets.events.ClickHandler; + +import com.smartgwt.client.types.Alignment; + +import de.intevation.flys.client.shared.model.Artifact; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.CollectionItem; + +import de.intevation.flys.client.client.services.LoadArtifactService; +import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; +import de.intevation.flys.client.client.services.FeedService; +import de.intevation.flys.client.client.services.FeedServiceAsync; + +import de.intevation.flys.client.shared.model.Data; +import de.intevation.flys.client.shared.model.DefaultArtifact; +import de.intevation.flys.client.shared.model.DefaultData; +import de.intevation.flys.client.shared.model.Recommendation; +import de.intevation.flys.client.shared.model.Settings; +import de.intevation.flys.client.shared.model.Property; +import de.intevation.flys.client.shared.model.PropertyGroup; +import de.intevation.flys.client.shared.model.StringProperty; + +import de.intevation.flys.client.client.event.RedrawRequestHandler; +import de.intevation.flys.client.client.event.RedrawRequestEvent; + +import com.smartgwt.client.widgets.form.DynamicForm; +import com.smartgwt.client.widgets.form.fields.FormItem; +import com.smartgwt.client.widgets.form.fields.TextItem; + + +/** + * UI to enter point data and save it to an PointArtifact. + */ +public class ManualWSPEditor +extends Window +implements ClickHandler +{ + /** The interface that provides i18n messages. */ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + /** Name of the main data item to be fed. */ + public static final String LINE_DATA = "manualpoints.lines"; + + /** When we chaged something, we need a RedrawRequest(Handler). */ + protected RedrawRequestHandler redrawRequestHandler; + + /** The collection */ + protected Collection collection; + + /** Service handle to clone and add artifacts to collection. */ + LoadArtifactServiceAsync loadArtifactService = GWT.create( + de.intevation.flys.client.client.services.LoadArtifactService.class); + + /** Service to feed the artifact with new point-data. */ + FeedServiceAsync feedService = GWT.create( + de.intevation.flys.client.client.services.FeedService.class); + + /** UUID of artifact to feed. */ + protected String uuid; + + /** Name of the outputmode, important when feeding data. */ + protected String outputModeName; + + /** Name of the data item for lines in this context. */ + protected String dataItemName; + + /** Input Field for y-coor of line. */ + protected TextItem valueInputPanel; + + /** Input Field for name of line. */ + protected TextItem nameInputPanel; + + /** Line data that is not added in this session. */ + protected JSONArray oldLines = null; + + + /** + * Setup editor dialog. + * @param collection The collection to use. + */ + public ManualWSPEditor(Collection collection, + RedrawRequestHandler handler, String outputModeName + ) { + this.collection = collection; + this.redrawRequestHandler = handler; + this.outputModeName = outputModeName; + this.dataItemName = outputModeName + "." + LINE_DATA; + init(); + } + + + /** Searches collection for first artifact to serve (manual) line data. */ + public String findManualPointsUUID() { + int size = collection.getItemLength(); + + for (int i = 0; i < size; i++) { + CollectionItem item = collection.getItem(i); + String dataValue = (String) item.getData().get(dataItemName); + if (dataValue != null) { + // Found it. + uuid = item.identifier(); + return uuid; + } + } + + return null; + } + + + /** + * Initialize the editor window and its components. + */ + protected void init() { + setTitle(MSG.addpoints()); + setCanDragReposition(true); + setCanDragResize(true); + + if(findManualPointsUUID() == null) { + addArtifactCreateUI(); + } + else { + createUI(); + } + } + + + /** Create and setup/add the ui. */ + public void createUI() { + Config config = Config.getInstance(); + + Button accept = new Button(MSG.label_ok()); + Button cancel = new Button(MSG.label_cancel()); + cancel.addClickHandler(this); + + accept.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent e) { + okClicked(); + } + }); + + HLayout buttons = new HLayout(); + buttons.addMember(accept); + buttons.addMember(cancel); + buttons.setAlign(Alignment.CENTER); + buttons.setHeight(30); + + DynamicForm form = new DynamicForm(); + valueInputPanel = new TextItem(); + valueInputPanel.setTitle("wsp"); + valueInputPanel.setShowTitle(false); + nameInputPanel = new TextItem(); + nameInputPanel.setTitle("name"); + nameInputPanel.setShowTitle(false); + form.setFields(valueInputPanel, nameInputPanel); + + VLayout layout = new VLayout(); + layout.addMember(form); + + // Use X and Y as default fallback. + String yAxis = "Y"; + + // Get header text from collection settings. + Settings settings = this.collection.getSettings(outputModeName); + List axes = settings.getSettings("axes"); + if(axes != null) { + for (Property p: axes) { + PropertyGroup pg = (PropertyGroup)p; + StringProperty id = + (StringProperty)pg.getPropertyByName("id"); + if (yAxis.equals("Y")) { + StringProperty name = + (StringProperty)pg.getPropertyByName("label"); + yAxis = name.getValue(); + } + } + } + + + // Find the artifacts uuid. + // TODO this has been called already, why call it again? + findManualPointsUUID(); + CollectionItem item = collection.getItem(uuid); + + // Store the old line data. + if (item != null) { + String jsonData = item.getData().get(dataItemName); + oldLines = (JSONArray) JSONParser.parse(jsonData); + } + else { + GWT.log("No old lines found for " + uuid); + } + + addItem(layout); + + addItem(buttons); + setWidth(380); + setHeight(470); + centerInPage(); + } + + + /** + * Create JSON representation of the points present in the form. + * Add old data, too. + * @return a jsonarray with the old and the new lines. + */ + protected JSONArray jsonArrayFromForm() { + if (oldLines == null) { + oldLines = new JSONArray(); + } + + int idx = 0; + double val; + if (valueInputPanel.getValue() == null) + return oldLines; + try { + NumberFormat nf = NumberFormat.getDecimalFormat(); + double d = nf.parse(valueInputPanel.getValue().toString()); + val = d; + } + catch(NumberFormatException nfe) { + SC.warn("fehler... nfe... TODO"); + return oldLines; + } + + JSONArray data = new JSONArray(); + data.set(0, new JSONNumber(val)); + if (nameInputPanel.getValue() == null) { + data.set(1, new JSONString(valueInputPanel.getValue().toString())); + } + else { + data.set(1, new JSONString(nameInputPanel.getValue().toString())); + } + oldLines.set(oldLines.size(), data); + + return oldLines; + } + + + /** + * Called when OK Button was clicked. Then, if entered values are valid, + * fire a RedrawRequest and destroy. + */ + protected void okClicked() { + // TODO proper validation (might use DynamicForm) + if (valueInputPanel.getValue() == null) { + // not valid... + //TODO + return; + } + GWT.log(valueInputPanel.getValue().toString()); + if(isDialogValid()) { + // Feed JSON-encoded content of form. + JSONArray list = jsonArrayFromForm(); + + Data[] feedData = new Data[] { + DefaultData.createSimpleStringData(dataItemName, + 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 lines."); + SC.warn(MSG.getString(caught.getMessage())); + enable(); + } + public void onSuccess(Artifact fartifact) { + GWT.log("Successfully set lines "); + redrawRequestHandler.onRedrawRequest( + new RedrawRequestEvent()); + destroy(); + } + }); + } + else { + GWT.log("Dialog not valid"); + SC.warn(MSG.error_dialog_not_valid()); + } + } + + + /** Add a ManualPointArtifact to Collection. */ + public void addArtifactCreateUI() { + final Label standByLabel = new Label(MSG.standby()); + addItem(standByLabel); + + setWidth(380); + setHeight(470); + centerInPage(); + + Config config = Config.getInstance(); + String locale = config.getLocale(); + + loadArtifactService.load( + this.collection, + new Recommendation("manualpoints", ""), + "manualpoints", + locale, + new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("Creating manualpoint artifact failed!"); + } + public void onSuccess(Artifact artifact) { + GWT.log("Successfully created artifact."); + removeItem(standByLabel); + uuid = artifact.getUuid(); + createUI(); + } + }); + } + + + /** + * This method is called when the user aborts point editing. + * @param event The event. + */ + public void onClick(ClickEvent event) { + this.destroy(); + } + + + /** Return false if x or y attribute is missing. */ + protected boolean isDialogValid() { + boolean valid = true; + // TODO implement + return valid; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :