1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import org.eclipse.jface.viewers.Viewer; 14 import org.eclipse.jface.viewers.ViewerComparator; 15 import org.eclipse.osgi.service.resolver.BundleDescription; 16 import org.eclipse.osgi.service.resolver.BundleSpecification; 17 import org.eclipse.osgi.service.resolver.ImportPackageSpecification; 18 import org.eclipse.pde.internal.ui.PDEPlugin; 19 20 public class DependenciesViewComparator extends ViewerComparator { 21 22 private static DependenciesViewComparator fComparator = null; 23 24 private DependenciesViewComparator() { 25 super(); 26 } 27 28 public int compare(Viewer viewer, Object e1, Object e2) { 29 return getId(e1).compareTo(getId(e2)); 30 } 31 32 private String getId(Object obj) { 33 BundleDescription desc = null; 34 if (obj instanceof ImportPackageSpecification) { 35 return ((ImportPackageSpecification)obj).getName(); 36 } else if (obj instanceof BundleSpecification) { 37 desc = (BundleDescription)((BundleSpecification)obj).getSupplier(); 38 } else if (obj instanceof BundleDescription) 39 desc = (BundleDescription)obj; 40 if (desc != null) 41 return PDEPlugin.getDefault().getLabelProvider().getObjectText(desc); 42 return ""; } 44 45 public static DependenciesViewComparator getViewerComparator() { 46 if (fComparator == null) 47 fComparator = new DependenciesViewComparator(); 48 return fComparator; 49 } 50 51 } 52 | Popular Tags |