Promise<Void> (@NotNull Object service, @NotNull Class<?> contributorClass, boolean safe) { ServiceViewItem selectedItem = myLastSelection; if (selectedItem == null || !selectedItem.getValue().equals(service)) { AsyncPromise<Void> result = new AsyncPromise<>(); Promise<TreePath> pathPromise = safe ? myTreeModel.findPathSafe(service, contributorClass) : myTreeModel.findPath(service, contributorClass); pathPromise .onError(result::setError) .onSuccess(path -> { TreeUtil.promiseSelect(myTree, new PathSelectionVisitor(path)) .onError(result::setError) .onSuccess(selectedPath -> { result.setResult(null); cancelSelectionUpdate(); }); cancelSelectionUpdate(); }); return result; } return Promises.resolvedPromise(); }