void (AnActionButton button) { final TreePath path = myTree.getSelectionPath(); final DefaultMutableTreeNode selected = path == null ? (DefaultMutableTreeNode)myTree.getModel().getRoot() : (DefaultMutableTreeNode)path.getLastPathComponent(); final Object selectedNode = selected.getUserObject(); myTree.stopEditing(); Object element; if (model instanceof DefaultTreeModel && myProducer != null) { element = myProducer.createElement(); if (element == null) return; } else { element = null; } DefaultMutableTreeNode parent = selected; if ((selectedNode instanceof SimpleNode && ((SimpleNode)selectedNode).isAlwaysLeaf()) || !selected.getAllowsChildren()) { parent = (DefaultMutableTreeNode)selected.getParent(); } if (parent != null) { parent.insert(new DefaultMutableTreeNode(element), parent.getChildCount()); } final TreePath createdPath = model.addNode(new TreePath(parent.getPath())); if (path != null) { TreeUtil.selectPath(myTree, createdPath); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myTree, true)); } }