DefaultMutableTreeNode (@Nullable PatternDescriptor descriptor) { DefaultMutableTreeNode root = new DefaultMutableTreeNode(descriptor) { @NotNull @Override public String toString() { Object object = getUserObject(); return object == null ? "" : ((PatternDescriptor)object).getName(); } }; String id = descriptor == null ? PatternDescriptor.ROOT : descriptor.getId(); Collection<PatternDescriptor> collection = myMap.get(id); for (PatternDescriptor childDescriptor : collection) { root.add(createNode(childDescriptor)); } return root; }