sort labels for new reference menu
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / e4 / command / DynamicNewObjectMenuE4.java
index ca2469d003a81f81edffdb2296b200b52c238ca2..fa09ac676e51310d622fbd82a9ed2f0959328496 100644 (file)
@@ -9,7 +9,9 @@
 
 package eu.etaxonomy.taxeditor.bulkeditor.e4.command;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
@@ -47,15 +49,37 @@ public class DynamicNewObjectMenuE4 {
         editor = (BulkEditor) activePart.getObject();
 
                classLabelPairs = getClassLabelPairs();
+               
 
                MMenu menu = MMenuFactory.INSTANCE.createMenu();
         menu.setLabel(Messages.DynamicNewObjectMenuE4_NEW);
         items.add(menu);
-
-        for(final Object key : classLabelPairs.keySet()){
+        List<Object> keys = new ArrayList(classLabelPairs.keySet());
+        Collections.sort(keys, new Comparator<Object>() {
+
+                       @Override
+                       public int compare(Object o1, Object o2) {
+                               if (o1 == o2) {
+                                       return 0;
+                               }
+                               if (o1 == null) {
+                                       return -1;
+                               }
+                               if (o2 == null) {
+                                       return 1;
+                               }
+                               if (o1 instanceof String && o2 instanceof String) {
+                                       return ((String)o1).compareTo((String)o2);
+                               }
+                               return 0;
+                       }
+               });
+        for(final Object key : keys){
             createMenuItem(menu, key);
         }
        }
+    
+    
 
        private void createMenuItem(MMenu menu, final Object key){
            MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();