void (Map<TemplateImpl, DefaultMutableTreeNode> map, @NotNull String newGroupName) { List<TreePath> toSelect = new ArrayList<>(); for (TemplateImpl template : map.keySet()) { DefaultMutableTreeNode oldTemplateNode = map.get(template); TemplateGroup oldGroup = getTemplateGroup(template.getGroupName()); if (oldGroup != null) { oldGroup.removeElement(template); } template.setGroupName(newGroupName); removeNodeFromParent(oldTemplateNode); toSelect.add(new TreePath(registerTemplate(template).getPath())); } TreeUtil.selectPaths(myTree, toSelect); }