[service-view] reselect items after update only if selected paths changed

GitOrigin-RevId: 9a6696a3359236414f49a8c19654b04b094efeb5
This commit is contained in:
Konstantin Aleev
2019-06-11 17:39:53 +03:00
committed by intellij-monorepo-bot
parent 492ea47776
commit 7ee7b84af1
@@ -177,15 +177,20 @@ class ServiceTreeView extends ServiceView {
@Override
public void rootsChanged() {
AppUIUtil.invokeOnEdt(() -> {
List<ServiceViewItem> selectedItems = getSelectedItems();
TreePath[] currentPaths = myTree.getSelectionPaths();
List<TreePath> selectedPaths =
currentPaths == null || currentPaths.length == 0 ? Collections.emptyList() : Arrays.asList(currentPaths);
myTreeModel.rootsChanged();
if (selectedItems.isEmpty()) return;
if (selectedPaths.isEmpty()) return;
myTreeModel.getInvoker().invokeLater(() -> {
List<Promise<TreePath>> pathPromises =
ContainerUtil.map(selectedItems, item -> myTreeModel.findPath(item.getValue(), item.getRootContributor().getClass()));
ContainerUtil.mapNotNull(selectedPaths, path -> {
ServiceViewItem item = ObjectUtils.tryCast(path.getLastPathComponent(), ServiceViewItem.class);
return item == null ? null : myTreeModel.findPath(item.getValue(), item.getRootContributor().getClass());
});
Promises.collectResults(pathPromises, true).onProcessed(paths -> {
if (paths != null) {
if (paths != null && !paths.isEmpty() && !paths.equals(selectedPaths)) {
TreeUtil.promiseSelect(myTree, paths.stream().map(PathSelectionVisitor::new));
}
});