comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java @ 2884:88bca9f735c0

Implemented filter for fix analysis helper widgets. flys-client/trunk@4567 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 01 Jun 2012 10:27:14 +0000
parents a9cdd62aa73e
children 6ab6025cef20
comparison
equal deleted inserted replaced
2883:c3feb721035c 2884:88bca9f735c0
1 package de.intevation.flys.client.client.ui.fixation; 1 package de.intevation.flys.client.client.ui.fixation;
2 2
3 import java.util.HashMap; 3 import java.util.HashMap;
4 import java.util.Date;
5
4 import java.lang.Math; 6 import java.lang.Math;
7 import java.io.Serializable;
5 8
6 import java.lang.NumberFormatException; 9 import java.lang.NumberFormatException;
7 10
8 import com.google.gwt.core.client.GWT; 11 import com.google.gwt.core.client.GWT;
9 import com.google.gwt.user.client.rpc.AsyncCallback; 12 import com.google.gwt.user.client.rpc.AsyncCallback;
13
14 import com.google.gwt.json.client.JSONArray;
15 import com.google.gwt.json.client.JSONObject;
16 import com.google.gwt.json.client.JSONNumber;
17 import com.google.gwt.json.client.JSONParser;
18 import com.google.gwt.json.client.JSONString;
19 import com.google.gwt.i18n.client.DateTimeFormat;
10 20
11 import com.smartgwt.client.util.SC; 21 import com.smartgwt.client.util.SC;
12 22
13 import com.smartgwt.client.widgets.Canvas; 23 import com.smartgwt.client.widgets.Canvas;
14 import com.smartgwt.client.widgets.Button; 24 import com.smartgwt.client.widgets.Button;
36 import de.intevation.flys.client.client.Config; 46 import de.intevation.flys.client.client.Config;
37 47
38 import de.intevation.flys.client.shared.model.Data; 48 import de.intevation.flys.client.shared.model.Data;
39 import de.intevation.flys.client.shared.model.DataList; 49 import de.intevation.flys.client.shared.model.DataList;
40 import de.intevation.flys.client.shared.model.FixingsOverviewInfo; 50 import de.intevation.flys.client.shared.model.FixingsOverviewInfo;
51 import de.intevation.flys.client.shared.model.FixAnalysisArtifact;
41 52
42 import de.intevation.flys.client.client.services.FixingsOverviewService; 53 import de.intevation.flys.client.client.services.FixingsOverviewService;
43 import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync; 54 import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync;
44 55
45 56
61 protected FixingsOverviewServiceAsync overviewService = 72 protected FixingsOverviewServiceAsync overviewService =
62 GWT.create(FixingsOverviewService.class); 73 GWT.create(FixingsOverviewService.class);
63 74
64 protected String htmlOverview; 75 protected String htmlOverview;
65 protected FixingsOverviewInfo fixInfo; 76 protected FixingsOverviewInfo fixInfo;
66 protected FixFilter fixFilter;
67 protected TabSet tabs; 77 protected TabSet tabs;
68 protected Tab events; 78 protected Tab events;
69 protected Tab chart; 79 protected Tab chart;
70 protected VLayout chartContainer; 80 protected VLayout chartContainer;
71 protected Img chartImg; 81 protected Img chartImg;
72 82
73 public FixationPanel() { 83 public FixationPanel() {
74 fixFilter = new FixFilter(); 84 GWT.log("new filter");
75 chartImg = new Img(); 85 chartImg = new Img();
76 htmlOverview = ""; 86 htmlOverview = "";
77 } 87 }
78 88
79 protected String getArtifactUuid() { 89 protected String getArtifactUuid() {
125 chart.setPane(layout); 135 chart.setPane(layout);
126 136
127 final HTMLPane eventPane = new HTMLPane(); 137 final HTMLPane eventPane = new HTMLPane();
128 138
129 String river = artifact.getArtifactDescription().getRiver(); 139 String river = artifact.getArtifactDescription().getRiver();
130 fixFilter.setRiver(river);
131 createCallback(); 140 createCallback();
132 /* 141 /*
133 Filter example. 142 Filter example.
134 {"fixings": { "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }} 143 {"fixings": "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }}
135 */ 144 */
136 String callBack = "fixationCallback(this.checked, this.name)"; 145 String callBack = "fixationCallback(this.checked, this.name)";
146 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
147
148 GWT.log(art.getFilter().getOverviewFilter());
137 149
138 overviewService.generateOverview( 150 overviewService.generateOverview(
139 locale, 151 locale,
140 artifact.getUuid(), 152 artifact.getUuid(),
141 fixFilter.getOverviewFilter(), 153 art.getFilter().getOverviewFilter(),
142 renderCheckboxes(), 154 renderCheckboxes(),
143 callBack, 155 callBack,
144 new AsyncCallback<FixingsOverviewInfo>() { 156 new AsyncCallback<FixingsOverviewInfo>() {
145 public void onFailure(Throwable caught) { 157 public void onFailure(Throwable caught) {
146 GWT.log("Could not receive overview."); 158 GWT.log("Could not receive overview.");
148 } 160 }
149 public void onSuccess(FixingsOverviewInfo info) { 161 public void onSuccess(FixingsOverviewInfo info) {
150 GWT.log("Successfully loaded overview."); 162 GWT.log("Successfully loaded overview.");
151 fixInfo = info; 163 fixInfo = info;
152 htmlOverview = info.getHTML(); 164 htmlOverview = info.getHTML();
153 fixFilter.setRiver(info.getRiver()); 165 FixAnalysisArtifact art = (FixAnalysisArtifact)artifact;
154 fixFilter.setCurrentKm(1d); 166 art.getFilter().setRiver(info.getRiver());
155 fixFilter.setFromKm(info.getFrom()); 167 art.getFilter().setCurrentKm(1d);
156 fixFilter.setToKm(info.getTo()); 168 art.getFilter().setFromKm(info.getFrom());
169 art.getFilter().setToKm(info.getTo());
157 eventPane.setContents(htmlOverview); 170 eventPane.setContents(htmlOverview);
158 updateChartTab(fixInfo.getFrom()); 171 updateChartTab(fixInfo.getFrom());
159 events.setPane(eventPane); 172 events.setPane(eventPane);
160 success(); 173 success();
161 } 174 }
184 form.setFields(currentkm); 197 form.setFields(currentkm);
185 form.setWidth(60); 198 form.setWidth(60);
186 lower.addClickHandler(new ClickHandler() { 199 lower.addClickHandler(new ClickHandler() {
187 public void onClick(ClickEvent ce) { 200 public void onClick(ClickEvent ce) {
188 updateChartTabLow(); 201 updateChartTabLow();
189 currentkm.setValue(fixFilter.getCurrentKm()); 202 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
203 currentkm.setValue(art.getFilter().getCurrentKm());
190 } 204 }
191 }); 205 });
192 206
193 upper.addClickHandler(new ClickHandler() { 207 upper.addClickHandler(new ClickHandler() {
194 public void onClick(ClickEvent ce) { 208 public void onClick(ClickEvent ce) {
195 updateChartTabUp(); 209 updateChartTabUp();
196 currentkm.setValue(fixFilter.getCurrentKm()); 210 FixAnalysisArtifact art = (FixAnalysisArtifact) artifact;
211 currentkm.setValue(art.getFilter().getCurrentKm());
197 } 212 }
198 }); 213 });
199 214
200 currentkm.addChangedHandler(new ChangedHandler() { 215 currentkm.addChangedHandler(new ChangedHandler() {
201 public void onChanged(ChangedEvent ce) { 216 public void onChanged(ChangedEvent ce) {
224 239
225 protected void updateChartTab(double km) { 240 protected void updateChartTab(double km) {
226 Config config = Config.getInstance(); 241 Config config = Config.getInstance();
227 String locale = config.getLocale (); 242 String locale = config.getLocale ();
228 243
229 fixFilter.setCurrentKm(km); 244 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
230 chartContainer.removeMember(chartImg); 245 GWT.log("km: " + km);
246 if (km < 0) {
247 km = 0;
248 }
249 GWT.log("km: " + km);
250 art.getFilter().setCurrentKm(km);
251 if (chartContainer.hasMember(chartImg)) {
252 chartContainer.removeMember(chartImg);
253 }
231 String imgUrl = GWT.getModuleBaseURL(); 254 String imgUrl = GWT.getModuleBaseURL();
232 imgUrl += "fixings-km-chart"; 255 imgUrl += "fixings-km-chart";
233 imgUrl += "?locale=" + locale; 256 imgUrl += "?locale=" + locale;
234 imgUrl += "&filter=" + fixFilter.getChartFilter(helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12); 257 imgUrl += "&filter=" + art.getFilter().getChartFilter(helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12);
235 258
236 chartImg = new Img(imgUrl, helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12); 259 chartImg = new Img(imgUrl, helperContainer.getWidth() - 12, (int)(helperContainer.getWidth()*3/4) - 12);
237 chartContainer.addMember(chartImg); 260 chartContainer.addMember(chartImg);
238 261
239 } 262 }
240 263
241 264
242 protected void updateChartTabLow() { 265 protected void updateChartTabLow() {
243 double curr = fixFilter.getCurrentKm(); 266 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
244 if (curr > fixFilter.getFromKm()) { 267
268 double curr = art.getFilter().getCurrentKm();
269 if (curr > art.getFilter().getFromKm()) {
245 double newVal = (curr - 0.1) * 10; 270 double newVal = (curr - 0.1) * 10;
246 long round = Math.round(newVal); 271 long round = Math.round(newVal);
247 updateChartTab(((double)round) / 10); 272 updateChartTab(((double)round) / 10);
248 } 273 }
249 return; 274 return;
250 } 275 }
251 276
252 277
253 protected void updateChartTabUp() { 278 protected void updateChartTabUp() {
254 double curr = fixFilter.getCurrentKm(); 279 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
255 if (curr < fixFilter.getToKm()) { 280
281 double curr = art.getFilter().getCurrentKm();
282 if (curr < art.getFilter().getToKm()) {
256 double newVal = (curr + 0.1) * 10; 283 double newVal = (curr + 0.1) * 10;
257 long round = Math.round(newVal); 284 long round = Math.round(newVal);
258 updateChartTab(((double)round) / 10); 285 updateChartTab(((double)round) / 10);
259 } 286 }
260 return; 287 return;
261 } 288 }
262 289
263 290
264 public void onResized(ResizedEvent re) { 291 public void onResized(ResizedEvent re) {
265 updateChartTab(fixFilter.getCurrentKm()); 292 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact;
293
294 updateChartTab(art.getFilter().getCurrentKm());
266 } 295 }
267 296
268 297
269 private native void createCallback() /*-{ 298 private native void createCallback() /*-{
270 $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); 299 $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;);
290 } 319 }
291 320
292 public abstract Canvas createWidget(DataList data); 321 public abstract Canvas createWidget(DataList data);
293 public abstract void setValues(String cid, boolean checked); 322 public abstract void setValues(String cid, boolean checked);
294 public abstract boolean renderCheckboxes(); 323 public abstract boolean renderCheckboxes();
295 public abstract FixFilter getFilter();
296 public abstract void setFilter(FixFilter filter);
297 public abstract void success(); 324 public abstract void success();
298 325
299 public static class FixFilter { 326 public static class FixFilter implements Serializable{
300 protected String river; 327 protected String river;
301 protected double fromKm; 328 protected double fromKm;
302 protected double toKm; 329 protected double toKm;
303 protected double currentKm; 330 protected double currentKm;
304 protected int fromClass; 331 protected int fromClass;
394 public int[] getEvents() { 421 public int[] getEvents() {
395 return this.events; 422 return this.events;
396 } 423 }
397 424
398 public String getOverviewFilter() { 425 public String getOverviewFilter() {
399 String filter = "";
400 if (river != null && river.length() > 0) { 426 if (river != null && river.length() > 0) {
401 filter = "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}"; 427 JSONObject jfix = new JSONObject();
402 filter += createFilter(); 428 JSONObject jfilter = new JSONObject();
403 filter += "}"; 429 JSONObject jrName = new JSONObject();
404 } 430 JSONString jrValue = new JSONString(river);
405 return filter; 431 jrName.put("name", jrValue);
432 jfilter.put("river", jrName);
433 jfix.put("fixings", createFilter(jfilter));
434 GWT.log("filter: " + jfix.toString());
435 return jfix.toString();
436 }
437 return "";
406 } 438 }
407 439
408 public String getChartFilter(int width, int height) { 440 public String getChartFilter(int width, int height) {
409 String filter = "";
410 if (river != null && river.length() > 0 && 441 if (river != null && river.length() > 0 &&
411 currentKm >= fromKm && currentKm <= toKm) 442 currentKm >= fromKm && currentKm <= toKm)
412 { 443 {
413 filter = "{\"fixings\": "+ 444 GWT.log("current: " + currentKm);
414 "{\"river\": {\"name\": \"" + river + "\"}," + 445 JSONObject jfix = new JSONObject();
415 "\"km\": {\"value\": \"" + currentKm + "\"}," + 446 JSONObject jfilter = new JSONObject();
416 "\"extent\": {\"width\": \"" + width + "\", \"height\": \"" + height + "\"}}"; 447 JSONObject jrName = new JSONObject();
417 filter += createFilter(); 448 JSONString jrValue = new JSONString(river);
418 filter += "}"; 449 JSONObject jkm = new JSONObject();
419 } 450 JSONNumber jkmValue = new JSONNumber(currentKm);
420 return filter; 451 JSONObject jextent = new JSONObject();
421 } 452 JSONNumber jwidth = new JSONNumber(width);
422 453 JSONNumber jheight = new JSONNumber(height);
423 protected String createFilter() { 454
424 //TODO create filter... 455 jkm.put("value", jkmValue);
425 return ""; 456 jrName.put("name", jrValue);
457 jfilter.put("river", jrName);
458 jfilter.put("km", jkm);
459 jextent.put("width", jwidth);
460 jextent.put("height", jheight);
461 jfilter.put("extent", jextent);
462 jfix.put("fixings", createFilter(jfilter));
463 GWT.log("filter: " + jfix.toString());
464 return jfix.toString();
465 }
466 return "";
467 }
468
469 protected JSONObject createFilter(JSONObject root) {
470 GWT.log("km:" + fromKm + ", " + toKm);
471 if (this.fromKm >= 0 && this.toKm >= 0 && this.fromKm <=this.toKm) {
472 JSONObject range = new JSONObject();
473 JSONObject fromtokm = new JSONObject();
474 JSONNumber f = new JSONNumber(this.fromKm);
475 JSONNumber t = new JSONNumber(this.toKm);
476 fromtokm.put("from", f);
477 fromtokm.put("to", t);
478 root.put("range", fromtokm);
479 }
480 JSONObject and = new JSONObject();
481 if (this.hasDate) {
482 JSONObject daterange = new JSONObject();
483 Date df = new Date(this.fromDate);
484 Date dt = new Date(this.toDate);
485 DateTimeFormat dtf = DateTimeFormat.getFormat("dd.MM.yyyy");
486 JSONString f = new JSONString(dtf.format(df));
487 JSONString t = new JSONString(dtf.format(dt));
488 daterange.put("from", f);
489 daterange.put("to", t);
490 and.put("date-range", daterange);
491 }
492 if (this.fromClass >= 0 &&
493 this.toClass >= 0 &&
494 this.fromClass <= this.toClass) {
495 JSONObject classrange = new JSONObject();
496 JSONNumber f = new JSONNumber(this.fromClass);
497 JSONNumber t = new JSONNumber(this.toClass);
498 classrange.put("from", f);
499 classrange.put("to", t);
500 and.put("sector-range", classrange);
501 }
502 if (this.events.length > 0) {
503 JSONArray col = new JSONArray();
504 for(int i = 0; i < this.events.length; i++) {
505 JSONObject column = new JSONObject();
506 JSONObject cid = new JSONObject();
507 JSONNumber id = new JSONNumber(this.events[i]);
508 cid.put("cid", id);
509 column.put("column", cid);
510 col.set(i, column);
511 }
512 and.put("or", col);
513 }
514 if (and.size() > 0) {
515 JSONObject filter = new JSONObject();
516 filter.put("and", and);
517 root.put("filter", filter);
518 }
519 return root;
426 } 520 }
427 } 521 }
428 } 522 }

http://dive4elements.wald.intevation.org