void (DirectoryChooser.ItemWrapper itemWrapper) { myItems.add(itemWrapper); final Module module = itemWrapper.getModule(); DefaultMutableTreeNode node = myModuleNodes.get(module); if (node == null) { node = new DefaultMutableTreeNode(module, true); final List<String> groupPath = module != null ? myModuleGrouper.getGroupPath(module) : null; if (groupPath == null || groupPath.isEmpty()) { insertNode(node, myRootNode); } else { final DefaultMutableTreeNode parentNode = ModuleGroupUtil.buildModuleGroupPath( new ModuleGroup(groupPath), myRootNode, myModuleGroupNodes, parentChildRelation -> insertNode(parentChildRelation.getChild(), parentChildRelation.getParent()), moduleGroup -> new DefaultMutableTreeNode(moduleGroup, true) ); insertNode(node, parentNode); } myModuleNodes.put(module, node); } final DefaultMutableTreeNode itemNode = new DefaultMutableTreeNode(itemWrapper, false); myItemNodes.put(itemWrapper, itemNode); insertNode(itemNode, node); ((DefaultTreeModel)myTree.getModel()).nodeStructureChanged(node); }