Skip to content

Commit

Permalink
Cleared warnings, also one from lgtm.com
Browse files Browse the repository at this point in the history
  • Loading branch information
reikjarloekl committed Aug 18, 2022
1 parent 40e070a commit 0566950
Showing 1 changed file with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class FilterableTreeItem<T> extends CheckBoxTreeItem<T> {
private final FilteredList<FilterableTreeItem<T>> filteredList =new FilteredList<>(sourceList);
private final ObjectProperty<TreeItemPredicate<T>> predicate = new SimpleObjectProperty<>();

private Map<FilterableTreeItem<T>, Integer> childItemIndexesMap = new HashMap<>();
private final Map<FilterableTreeItem<T>, Integer> childItemIndexesMap = new HashMap<>();

/**
* Creates a new {@link TreeItem} with sorted children.
Expand All @@ -58,28 +58,25 @@ public FilterableTreeItem(T value) {
}

private void setupFilteredListPredicateBindings() {
filteredList.predicateProperty().bind(Bindings.createObjectBinding(() -> {
Predicate<FilterableTreeItem<T>> treeItemPredicate = child -> {
// Set the predicate of child items to force filtering
if (child instanceof FilterableTreeItem) {
FilterableTreeItem<T> filterableChild = (FilterableTreeItem<T>) child;
filterableChild.setPredicate(predicate.get());
}

// If there is no predicate, keep this tree item
if (predicate.get() == null) {
return true;
}

// If there are children, keep this tree item
if (child.getChildren().size() > 0) {
return true;
}

// Otherwise ask the TreeItemPredicate
return predicate.get().test(this, child.getValue());
};
return treeItemPredicate;
filteredList.predicateProperty().bind(Bindings.createObjectBinding(() -> child -> {
// Set the predicate of child items to force filtering
if (child != null) {
child.setPredicate(predicate.get());
}

// If there is no predicate, keep this tree item
if (predicate.get() == null) {
return true;
}

// If there are children, keep this tree item
assert child != null;
if (child.getChildren().size() > 0) {
return true;
}

// Otherwise ask the TreeItemPredicate
return predicate.get().test(this, child.getValue());
}, predicate));

Bindings.bindContent(getChildren(), getBackingList());
Expand Down

0 comments on commit 0566950

Please sign in to comment.