void (@NotNull Tool newTool, boolean setSelection) { CheckedTreeNode groupNode = findGroupNode(newTool.getGroup()); ToolsGroup group; if (groupNode == null) { group = new ToolsGroup<>(newTool.getGroup()); groupNode = addGroupNode(group); nodeWasInserted(groupNode); } else { //noinspection unchecked group = (ToolsGroup<T>)groupNode.getUserObject(); } CheckedTreeNode toolNode = addToolNode(groupNode, newTool); group.addElement(newTool); if (setSelection) { TreePath treePath = new TreePath(toolNode.getPath()); myTree.expandPath(treePath); myTree.getSelectionModel().setSelectionPath(treePath); } myIsModified = true; }