void (Runnable action) { ApplicationManager.getApplication().invokeLater(() -> { final List<TreePath> selectedPaths = TreeUtil.collectSelectedPaths(myTree); final List<TreePath> expandedPaths = TreeUtil.collectExpandedPaths(myTree); action.run(); for (TreePath path : selectedPaths) { TreeUtil.promiseSelect(myTree, path); } for (TreePath path : expandedPaths) { TreeUtil.promiseExpand(myTree, path); } }); }