void (@NotNull List<? extends TreeNode> toInsert, @NotNull DefaultMutableTreeNode parentNode) { sortChildren(parentNode, toInsert, false, true); List<TreeNode> all = new ArrayList<>(toInsert.size() + parentNode.getChildCount()); all.addAll(toInsert); all.addAll(TreeUtil.listChildren(parentNode)); if (!toInsert.isEmpty()) { sortChildren(parentNode, all, true, true); int[] newNodeIndices = new int[toInsert.size()]; int eachNewNodeIndex = 0; TreeMap<Integer, TreeNode> insertSet = new TreeMap<>(); for (int i = 0; i < toInsert.size(); i++) { TreeNode eachNewNode = toInsert.get(i); while (all.get(eachNewNodeIndex) != eachNewNode) { eachNewNodeIndex++; } newNodeIndices[i] = eachNewNodeIndex; insertSet.put(eachNewNodeIndex, eachNewNode); } for (Map.Entry<Integer, TreeNode> entry : insertSet.entrySet()) { TreeNode eachNode = entry.getValue(); Integer index = entry.getKey(); parentNode.insert((MutableTreeNode)eachNode, index); } myTreeModel.nodesWereInserted(parentNode, newNodeIndices); } else { List<TreeNode> before = new ArrayList<>(all); sortChildren(parentNode, all, true, false); if (!before.equals(all)) { processInnerChange(new TreeRunnable("AbstractTreeUi.insertNodesInto") { @Override public void perform() { Enumeration<TreePath> expanded = getTree().getExpandedDescendants(getPathFor(parentNode)); TreePath[] selected = getTree().getSelectionModel().getSelectionPaths(); parentNode.removeAllChildren(); for (TreeNode each : all) { parentNode.add((MutableTreeNode)each); } nodeStructureChanged(parentNode); if (expanded != null) { while (expanded.hasMoreElements()) { expandSilently(expanded.nextElement()); } } if (selected != null) { for (TreePath each : selected) { if (!getTree().getSelectionModel().isPathSelected(each)) { addSelectionSilently(each); } } } } }); } } }