DefaultTreeModel () { final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); final Ref<Integer> count = new Ref<>(0); Ref<Map<MemberChooserObject, ParentNode>> mapRef = new Ref<>(); mapRef.set(FactoryMap.create(key -> { ParentNode node = null; DefaultMutableTreeNode parentNode1 = rootNode; if (supportsNestedContainers() && key instanceof ClassMember) { MemberChooserObject parentNodeDelegate = ((ClassMember)key).getParentNodeDelegate(); if (parentNodeDelegate != null) { parentNode1 = mapRef.get().get(parentNodeDelegate); } } if (isContainerNode(key)) { final ContainerNode containerNode = new ContainerNode(parentNode1, key, count); node = containerNode; myContainerNodes.add(containerNode); } if (node == null) { node = new ParentNode(parentNode1, key, count); } return node; })); final Map<MemberChooserObject, ParentNode> map = mapRef.get(); for (T object : myElements) { final ParentNode parentNode = map.get(object.getParentNodeDelegate()); final MemberNode elementNode = createMemberNode(count, object, parentNode); myNodeToParentMap.put(elementNode, parentNode); myElementToNodeMap.put(object, elementNode); } return new DefaultTreeModel(rootNode); }