TreeExpander () { return new DefaultTreeExpander(this::getTree) { private boolean isExpandAllAllowed() { JTree tree = getTree(); TreeModel model = tree == null ? null : tree.getModel(); return model == null || model instanceof AsyncTreeModel || model instanceof InvokerSupplier; } @Override public boolean isExpandAllVisible() { return isExpandAllAllowed() && Registry.is("ide.project.view.expand.all.action.visible"); } @Override public boolean canExpand() { return isExpandAllAllowed() && super.canExpand(); } @Override protected void collapseAll(@NotNull JTree tree, boolean strict, int keepSelectionLevel) { super.collapseAll(tree, false, keepSelectionLevel); } }; }