Skip to content

Commit

Permalink
Import Maven Projects wizard does not sort projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasReinhardt authored and akurtakov committed Oct 2, 2024
1 parent 2a342a2 commit aa4f825
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -250,7 +251,7 @@ public Object[] getElements(Object element) {
if(element instanceof List) {
@SuppressWarnings("unchecked")
List<MavenProjectInfo> projects = (List<MavenProjectInfo>) element;
return projects.toArray(new MavenProjectInfo[projects.size()]);
return sorted(projects);
}
return EMPTY;
}
Expand All @@ -260,14 +261,20 @@ public Object[] getChildren(Object parentElement) {
if(parentElement instanceof List) {
@SuppressWarnings("unchecked")
List<MavenProjectInfo> projects = (List<MavenProjectInfo>) parentElement;
return projects.toArray(new MavenProjectInfo[projects.size()]);
return sorted(projects);
} else if(parentElement instanceof MavenProjectInfo mavenProjectInfo) {
Collection<MavenProjectInfo> projects = mavenProjectInfo.getProjects();
return projects.toArray(new MavenProjectInfo[projects.size()]);
return sorted(projects);
}
return EMPTY;
}

private MavenProjectInfo[] sorted(Collection<MavenProjectInfo> projects) {
List<MavenProjectInfo> sortedProjects = new ArrayList<>(projects);
sortedProjects.sort(Comparator.comparing(MavenProjectInfo::getLabel));
return sortedProjects.toArray(MavenProjectInfo[]::new);
}

@Override
public Object getParent(Object element) {
return null;
Expand Down

0 comments on commit aa4f825

Please sign in to comment.