Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/LocationDistancePanel.java @ 8449:f61e2791ccdf
(issue1733) Fix locationdistancepanel
There is now a central method to setup the listgrids and connect
the Input completion pins. The old variant with three tables
was broken and had did many duplicated things. Comments should
also be clearer to point out which code path belongs to which
input state.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 27 Oct 2014 17:00:40 +0100 |
parents | e98dbf72c9ec |
children | 07df414d5d88 |
comparison
equal
deleted
inserted
replaced
8448:e98dbf72c9ec | 8449:f61e2791ccdf |
---|---|
143 protected ListGrid distanceTable; | 143 protected ListGrid distanceTable; |
144 | 144 |
145 /** The locations table. */ | 145 /** The locations table. */ |
146 protected ListGrid locationsTable; | 146 protected ListGrid locationsTable; |
147 | 147 |
148 /** The locations table for distance input. */ | |
149 protected ListGrid locationDistanceTable; | |
150 | |
151 /** The table data. */ | 148 /** The table data. */ |
152 protected DistanceInfoObject[] tableData; | 149 protected DistanceInfoObject[] tableData; |
153 | 150 |
154 /** The table filter.*/ | 151 /** The table filter.*/ |
155 protected TableFilter filterDescription; | 152 protected TableFilter filterDescription; |
168 distanceTable.setAutoFetchData(true); | 165 distanceTable.setAutoFetchData(true); |
169 | 166 |
170 locationsTable = new ListGrid(); | 167 locationsTable = new ListGrid(); |
171 locationsTable.setAutoFetchData(true); | 168 locationsTable.setAutoFetchData(true); |
172 | 169 |
173 locationDistanceTable = new ListGrid(); | |
174 locationDistanceTable.setAutoFetchData(true); | |
175 | |
176 locationDistanceTable.setShowHeaderContextMenu(false); | |
177 distanceTable.setShowHeaderContextMenu(false); | 170 distanceTable.setShowHeaderContextMenu(false); |
178 locationsTable.setShowHeaderContextMenu(false); | 171 locationsTable.setShowHeaderContextMenu(false); |
179 } | 172 } |
180 | 173 |
181 | 174 |
198 Canvas submit = getNextButton(); | 191 Canvas submit = getNextButton(); |
199 createDistanceInputPanel(); | 192 createDistanceInputPanel(); |
200 | 193 |
201 initDefaults(data); | 194 initDefaults(data); |
202 | 195 |
203 createLocationTableDistance (); | |
204 createDistanceTable(); | |
205 createLocationTable(); | |
206 | |
207 widget.setHeight(50); | 196 widget.setHeight(50); |
208 label.setHeight(25); | 197 label.setHeight(25); |
209 | 198 |
210 layout.addMember(label); | 199 layout.addMember(label); |
211 layout.addMember(widget); | 200 layout.addMember(widget); |
214 return layout; | 203 return layout; |
215 } | 204 } |
216 | 205 |
217 | 206 |
218 /** | 207 /** |
219 * This method creates a table that contains the distance values. | 208 * Setup a table for a DistanceInfoDataSource. |
220 */ | 209 * |
221 protected void createDistanceTable() { | 210 * Sets up a table to for input completion. The table |
211 * can be used either for single locations or distances. | |
212 * Depending on the value of isDistance the table will | |
213 * have a to and a from column or a single location column. | |
214 * | |
215 * @param table the ListGrid to set up. | |
216 * @param doublePins wether or not to have. | |
217 * @param isDistance wether or not to and from should be included. | |
218 */ | |
219 protected void setupDistanceInfoTable(ListGrid table, | |
220 boolean doublePins, | |
221 boolean isDistance) { | |
222 | 222 |
223 String baseUrl = GWT.getHostPageBaseURL(); | 223 String baseUrl = GWT.getHostPageBaseURL(); |
224 | 224 |
225 distanceTable.setWidth100(); | 225 table.setWidth100(); |
226 distanceTable.setShowRecordComponents(true); | 226 table.setShowRecordComponents(true); |
227 distanceTable.setShowRecordComponentsByCell(true); | 227 table.setShowRecordComponentsByCell(true); |
228 distanceTable.setHeight100(); | 228 table.setHeight100(); |
229 distanceTable.setEmptyMessage(MESSAGES.empty_filter()); | 229 table.setEmptyMessage(MESSAGES.empty_filter()); |
230 distanceTable.setCanReorderFields(false); | 230 table.setCanReorderFields(false); |
231 | 231 |
232 CellFormatter cf = new CellFormatter() { | 232 CellFormatter cf = new CellFormatter() { |
233 @Override | 233 @Override |
234 public String format( | 234 public String format( |
235 Object value, | 235 Object value, |
245 catch (Exception e) { | 245 catch (Exception e) { |
246 return value.toString(); | 246 return value.toString(); |
247 } | 247 } |
248 } | 248 } |
249 }; | 249 }; |
250 | 250 ListGridField pin1 = null; |
251 ListGridField addDistance = new ListGridField ("", ""); | 251 ListGridField pin2 = null; |
252 addDistance.setType (ListGridFieldType.ICON); | 252 |
253 addDistance.setWidth (30); | 253 if (doublePins) { |
254 addDistance.addRecordClickHandler (new RecordClickHandler () { | 254 pin1 = new ListGridField ("fromIcon", MESSAGES.from()); |
255 @Override | 255 pin1.setWidth (30); |
256 public void onRecordClick (RecordClickEvent e) { | 256 } else { |
257 if (!isLocationMode ()) { | 257 pin1 = new ListGridField ("fromIcon", MESSAGES.selection()); |
258 pin1.setWidth (60); | |
259 } | |
260 pin1.setType (ListGridFieldType.ICON); | |
261 pin1.setCellIcon(baseUrl + MESSAGES.markerGreen()); | |
262 | |
263 if (doublePins) { | |
264 pin2 = new ListGridField ("toIcon", MESSAGES.to()); | |
265 pin2.setType (ListGridFieldType.ICON); | |
266 pin2.setWidth (30); | |
267 pin2.setCellIcon(baseUrl + MESSAGES.markerRed()); | |
268 } | |
269 | |
270 if (isDistance) { | |
271 /* We have from / to fields */ | |
272 pin1.addRecordClickHandler (new RecordClickHandler () { | |
273 @Override | |
274 public void onRecordClick (RecordClickEvent e) { | |
258 Record r = e.getRecord(); | 275 Record r = e.getRecord(); |
259 try { | 276 if (!isLocationMode ()) { |
260 double min = Double.parseDouble(r.getAttribute("from")); | 277 /* distance panel and distance mode */ |
261 double max = Double.parseDouble(r.getAttribute("to")); | 278 setFrom(r.getAttribute("from")); |
262 setDistanceValues(min, max); | 279 setTo(r.getAttribute("to")); |
263 } | 280 } else { |
264 catch(NumberFormatException nfe) { | 281 /* distance panel and location mode */ |
265 // Is there anything to do? | 282 /* Pin 1 is the "from" pin */ |
283 appendLocation(r.getAttribute("from")); | |
266 } | 284 } |
267 } | 285 } |
268 else { | 286 }); |
269 double[] selected; | 287 if (doublePins) { |
288 pin2.addRecordClickHandler (new RecordClickHandler () { | |
289 @Override | |
290 public void onRecordClick (RecordClickEvent e) { | |
291 Record r = e.getRecord(); | |
292 if (isLocationMode ()) { | |
293 appendLocation(r.getAttribute("to")); | |
294 } else { | |
295 /* Distance and double pin behavior is only defined for | |
296 * location mode. */ | |
297 GWT.log("Unhandled input state."); | |
298 } | |
299 } | |
300 }); | |
301 } | |
302 } else { | |
303 /* We only have the from field */ | |
304 pin1.addRecordClickHandler (new RecordClickHandler () { | |
305 @Override | |
306 public void onRecordClick (RecordClickEvent e) { | |
270 Record r = e.getRecord(); | 307 Record r = e.getRecord(); |
271 double min = 0, max = 0; | 308 if (!isLocationMode ()) { |
272 try { | 309 /* Location panel and distance mode */ |
273 min = Double.parseDouble(r.getAttribute("from")); | 310 setFrom(r.getAttribute("from")); |
274 max = Double.parseDouble(r.getAttribute("to")); | 311 } else { |
312 /* Location panel and location mode */ | |
313 appendLocation(r.getAttribute("from")); | |
275 } | 314 } |
276 catch(NumberFormatException nfe) { | 315 } |
277 // Is there anything to do? | 316 }); |
317 if (doublePins) { | |
318 pin2.addRecordClickHandler (new RecordClickHandler () { | |
319 @Override | |
320 public void onRecordClick (RecordClickEvent e) { | |
321 Record r = e.getRecord(); | |
322 if (!isLocationMode ()) { | |
323 setTo(r.getAttribute("from")); | |
324 } else { | |
325 /* Distance and double pin behavior is only defined for | |
326 * location mode. */ | |
327 GWT.log("Unhandled input state."); | |
328 } | |
278 } | 329 } |
279 if (getLocationValues() != null) { | 330 }); |
280 double[] val = getLocationValues(); | 331 } |
281 selected = new double[val.length + 2]; | 332 } |
282 for(int i = 0; i < val.length; i++){ | |
283 selected[i] = val[i]; | |
284 } | |
285 selected[val.length] = min; | |
286 selected[val.length + 1] = max; | |
287 } | |
288 else { | |
289 selected = new double[2]; | |
290 selected[0] = min; | |
291 selected[1] = max; | |
292 } | |
293 setLocationValues(selected); | |
294 } | |
295 } | |
296 }); | |
297 addDistance.setCellIcon(baseUrl + MESSAGES.markerGreen()); | |
298 | 333 |
299 ListGridField ddescr = new ListGridField("description", | 334 ListGridField ddescr = new ListGridField("description", |
300 MESSAGES.description()); | 335 MESSAGES.description()); |
301 ddescr.setType(ListGridFieldType.TEXT); | 336 ddescr.setType(ListGridFieldType.TEXT); |
302 ddescr.setWidth("*"); | 337 ddescr.setWidth("*"); |
303 ListGridField from = new ListGridField("from", MESSAGES.from()); | 338 |
339 ListGridField from; | |
340 ListGridField to = null; | |
341 | |
342 if (isDistance) { | |
343 from = new ListGridField("from", MESSAGES.from()); | |
344 to = new ListGridField("to", MESSAGES.to()); | |
345 to.setType(ListGridFieldType.FLOAT); | |
346 to.setCellFormatter(cf); | |
347 | |
348 to.setWidth("12%"); | |
349 to.setAlign(Alignment.LEFT); | |
350 } else { | |
351 from = new ListGridField("from", MESSAGES.locations()); | |
352 } | |
304 from.setCellFormatter(cf); | 353 from.setCellFormatter(cf); |
305 | |
306 from.setWidth("12%"); | 354 from.setWidth("12%"); |
307 ListGridField to = new ListGridField("to", MESSAGES.to()); | 355 |
308 to.setType(ListGridFieldType.FLOAT); | |
309 to.setCellFormatter(cf); | |
310 | |
311 to.setWidth("12%"); | |
312 to.setAlign(Alignment.LEFT); | |
313 ListGridField dside = new ListGridField("riverside", | 356 ListGridField dside = new ListGridField("riverside", |
314 MESSAGES.riverside()); | 357 MESSAGES.riverside()); |
315 dside.setType(ListGridFieldType.TEXT); | 358 dside.setType(ListGridFieldType.TEXT); |
316 dside.setWidth("12%"); | 359 dside.setWidth("12%"); |
317 | 360 |
325 new ListGridField("top", MESSAGES.top_edge()); | 368 new ListGridField("top", MESSAGES.top_edge()); |
326 top.setType(ListGridFieldType.TEXT); | 369 top.setType(ListGridFieldType.TEXT); |
327 top.setWidth("10%"); | 370 top.setWidth("10%"); |
328 top.setCellFormatter(cf); | 371 top.setCellFormatter(cf); |
329 | 372 |
330 distanceTable.setFields( | 373 if (doublePins && isDistance) { |
331 addDistance, ddescr, from, to, dside, bottom, top); | 374 table.setFields(pin1, pin2, ddescr, from, to, dside, bottom, top); |
332 } | 375 } else if (doublePins) { |
333 | 376 table.setFields(pin1, pin2, ddescr, from, dside, bottom, top); |
334 | 377 } else if (isDistance) { |
335 /** | 378 table.setFields(pin1, ddescr, from, to, dside, bottom, top); |
336 * This method creates a table that contains the location values. | 379 } else { |
337 */ | 380 table.setFields(pin1, ddescr, from, dside, bottom, top); |
338 protected void createLocationTable() { | 381 } |
339 | 382 } |
340 String baseUrl = GWT.getHostPageBaseURL(); | |
341 | |
342 locationsTable.setWidth100(); | |
343 locationsTable.setShowRecordComponents(true); | |
344 locationsTable.setShowRecordComponentsByCell(true); | |
345 locationsTable.setHeight100(); | |
346 locationsTable.setEmptyMessage(MESSAGES.empty_filter()); | |
347 locationsTable.setCanReorderFields(false); | |
348 | |
349 CellFormatter cf = new CellFormatter() { | |
350 @Override | |
351 public String format( | |
352 Object value, | |
353 ListGridRecord record, | |
354 int rowNum, int colNum) { | |
355 if (value == null) return null; | |
356 try { | |
357 NumberFormat nf; | |
358 double v = Double.parseDouble((String)value); | |
359 nf = NumberFormat.getFormat("###0.00##"); | |
360 return nf.format(v); | |
361 } | |
362 catch (Exception e) { | |
363 return value.toString(); | |
364 } | |
365 } | |
366 }; | |
367 | |
368 | |
369 | |
370 ListGridField addLocation = new ListGridField ("", ""); | |
371 addLocation.setType (ListGridFieldType.ICON); | |
372 addLocation.setWidth (20); | |
373 | |
374 addLocation.addRecordClickHandler (new RecordClickHandler () { | |
375 @Override | |
376 public void onRecordClick (RecordClickEvent e) { | |
377 Record record = e.getRecord(); | |
378 double[] selected; | |
379 if (getLocationValues() != null) { | |
380 double[] val = getLocationValues(); | |
381 selected = new double[val.length + 1]; | |
382 for(int i = 0; i < val.length; i++){ | |
383 selected[i] = val[i]; | |
384 } | |
385 try { | |
386 selected[val.length] = | |
387 Double.parseDouble(record.getAttribute("from")); | |
388 } | |
389 catch(NumberFormatException nfe) { | |
390 // Is there anything to do here? | |
391 } | |
392 } | |
393 else { | |
394 selected = new double[1]; | |
395 selected[0] = | |
396 Double.parseDouble(record.getAttribute("from")); | |
397 } | |
398 setLocationValues(selected); | |
399 } | |
400 }); | |
401 addLocation.setCellIcon (baseUrl + MESSAGES.markerGreen ()); | |
402 | |
403 ListGridField ldescr = new ListGridField("description", | |
404 MESSAGES.description()); | |
405 ldescr.setType(ListGridFieldType.TEXT); | |
406 ldescr.setWidth("*"); | |
407 ListGridField lside = new ListGridField("riverside", | |
408 MESSAGES.riverside()); | |
409 lside.setType(ListGridFieldType.TEXT); | |
410 lside.setWidth("12%"); | |
411 ListGridField loc = new ListGridField("from", MESSAGES.locations()); | |
412 loc.setAlign(Alignment.LEFT); | |
413 loc.setType(ListGridFieldType.FLOAT); | |
414 loc.setWidth("12%"); | |
415 loc.setCellFormatter(cf); | |
416 | |
417 ListGridField bottom = | |
418 new ListGridField("bottom", MESSAGES.bottom_edge()); | |
419 bottom.setType(ListGridFieldType.TEXT); | |
420 bottom.setWidth("10%"); | |
421 bottom.setCellFormatter(cf); | |
422 | |
423 ListGridField top = | |
424 new ListGridField("top", MESSAGES.top_edge()); | |
425 top.setType(ListGridFieldType.TEXT); | |
426 top.setWidth("10%"); | |
427 top.setCellFormatter(cf); | |
428 | |
429 locationsTable.setFields(addLocation, ldescr, loc, lside, bottom, top); | |
430 } | |
431 | |
432 | |
433 /** | |
434 * This method creates a table that contains the location values. | |
435 */ | |
436 protected void createLocationTableDistance (){ | |
437 | |
438 String baseUrl = GWT.getHostPageBaseURL(); | |
439 | |
440 locationDistanceTable.setWidth100(); | |
441 locationDistanceTable.setShowRecordComponents(true); | |
442 locationDistanceTable.setShowRecordComponentsByCell(true); | |
443 locationDistanceTable.setHeight100(); | |
444 locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter()); | |
445 locationDistanceTable.setCanReorderFields(false); | |
446 | |
447 CellFormatter cf = new CellFormatter() { | |
448 @Override | |
449 public String format( | |
450 Object value, | |
451 ListGridRecord record, | |
452 int rowNum, int colNum) { | |
453 if (value == null) return null; | |
454 try { | |
455 NumberFormat nf; | |
456 double v = Double.parseDouble((String)value); | |
457 nf = NumberFormat.getFormat("###0.00##"); | |
458 return nf.format(v); | |
459 } | |
460 catch (Exception e) { | |
461 return value.toString(); | |
462 } | |
463 } | |
464 }; | |
465 | |
466 ListGridField addfrom = new ListGridField ("fromIcon", MESSAGES.from()); | |
467 addfrom.setType (ListGridFieldType.ICON); | |
468 addfrom.setWidth (30); | |
469 addfrom.setCellIcon(baseUrl + MESSAGES.markerGreen()); | |
470 | |
471 ListGridField addto2 = new ListGridField ("toIcon", MESSAGES.to()); | |
472 addto2.setType (ListGridFieldType.ICON); | |
473 addto2.setWidth (30); | |
474 addto2.setCellIcon(baseUrl + MESSAGES.markerRed()); | |
475 | |
476 locationDistanceTable.addCellClickHandler (new CellClickHandler () { | |
477 @Override | |
478 public void onCellClick (CellClickEvent e) { | |
479 if (e.getColNum() == 0) { | |
480 Record r = e.getRecord (); | |
481 try { | |
482 double fromvalue = | |
483 Double.parseDouble(r.getAttribute("from")); | |
484 double tovalue = getTo (); | |
485 setDistanceValues (fromvalue, tovalue); | |
486 } | |
487 catch(NumberFormatException nfe) { | |
488 // Is there anything to do in here? | |
489 } | |
490 } | |
491 else if (e.getColNum() == 1) { | |
492 Record r = e.getRecord (); | |
493 try { | |
494 double fromvalue = getFrom (); | |
495 double tovalue = | |
496 Double.parseDouble(r.getAttribute("from")); | |
497 setDistanceValues (fromvalue, tovalue); | |
498 } | |
499 catch(NumberFormatException nfe) { | |
500 // Is there anything to do in here? | |
501 } | |
502 } | |
503 } | |
504 }); | |
505 ListGridField bottom = | |
506 new ListGridField("bottom", MESSAGES.bottom_edge()); | |
507 bottom.setType(ListGridFieldType.TEXT); | |
508 bottom.setWidth("10%"); | |
509 bottom.setCellFormatter(cf); | |
510 | |
511 ListGridField top = | |
512 new ListGridField("top", MESSAGES.top_edge()); | |
513 top.setType(ListGridFieldType.TEXT); | |
514 top.setWidth("10%"); | |
515 top.setCellFormatter(cf); | |
516 | |
517 ListGridField ldescr = new ListGridField("description", | |
518 MESSAGES.description()); | |
519 ldescr.setType(ListGridFieldType.TEXT); | |
520 ldescr.setWidth("*"); | |
521 ListGridField lside = new ListGridField("riverside", | |
522 MESSAGES.riverside()); | |
523 lside.setType(ListGridFieldType.TEXT); | |
524 lside.setWidth("12%"); | |
525 ListGridField loc = new ListGridField("from", MESSAGES.locations()); | |
526 loc.setType(ListGridFieldType.FLOAT); | |
527 loc.setAlign(Alignment.LEFT); | |
528 loc.setWidth("12%"); | |
529 loc.setCellFormatter(cf); | |
530 | |
531 locationDistanceTable.setFields( | |
532 addfrom, addto2, ldescr, loc, lside, bottom, top); | |
533 } | |
534 | |
535 | 383 |
536 @Override | 384 @Override |
537 public Canvas createOld(DataList dataList) { | 385 public Canvas createOld(DataList dataList) { |
538 List<Data> items = dataList.getAll(); | 386 List<Data> items = dataList.getAll(); |
539 | 387 |
692 } | 540 } |
693 | 541 |
694 if (theMode.equals(FIELD_VALUE_DISTANCE)) { | 542 if (theMode.equals(FIELD_VALUE_DISTANCE)) { |
695 enableDistanceMode(); | 543 enableDistanceMode(); |
696 inputTables.selectTab(1); | 544 inputTables.selectTab(1); |
545 } else { | |
546 enableLocationMode(); | |
697 } | 547 } |
698 currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); | 548 currentFiltered = (ListGrid)inputTables.getSelectedTab().getPane(); |
699 | 549 |
700 distancePanel.setValues(getFrom(), getTo(), getStep()); | 550 distancePanel.setValues(getFrom(), getTo(), getStep()); |
701 } | 551 } |
733 filterDescription.clear(); | 583 filterDescription.clear(); |
734 filterRange.clear(); | 584 filterRange.clear(); |
735 filterResultCount.setValue(""); | 585 filterResultCount.setValue(""); |
736 | 586 |
737 // The assumption is that location is tab 0 and distance tab 1 | 587 // The assumption is that location is tab 0 and distance tab 1 |
738 if (inputTables.getSelectedTabNumber() == 0) { | |
739 enableLocationMode(); | |
740 } else { | |
741 enableDistanceMode(); | |
742 } | |
743 | 588 |
744 Canvas c = evt.getTabPane(); | 589 Canvas c = evt.getTabPane(); |
745 if(c instanceof ListGrid) { | 590 if(c instanceof ListGrid) { |
746 currentFiltered = (ListGrid)c; | 591 currentFiltered = (ListGrid)c; |
747 } | 592 } |
752 Tab distances = new Tab(MESSAGES.distance()); | 597 Tab distances = new Tab(MESSAGES.distance()); |
753 | 598 |
754 inputTables.setWidth100(); | 599 inputTables.setWidth100(); |
755 inputTables.setHeight100(); | 600 inputTables.setHeight100(); |
756 | 601 |
757 locations.setPane(locationDistanceTable); | 602 locations.setPane(locationsTable); |
758 distances.setPane(distanceTable); | 603 distances.setPane(distanceTable); |
759 | 604 |
760 inputTables.addTab(locations); | 605 inputTables.addTab(locations); |
761 inputTables.addTab(distances); | 606 inputTables.addTab(distances); |
762 | 607 |
834 if (search != null && search.length() > 0) { | 679 if (search != null && search.length() > 0) { |
835 Criteria c = new Criteria("description", search); | 680 Criteria c = new Criteria("description", search); |
836 | 681 |
837 locationsTable.filterData(c); | 682 locationsTable.filterData(c); |
838 distanceTable.filterData(c); | 683 distanceTable.filterData(c); |
839 locationDistanceTable.filterData(c); | |
840 filterResultCount.setValue(currentFiltered.getRecords().length); | 684 filterResultCount.setValue(currentFiltered.getRecords().length); |
841 } | 685 } |
842 else { | 686 else { |
843 locationsTable.clearCriteria(); | 687 locationsTable.clearCriteria(); |
844 distanceTable.clearCriteria(); | 688 distanceTable.clearCriteria(); |
845 locationDistanceTable.clearCriteria(); | |
846 filterResultCount.setValue(""); | 689 filterResultCount.setValue(""); |
847 } | 690 } |
848 } | 691 } |
849 | 692 |
850 | 693 |
858 Criterion combinedFilter = null; | 701 Criterion combinedFilter = null; |
859 Criterion locationFilter = null; | 702 Criterion locationFilter = null; |
860 if (from.equals(Float.NaN) && to.equals(Float.NaN)) { | 703 if (from.equals(Float.NaN) && to.equals(Float.NaN)) { |
861 locationsTable.clearCriteria(); | 704 locationsTable.clearCriteria(); |
862 distanceTable.clearCriteria(); | 705 distanceTable.clearCriteria(); |
863 locationDistanceTable.clearCriteria(); | |
864 filterResultCount.setValue(""); | 706 filterResultCount.setValue(""); |
865 return; | 707 return; |
866 } | 708 } |
867 else if (from.equals(Float.NaN)) { | 709 else if (from.equals(Float.NaN)) { |
868 combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); | 710 combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); |
869 locationFilter = | 711 locationFilter = |
870 new Criterion("from", OperatorId.LESS_OR_EQUAL, to); | 712 new Criterion("from", OperatorId.LESS_OR_EQUAL, to); |
871 locationsTable.filterData(locationFilter); | 713 locationsTable.filterData(locationFilter); |
872 distanceTable.filterData(combinedFilter); | 714 distanceTable.filterData(combinedFilter); |
873 locationDistanceTable.filterData(combinedFilter); | |
874 filterResultCount.setValue(currentFiltered.getRecords().length); | 715 filterResultCount.setValue(currentFiltered.getRecords().length); |
875 return; | 716 return; |
876 } | 717 } |
877 else if (to.equals(Float.NaN)) { | 718 else if (to.equals(Float.NaN)) { |
878 combinedFilter = | 719 combinedFilter = |
879 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); | 720 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); |
880 locationsTable.filterData(combinedFilter); | 721 locationsTable.filterData(combinedFilter); |
881 distanceTable.filterData(combinedFilter); | 722 distanceTable.filterData(combinedFilter); |
882 locationDistanceTable.filterData(combinedFilter); | |
883 } | 723 } |
884 else { | 724 else { |
885 AdvancedCriteria c1 = | 725 AdvancedCriteria c1 = |
886 new AdvancedCriteria(OperatorId.AND, new Criterion[] { | 726 new AdvancedCriteria(OperatorId.AND, new Criterion[] { |
887 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), | 727 new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), |
905 c1, c2, c3 | 745 c1, c2, c3 |
906 }); | 746 }); |
907 } | 747 } |
908 locationsTable.filterData(combinedFilter); | 748 locationsTable.filterData(combinedFilter); |
909 distanceTable.filterData(combinedFilter); | 749 distanceTable.filterData(combinedFilter); |
910 locationDistanceTable.filterData(combinedFilter); | |
911 filterResultCount.setValue(currentFiltered.getRecords().length); | 750 filterResultCount.setValue(currentFiltered.getRecords().length); |
912 } | 751 } |
913 | 752 |
914 | 753 |
915 @Override | 754 @Override |
1166 */ | 1005 */ |
1167 protected void enableLocationMode() { | 1006 protected void enableLocationMode() { |
1168 mode.setValue(FIELD_MODE, FIELD_VALUE_LOCATION); | 1007 mode.setValue(FIELD_MODE, FIELD_VALUE_LOCATION); |
1169 container.hideMember(distancePanel); | 1008 container.hideMember(distancePanel); |
1170 container.showMember(locationPanel); | 1009 container.showMember(locationPanel); |
1010 setupDistanceInfoTable(locationsTable, false, false); | |
1011 setupDistanceInfoTable(distanceTable, true, true); | |
1012 inputTables.updateTab(0, locationsTable); | |
1013 inputTables.updateTab(1, distanceTable); | |
1171 } | 1014 } |
1172 | 1015 |
1173 | 1016 |
1174 /** | 1017 /** |
1175 * Activates the distance panel. | 1018 * Activates the distance panel. |
1176 */ | 1019 */ |
1177 protected void enableDistanceMode() { | 1020 protected void enableDistanceMode() { |
1178 mode.setValue(FIELD_MODE, FIELD_VALUE_DISTANCE); | 1021 mode.setValue(FIELD_MODE, FIELD_VALUE_DISTANCE); |
1179 container.hideMember(locationPanel); | 1022 container.hideMember(locationPanel); |
1180 container.showMember(distancePanel); | 1023 container.showMember(distancePanel); |
1024 setupDistanceInfoTable(locationsTable, true, false); | |
1025 setupDistanceInfoTable(distanceTable, false, true); | |
1026 inputTables.updateTab(0, locationsTable); | |
1027 inputTables.updateTab(1, distanceTable); | |
1181 } | 1028 } |
1182 | 1029 |
1183 | 1030 |
1184 /** | 1031 /** |
1185 * This method switches the input mode between location and distance input. | 1032 * This method switches the input mode between location and distance input. |
1357 | 1204 |
1358 distanceTable.setDataSource(new DistanceInfoDataSource( | 1205 distanceTable.setDataSource(new DistanceInfoDataSource( |
1359 url, river, "distances")); | 1206 url, river, "distances")); |
1360 locationsTable.setDataSource(new DistanceInfoDataSource( | 1207 locationsTable.setDataSource(new DistanceInfoDataSource( |
1361 url, river, "locations")); | 1208 url, river, "locations")); |
1362 locationDistanceTable.setDataSource(new DistanceInfoDataSource( | 1209 } |
1363 url, river, "locations")); | |
1364 } | |
1365 | |
1366 | 1210 |
1367 protected double getFrom() { | 1211 protected double getFrom() { |
1368 return from; | 1212 return from; |
1369 } | 1213 } |
1370 | 1214 |
1215 protected void setTo(String to) { | |
1216 try { | |
1217 double toValue = Double.parseDouble(to); | |
1218 setTo(toValue); | |
1219 } | |
1220 catch(NumberFormatException nfe) { | |
1221 // Is there anything to do? | |
1222 } | |
1223 } | |
1224 | |
1225 protected void setFrom(String from) { | |
1226 try { | |
1227 double fromValue = Double.parseDouble(from); | |
1228 setFrom(fromValue); | |
1229 } | |
1230 catch(NumberFormatException nfe) { | |
1231 // Is there anything to do? | |
1232 } | |
1233 } | |
1371 | 1234 |
1372 protected void setFrom(double from) { | 1235 protected void setFrom(double from) { |
1373 this.from = from; | 1236 this.from = from; |
1237 /* The doubling should be removed and this.from abolished */ | |
1238 distancePanel.setFrom(from); | |
1374 } | 1239 } |
1375 | 1240 |
1376 | 1241 |
1377 protected double getTo() { | 1242 protected double getTo() { |
1378 return to; | 1243 return to; |
1379 } | 1244 } |
1380 | 1245 |
1381 | 1246 |
1382 protected void setTo(double to) { | 1247 protected void setTo(double to) { |
1383 this.to = to; | 1248 this.to = to; |
1249 /* The doubling should be removed and this.to abolished */ | |
1250 distancePanel.setTo(to); | |
1384 } | 1251 } |
1385 | 1252 |
1386 | 1253 |
1387 protected double getStep() { | 1254 protected double getStep() { |
1388 return step; | 1255 return step; |
1396 | 1263 |
1397 protected double[] getLocationValues() { | 1264 protected double[] getLocationValues() { |
1398 return values; | 1265 return values; |
1399 } | 1266 } |
1400 | 1267 |
1268 protected void appendLocation(String loc) { | |
1269 double[] selected; | |
1270 if (getLocationValues() != null) { | |
1271 double[] val = getLocationValues(); | |
1272 selected = new double[val.length + 1]; | |
1273 for(int i = 0; i < val.length; i++){ | |
1274 selected[i] = val[i]; | |
1275 } | |
1276 try { | |
1277 selected[val.length] = Double.parseDouble(loc); | |
1278 } | |
1279 catch(NumberFormatException nfe) { | |
1280 // Is there anything to do here? | |
1281 } | |
1282 } | |
1283 else { | |
1284 selected = new double[1]; | |
1285 selected[0] = Double.parseDouble(loc); | |
1286 } | |
1287 setLocationValues(selected); | |
1288 } | |
1401 | 1289 |
1402 protected void setLocationValues(double[] values) { | 1290 protected void setLocationValues(double[] values) { |
1403 this.values = values; | 1291 this.values = values; |
1404 locationPanel.setValues(values); | 1292 locationPanel.setValues(values); |
1405 } | 1293 } |