void () { try { if (!checkDeferred(deferred, onDone)) return; Set<Object> currentElements = getSelectedElements(); if (checkCurrentSelection && !currentElements.isEmpty() && elements.length == currentElements.size()) { boolean runSelection = false; for (Object eachToSelect : elements) { if (!currentElements.contains(eachToSelect)) { runSelection = true; break; } } if (!runSelection) { selectVisible(elements[0], onDone, false, false, scrollToVisible); return; } } clearSelection(); Set<Object> toSelect = new HashSet<>(); ContainerUtil.addAllNotNull(toSelect, elements); if (addToSelection) { ContainerUtil.addAllNotNull(toSelect, currentElements); } if (checkIfInStructure) { toSelect.removeIf(each -> !isInStructure(each)); } Object[] elementsToSelect = ArrayUtil.toObjectArray(toSelect); if (wasRootNodeInitialized()) { int[] originalRows = myTree.getSelectionRows(); if (!addToSelection) { clearSelection(); } addNext(elementsToSelect, 0, new TreeRunnable("AbstractTreeUi._select: addNext") { @Override public void perform() { if (getTree().isSelectionEmpty()) { processInnerChange(new TreeRunnable("AbstractTreeUi._select: addNext: processInnerChange") { @Override public void perform() { restoreSelection(currentElements); } }); } runDone(onDone); } }, originalRows, deferred, scrollToVisible, canSmartExpand); } else { addToDeferred(elementsToSelect, onDone, addToSelection); } } finally { maybeReady(); } }