1 11 12 package org.eclipse.ui.internal.navigator.extensions; 13 14 import java.util.Comparator ; 15 16 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 17 import org.eclipse.ui.navigator.INavigatorContentExtension; 18 19 23 public class ExtensionPriorityComparator implements Comparator { 24 25 28 public static final ExtensionPriorityComparator INSTANCE = new ExtensionPriorityComparator(true); 29 30 33 public static final ExtensionPriorityComparator DESCENDING = new ExtensionPriorityComparator(false); 34 35 private final int sortAscending; 36 37 public ExtensionPriorityComparator(boolean toSortAscending) { 38 sortAscending = toSortAscending ? 1 : -1; 39 } 40 41 46 public int compare(Object o1, Object o2) { 47 48 INavigatorContentDescriptor lvalue = null; 49 INavigatorContentDescriptor rvalue = null; 50 51 if (o1 instanceof INavigatorContentDescriptor) { 52 lvalue = (INavigatorContentDescriptor) o1; 53 } else if (o1 instanceof INavigatorContentExtension) { 54 lvalue = ((INavigatorContentExtension) o1).getDescriptor(); 55 } 56 57 if (o2 instanceof INavigatorContentDescriptor) { 58 rvalue = (INavigatorContentDescriptor) o2; 59 } else if (o2 instanceof INavigatorContentExtension) { 60 rvalue = ((INavigatorContentExtension) o2).getDescriptor(); 61 } 62 63 if (lvalue == null || rvalue == null) { 64 return -1 * sortAscending; 65 } 66 67 int c = lvalue.getPriority() - rvalue.getPriority(); 68 if (c != 0) { 69 return c * sortAscending; 70 } 71 return lvalue.getId().compareTo(rvalue.getId()) * sortAscending; 72 73 } 74 75 } 76 | Popular Tags |