• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Filtering: Triggers a predicate when values ​​change dynamically

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm new to this forum.

I have a problem with Table View filtering.... in particular the filter work well, then when new entry are putted into the list, they are correctly filtered, but the problem starts when the the filter is active and the filtering parameters change dynamically, then in this condition the predicate is not re-called.

I created a TableView where the items are populated dynamically and putted into an ObservaleList.

Then, the ObservaleList is passed to the FilteredList.

The list is of type FXTargetBean, that is composed by different fileds: name, speed ....

Then, the code for filteredList is


ObjectProperty<Predicate<FXTargetBean>> checkSpeedPred = new SimpleObjectProperty<Predicate<FXTargetBean>>();

checkSpeedPred.bind(FXFilterTableView.getSpeedBind(FXtableTarget, checkRadio, fromSpeedCheckBox));

filteredData.predicateProperty().bind(Bindings.createObjectBinding(()-> textPred.get(), textPred));


where, the implementation of the Predicate is

public static ObjectBinding<Predicate<FXTargetBean>> getSpeedBind(TableView<FXTargetBean> FXtableTarget, Observable dep, CheckBox fromSpeedCheckBox) {

ObjectBinding<Predicate<FXTargetBean>> binding = Bindings.createObjectBinding(() -> {
Predicate<FXTargetBean> predicate = bean -> {
if(!fromSpeedCheckBox.isSelected()) {
return true;
}

if(bean.getSpeed() != null) {
System.out.println("LOG Not NULL");
if(bean.getSpeed()>=4.0) {
System.out.println("LOG Greather 4");
if(fromSpeedCheckBox.isSelected()) {
FXtableTarget.refresh();
return true;
}
}
}

return false;
};
return predicate;
}, dep);

return binding;


Everything so far works fine, so when I have new entries, they are inserted into the table and filtered.

The problem, as mentioned, is that when the predicate is called and therefore the filter is active on the speed of the item, if this speed changes dynamically, the predicate is not called.

In fact, in the code, I have implemented a filter that shows items with a speed greater than 4.

Here, after the predicate is called, if the speed of an item goes below 4, since the predicate is not recalled, the item is not removed.

 
Don't listen to Steve. Just read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic