Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Maven Projects wizard does not sort projects #1841

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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