DefaultMutableTreeNode (List<MavenProject> projectList) { MavenProject[] projects = projectList.toArray(new MavenProject[0]); Arrays.sort(projects, new MavenProjectNamer.MavenProjectComparator()); Map<MavenProject, DefaultMutableTreeNode> projectsToNode = new HashMap<>(); for (MavenProject mavenProject : projects) { projectsToNode.put(mavenProject, new DefaultMutableTreeNode(mavenProject)); } DefaultMutableTreeNode root = new DefaultMutableTreeNode(); for (MavenProject mavenProject : projects) { DefaultMutableTreeNode parent; MavenProject aggregator = projectsManager.findAggregator(mavenProject); if (aggregator != null) { parent = projectsToNode.get(aggregator); } else { parent = root; } parent.add(projectsToNode.get(mavenProject)); } return root; }