1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 import java.util.Arrays ; 14 import java.util.Collections ; 15 import java.util.Comparator ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.debug.core.DebugPlugin; 23 import org.eclipse.debug.core.ILaunchConfiguration; 24 import org.eclipse.debug.core.ILaunchConfigurationType; 25 import org.eclipse.ui.model.WorkbenchViewerComparator; 26 27 33 public class LaunchConfigurationComparator extends WorkbenchViewerComparator { 34 35 38 private static Map fgCategories; 39 40 43 public int category(Object element) { 44 Map map = getCategories(); 45 if (element instanceof ILaunchConfiguration) { 46 ILaunchConfiguration configuration = (ILaunchConfiguration) element; 47 try { 48 Integer i = (Integer ) map.get(configuration.getType()); 49 if (i != null) { 50 return i.intValue(); 51 } 52 } catch (CoreException e) { 53 } 54 } 55 return map.size(); 56 } 57 58 62 private Map getCategories() { 63 if (fgCategories == null) { 64 fgCategories = new HashMap (); 65 List types = Arrays.asList(DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes()); 66 Collections.sort(types, new Comparator () { 67 public int compare(Object o1, Object o2) { 68 ILaunchConfigurationType t1 = (ILaunchConfigurationType) o1; 69 ILaunchConfigurationType t2 = (ILaunchConfigurationType) o2; 70 return t1.getName().compareTo(t2.getName()); 71 } 72 73 }); 74 Iterator iterator = types.iterator(); 75 int i = 0; 76 while (iterator.hasNext()) { 77 fgCategories.put(iterator.next(), new Integer (i)); 78 i++; 79 } 80 } 81 return fgCategories; 82 } 83 } 84 | Popular Tags |