Marco Maisano

Greenhorn
+ Follow
since Aug 30, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marco Maisano

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.

4 weeks ago