void (@Nullable final String groupName, @Nullable final String templateKey) { TreeUtil.traverseDepth(myTreeRoot, node -> { Object o = ((DefaultMutableTreeNode)node).getUserObject(); if (templateKey == null && o instanceof TemplateGroup && Objects.equals(groupName, ((TemplateGroup)o).getName()) || o instanceof TemplateImpl && Objects.equals(templateKey, ((TemplateImpl)o).getKey()) && Objects.equals(groupName, ((TemplateImpl)o).getGroupName())) { setSelectedNode((DefaultMutableTreeNode)node); return false; } return true; }); }