void (@NotNull JTree tree, boolean expand, @Nullable Object preferredSelection) { getInvoker().invoke(() -> { getTreeStructure().refilter(); invalidateAsync().thenRun(() -> { if (expand) { List<FilteringTreeStructure.FilteringNode> leaves = getTreeStructure().getVisibleLeaves(); Set<FilteringTreeStructure.FilteringNode> set = new HashSet<>(leaves); for (FilteringTreeStructure.FilteringNode node : leaves) { do { node = node.getParentNode(); } while (node != null && set.add(node)); } TreeUtil.promiseMakeVisible(tree, path -> { Object object = TreeUtil.getLastUserObject(path); if (!(object instanceof FilteringTreeStructure.FilteringNode)) return TreeVisitor.Action.CONTINUE; return set.contains(object) ? TreeVisitor.Action.CONTINUE : TreeVisitor.Action.SKIP_CHILDREN; }); } adjustSelection(tree, preferredSelection); }); }); }