ListSelection<Object> (@NotNull JTree tree) { List<Object> entries = selected(tree).userObjects(); if (entries.size() > 1) { return ListSelection.createAt(entries, 0) .asExplicitSelection(); } ChangesBrowserNode<?> selected = selected(tree).iterateNodes().first(); List<Object> allEntries; if (underExpandByDefault(selected)) { allEntries = new AllExpandedByDefaultData(getRoot(tree)).userObjects(); } else { allEntries = all(tree).userObjects(); } if (allEntries.size() <= entries.size()) { return ListSelection.createAt(entries, 0) .asExplicitSelection(); } else { int index = selected != null ? ContainerUtil.indexOfIdentity(allEntries, selected.getUserObject()) : 0; return ListSelection.createAt(allEntries, index); } }