package com.demonwav.mcdev.toolwindow;

import com.demonwav.mcdev.platform.MinecraftModule;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

import javax.swing.JPanel;

public class MinecraftToolWindow {
    private JPanel panel;

    private Project project;
    private Set<MinecraftModule> mcModules = new HashSet<>();

    public void setProjectAndInit(@NotNull Project project) {
        this.project = project;

        final Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module module : modules) {
            final MinecraftModule instance = MinecraftModule.getInstance(module);
            if (instance != null) {
                mcModules.add(instance);
            }
        }
    }

    public JPanel getPanel() {
        return panel;
    }
}

@@ -224,16 +224,64 @@
 roject;%0A
+import com.intellij.util.containers.OrderedSet;%0A
 import o
@@ -336,37 +336,19 @@
 til.
-HashSet;%0Aimport java.util.Set
+Collections
 ;%0A%0Ai
@@ -477,16 +477,23 @@
 private 
+Ordered
 Set%3CMine
@@ -525,12 +525,15 @@
 new 
-Hash
+Ordered
 Set%3C
@@ -933,24 +933,144 @@
  %7D%0A        %7D
+%0A%0A        Collections.sort(mcModules, (m1, m2) -%3E m1.getIdeaModule().getName().compareTo(m2.getIdeaModule().getName()));
 %0A    %7D%0A%0A    

Make the Module set ordered and keep it sorted