void (@NotNull ExternalProjectPojo topLevelProject, @NotNull Collection<? extends ExternalProjectPojo> subProjects) { ExternalSystemNode<ExternalProjectPojo> topLevelProjectNode = ensureProjectNodeExists(topLevelProject); Map<String/*config path*/, ExternalProjectPojo> toAdd = new HashMap<>(); for (ExternalProjectPojo subProject : subProjects) { toAdd.put(subProject.getPath(), subProject); } toAdd.remove(topLevelProject.getPath()); for (int i = 0; i < topLevelProjectNode.getChildCount(); i++) { ExternalSystemNode<?> child = topLevelProjectNode.getChildAt(i); Object childElement = child.getDescriptor().getElement(); if (childElement instanceof ExternalTaskExecutionInfo) { continue; } if (toAdd.remove(((ExternalProjectPojo)childElement).getPath()) == null) { removeNodeFromParent(child); //noinspection AssignmentToForLoopParameter i--; } } if (!toAdd.isEmpty()) { for (Map.Entry<String, ExternalProjectPojo> entry : toAdd.entrySet()) { ExternalProjectPojo element = new ExternalProjectPojo(entry.getValue().getName(), entry.getValue().getPath()); insertNodeInto(new ExternalSystemNode<>(descriptor(element, myUiAware.getProjectIcon())), topLevelProjectNode); } } }