# HG changeset patch # User Raimund Renkert # Date 1338546434 0 # Node ID 88bca9f735c0acfee87cc84897b70a9e1bbec2ca # Parent c3feb721035c90d488087b1a3d311186a958a1f6 Implemented filter for fix analysis helper widgets. flys-client/trunk@4567 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c3feb721035c -r 88bca9f735c0 flys-client/ChangeLog --- a/flys-client/ChangeLog Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/ChangeLog Fri Jun 01 10:27:14 2012 +0000 @@ -1,3 +1,20 @@ +2012-06-01 Raimund Renkert + + * src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java: + Added filter to artifact. The artifact extracts old state data to create the + filter. + + * src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java: + Implemented filter object. + + * src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java, + src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java: + Removed getter and setter for filter object. Moved filter to fix artifact. + 2012-05-30 Raimund Renkert * src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java: diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixEventSelect.java Fri Jun 01 10:27:14 2012 +0000 @@ -113,7 +113,6 @@ IntegerArrayData iad = new IntegerArrayData("events", "events", arr); - fixFilter.setEvents(iad.getValues()); data.add(iad); } @@ -141,15 +140,6 @@ } - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - public void success() {} public void dumpGWT(String cid) { diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixGaugeSelectPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -155,15 +155,6 @@ } - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - public void success() {} protected boolean saveClassValues() { @@ -175,9 +166,6 @@ if (v1i <= v2i) { this.first = v1; this.second = v2; - - this.fixFilter.setFromClass(v1i); - this.fixFilter.setToClass(v2i); return true; } } diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixLocationPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -23,7 +23,7 @@ import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; - +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; /** * This UIProvider creates a panel for location or distance input. * @@ -123,8 +123,6 @@ boolean valid = saveRangeValues(inputPanel); if (valid) { - this.fixFilter.setFromKm(this.from); - this.fixFilter.setToKm(this.to); String f = Double.valueOf(this.from).toString(); String t = Double.valueOf(this.to).toString(); String s = Double.valueOf(this.step).toString(); @@ -166,15 +164,6 @@ } - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - public void success() { inputPanel.setValues(fixInfo.getFrom(), fixInfo.getTo(), 100d); } diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixMultiPeriodPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -193,16 +193,6 @@ } - - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - protected boolean saveDateValues() { ListGridRecord[] lgr = elements.getRecords(); if (lgr.length == 0) { diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixPeriodPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -137,8 +137,6 @@ boolean valid = saveDateValues(); if(valid) { - this.fixFilter.setFromDate(this.start); - this.fixFilter.setToDate(this.end); String start = Long.valueOf(this.start).toString(); String end = Long.valueOf(this.end).toString(); DataItem startItem = new DefaultDataItem(startName, startName, start); @@ -172,15 +170,6 @@ } - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - public void success() {} protected boolean saveDateValues() { diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixQSelectPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -64,14 +64,5 @@ } - public void setFilter(FixFilter filter) { - this.fixFilter = filter; - } - - - public FixFilter getFilter() { - return this.fixFilter; - } - public void success() {} } diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java Fri Jun 01 10:27:14 2012 +0000 @@ -1,13 +1,23 @@ package de.intevation.flys.client.client.ui.fixation; import java.util.HashMap; +import java.util.Date; + import java.lang.Math; +import java.io.Serializable; import java.lang.NumberFormatException; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONObject; +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.i18n.client.DateTimeFormat; + import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; @@ -38,6 +48,7 @@ import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.FixingsOverviewInfo; +import de.intevation.flys.client.shared.model.FixAnalysisArtifact; import de.intevation.flys.client.client.services.FixingsOverviewService; import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; @@ -63,7 +74,6 @@ protected String htmlOverview; protected FixingsOverviewInfo fixInfo; - protected FixFilter fixFilter; protected TabSet tabs; protected Tab events; protected Tab chart; @@ -71,7 +81,7 @@ protected Img chartImg; public FixationPanel() { - fixFilter = new FixFilter(); + GWT.log("new filter"); chartImg = new Img(); htmlOverview = ""; } @@ -127,18 +137,20 @@ final HTMLPane eventPane = new HTMLPane(); String river = artifact.getArtifactDescription().getRiver(); - fixFilter.setRiver(river); createCallback(); /* Filter example. -{"fixings": { "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }} +{"fixings": "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }} */ String callBack = "fixationCallback(this.checked, this.name)"; + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + GWT.log(art.getFilter().getOverviewFilter()); overviewService.generateOverview( locale, artifact.getUuid(), - fixFilter.getOverviewFilter(), + art.getFilter().getOverviewFilter(), renderCheckboxes(), callBack, new AsyncCallback() { @@ -150,10 +162,11 @@ GWT.log("Successfully loaded overview."); fixInfo = info; htmlOverview = info.getHTML(); - fixFilter.setRiver(info.getRiver()); - fixFilter.setCurrentKm(1d); - fixFilter.setFromKm(info.getFrom()); - fixFilter.setToKm(info.getTo()); + FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; + art.getFilter().setRiver(info.getRiver()); + art.getFilter().setCurrentKm(1d); + art.getFilter().setFromKm(info.getFrom()); + art.getFilter().setToKm(info.getTo()); eventPane.setContents(htmlOverview); updateChartTab(fixInfo.getFrom()); events.setPane(eventPane); @@ -186,14 +199,16 @@ lower.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { updateChartTabLow(); - currentkm.setValue(fixFilter.getCurrentKm()); + FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; + currentkm.setValue(art.getFilter().getCurrentKm()); } }); upper.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { updateChartTabUp(); - currentkm.setValue(fixFilter.getCurrentKm()); + FixAnalysisArtifact art = (FixAnalysisArtifact) artifact; + currentkm.setValue(art.getFilter().getCurrentKm()); } }); @@ -226,12 +241,20 @@ Config config = Config.getInstance(); String locale = config.getLocale (); - fixFilter.setCurrentKm(km); - chartContainer.removeMember(chartImg); + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + GWT.log("km: " + km); + if (km < 0) { + km = 0; + } + GWT.log("km: " + km); + art.getFilter().setCurrentKm(km); + if (chartContainer.hasMember(chartImg)) { + chartContainer.removeMember(chartImg); + } String imgUrl = GWT.getModuleBaseURL(); imgUrl += "fixings-km-chart"; imgUrl += "?locale=" + locale; - imgUrl += "&filter=" + fixFilter.getChartFilter(helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12); + imgUrl += "&filter=" + art.getFilter().getChartFilter(helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12); chartImg = new Img(imgUrl, helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12); chartContainer.addMember(chartImg); @@ -240,8 +263,10 @@ protected void updateChartTabLow() { - double curr = fixFilter.getCurrentKm(); - if (curr > fixFilter.getFromKm()) { + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + double curr = art.getFilter().getCurrentKm(); + if (curr > art.getFilter().getFromKm()) { double newVal = (curr - 0.1) * 10; long round = Math.round(newVal); updateChartTab(((double)round) / 10); @@ -251,8 +276,10 @@ protected void updateChartTabUp() { - double curr = fixFilter.getCurrentKm(); - if (curr < fixFilter.getToKm()) { + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + double curr = art.getFilter().getCurrentKm(); + if (curr < art.getFilter().getToKm()) { double newVal = (curr + 0.1) * 10; long round = Math.round(newVal); updateChartTab(((double)round) / 10); @@ -262,7 +289,9 @@ public void onResized(ResizedEvent re) { - updateChartTab(fixFilter.getCurrentKm()); + FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; + + updateChartTab(art.getFilter().getCurrentKm()); } @@ -292,11 +321,9 @@ public abstract Canvas createWidget(DataList data); public abstract void setValues(String cid, boolean checked); public abstract boolean renderCheckboxes(); - public abstract FixFilter getFilter(); - public abstract void setFilter(FixFilter filter); public abstract void success(); - public static class FixFilter { + public static class FixFilter implements Serializable{ protected String river; protected double fromKm; protected double toKm; @@ -396,33 +423,100 @@ } public String getOverviewFilter() { - String filter = ""; if (river != null && river.length() > 0) { - filter = "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}"; - filter += createFilter(); - filter += "}"; + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jfix.put("fixings", createFilter(jfilter)); + GWT.log("filter: " + jfix.toString()); + return jfix.toString(); } - return filter; + return ""; } public String getChartFilter(int width, int height) { - String filter = ""; if (river != null && river.length() > 0 && currentKm >= fromKm && currentKm <= toKm) { - filter = "{\"fixings\": "+ - "{\"river\": {\"name\": \"" + river + "\"}," + - "\"km\": {\"value\": \"" + currentKm + "\"}," + - "\"extent\": {\"width\": \"" + width + "\", \"height\": \"" + height + "\"}}"; - filter += createFilter(); - filter += "}"; + GWT.log("current: " + currentKm); + JSONObject jfix = new JSONObject(); + JSONObject jfilter = new JSONObject(); + JSONObject jrName = new JSONObject(); + JSONString jrValue = new JSONString(river); + JSONObject jkm = new JSONObject(); + JSONNumber jkmValue = new JSONNumber(currentKm); + JSONObject jextent = new JSONObject(); + JSONNumber jwidth = new JSONNumber(width); + JSONNumber jheight = new JSONNumber(height); + + jkm.put("value", jkmValue); + jrName.put("name", jrValue); + jfilter.put("river", jrName); + jfilter.put("km", jkm); + jextent.put("width", jwidth); + jextent.put("height", jheight); + jfilter.put("extent", jextent); + jfix.put("fixings", createFilter(jfilter)); + GWT.log("filter: " + jfix.toString()); + return jfix.toString(); } - return filter; + return ""; } - protected String createFilter() { - //TODO create filter... - return ""; + protected JSONObject createFilter(JSONObject root) { + GWT.log("km:" + fromKm + ", " + toKm); + if (this.fromKm >= 0 && this.toKm >= 0 && this.fromKm <=this.toKm) { + JSONObject range = new JSONObject(); + JSONObject fromtokm = new JSONObject(); + JSONNumber f = new JSONNumber(this.fromKm); + JSONNumber t = new JSONNumber(this.toKm); + fromtokm.put("from", f); + fromtokm.put("to", t); + root.put("range", fromtokm); + } + JSONObject and = new JSONObject(); + if (this.hasDate) { + JSONObject daterange = new JSONObject(); + Date df = new Date(this.fromDate); + Date dt = new Date(this.toDate); + DateTimeFormat dtf = DateTimeFormat.getFormat("dd.MM.yyyy"); + JSONString f = new JSONString(dtf.format(df)); + JSONString t = new JSONString(dtf.format(dt)); + daterange.put("from", f); + daterange.put("to", t); + and.put("date-range", daterange); + } + if (this.fromClass >= 0 && + this.toClass >= 0 && + this.fromClass <= this.toClass) { + JSONObject classrange = new JSONObject(); + JSONNumber f = new JSONNumber(this.fromClass); + JSONNumber t = new JSONNumber(this.toClass); + classrange.put("from", f); + classrange.put("to", t); + and.put("sector-range", classrange); + } + if (this.events.length > 0) { + JSONArray col = new JSONArray(); + for(int i = 0; i < this.events.length; i++) { + JSONObject column = new JSONObject(); + JSONObject cid = new JSONObject(); + JSONNumber id = new JSONNumber(this.events[i]); + cid.put("cid", id); + column.put("column", cid); + col.set(i, column); + } + and.put("or", col); + } + if (and.size() > 0) { + JSONObject filter = new JSONObject(); + filter.put("and", and); + root.put("filter", filter); + } + return root; } } } diff -r c3feb721035c -r 88bca9f735c0 flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java --- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java Wed May 30 12:02:56 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/FixAnalysisArtifact.java Fri Jun 01 10:27:14 2012 +0000 @@ -1,7 +1,11 @@ package de.intevation.flys.client.shared.model; import java.util.List; +import java.lang.NumberFormatException; +import com.google.gwt.core.client.GWT; +import de.intevation.flys.client.client.ui.fixation.FixationPanel; +import de.intevation.flys.client.client.ui.fixation.FixationPanel.FixFilter; /** * The Fixanalysis implementation of an Artifact. @@ -13,13 +17,16 @@ /** The name of this artifact: 'minfo'.*/ public static final String NAME = "fixanalysis"; + protected FixationPanel.FixFilter filter; public FixAnalysisArtifact() { + this.filter = null; } public FixAnalysisArtifact(String uuid, String hash) { super(uuid, hash); + this.filter = null; } @@ -36,5 +43,90 @@ public String getName() { return NAME; } + + + public FixationPanel.FixFilter getFilter () { + return createFilter(); + } + + + protected FixFilter createFilter() { + if (this.filter == null) { + this.filter = new FixFilter(); + } + DataList[] old = artifactDescription.getOldData(); + for (int i = 0; i < old.length; i++) { + DataList data = old[i]; + List items = data.getAll(); + String state = data.getState(); + if (state.equals("state.fix.river")) { + Data d = getData(items, "river"); + this.filter.setRiver(d.getItems()[0].getLabel()); + } + if (state.equals("state.fix.location")) { + Data df = getData(items, "from"); + Data dt = getData(items, "to"); + try { + String from = df.getItems()[0].getLabel(); + String to = dt.getItems()[0].getLabel(); + double fkm = Double.valueOf(from).doubleValue(); + double tkm = Double.valueOf(to).doubleValue(); + this.filter.setFromKm(fkm); + this.filter.setToKm(tkm); + if (fkm > filter.getCurrentKm()) { + this.filter.setCurrentKm(fkm); + } + } + catch(NumberFormatException nfe) { + } + } + if (state.equals("state.fix.period")) { + Data ds = getData(items, "start"); + Data de = getData(items, "end"); + try { + String start = ds.getItems()[0].getStringValue(); + String end = de.getItems()[0].getStringValue(); + long sp = Long.parseLong(start); + long ep = Long.parseLong(end); + this.filter.setFromDate(sp); + this.filter.setToDate(ep); + } + catch(NumberFormatException nfe) { + } + } + if (state.equals("state.fix.gaugerange")) { + Data gr1 = getData(items, "q1"); + Data gr2 = getData(items, "q2"); + try { + String q1s = gr1.getItems()[0].getLabel(); + String q2s = gr2.getItems()[0].getLabel(); + int q1 = Integer.valueOf(q1s).intValue(); + int q2 = Integer.valueOf(q2s).intValue(); + this.filter.setFromClass(q1); + this.filter.setToClass(q2); + } + catch(NumberFormatException nfe) { + } + } + if(state.equals("state.fix.eventselect")) { + Data de = getData(items, "events"); + IntegerArrayData iad = (IntegerArrayData) de; + GWT.log(iad.getStringValue()); + this.filter.setEvents(iad.getValues()); + } + } + return this.filter; + } + + protected Data getData(List data, String name) { + for (Data d: data) { + if (name.equals(d.getLabel())) { + return d; + } + } + return null; + } + + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :