void (@NotNull DefaultMutableTreeNode parentNode, int selectedIndex, Object disposedElement) { if (selectedIndex >= 0 && !getSelectedElements().isEmpty()) return; DefaultMutableTreeNode node = disposedElement == null ? null : getNodeForElement(disposedElement, false); if (node != null && isValidForSelectionAdjusting(node)) { Object newElement = getElementFor(node); addSelectionPath(getPathFor(node), true, getExpiredElementCondition(newElement), disposedElement); return; } if (selectedIndex >= 0) { if (parentNode.getChildCount() > 0) { if (parentNode.getChildCount() > selectedIndex) { TreeNode newChildNode = parentNode.getChildAt(selectedIndex); if (isValidForSelectionAdjusting(newChildNode)) { addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChildNode)), true, getExpiredElementCondition(disposedElement), disposedElement); } } else { TreeNode newChild = parentNode.getChildAt(parentNode.getChildCount() - 1); if (isValidForSelectionAdjusting(newChild)) { addSelectionPath(new TreePath(myTreeModel.getPathToRoot(newChild)), true, getExpiredElementCondition(disposedElement), disposedElement); } } } else { addSelectionPath(new TreePath(myTreeModel.getPathToRoot(parentNode)), true, getExpiredElementCondition(disposedElement), disposedElement); } } }