diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java index dffd36df02..a4e5e6fcae 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenImportWizardPage.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -250,7 +251,7 @@ public Object[] getElements(Object element) { if(element instanceof List) { @SuppressWarnings("unchecked") List projects = (List) element; - return projects.toArray(new MavenProjectInfo[projects.size()]); + return sorted(projects); } return EMPTY; } @@ -260,14 +261,20 @@ public Object[] getChildren(Object parentElement) { if(parentElement instanceof List) { @SuppressWarnings("unchecked") List projects = (List) parentElement; - return projects.toArray(new MavenProjectInfo[projects.size()]); + return sorted(projects); } else if(parentElement instanceof MavenProjectInfo mavenProjectInfo) { Collection projects = mavenProjectInfo.getProjects(); - return projects.toArray(new MavenProjectInfo[projects.size()]); + return sorted(projects); } return EMPTY; } + private MavenProjectInfo[] sorted(Collection projects) { + List sortedProjects = new ArrayList<>(projects); + sortedProjects.sort(Comparator.comparing(MavenProjectInfo::getLabel)); + return sortedProjects.toArray(MavenProjectInfo[]::new); + } + @Override public Object getParent(Object element) { return null;