1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.core.runtime.Path; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jface.viewers.Viewer; 18 19 public class PathSorter extends NameSorter { 20 public int compare(Viewer viewer, Object e1, Object e2) { 21 IPath path1= getPath(e1); 22 IPath path2=getPath(e2); 23 int result= compare(path1, path2); 24 if (result != 0) 25 return result; 26 else 27 return super.compare(viewer, e1, e2); 28 } 29 30 34 private IPath getPath(Object element) { 35 if (element instanceof IJavaElement) 36 return ((IJavaElement)element).getPath(); 37 if (element instanceof IResource) 38 return ((IResource)element).getFullPath(); 39 return new Path(""); } 41 42 protected int compare(IPath path1, IPath path2) { 43 int segmentCount= Math.min(path1.segmentCount(), path2.segmentCount()); 44 for (int i= 0; i < segmentCount; i++) { 45 int value= collator.compare(path1.segment(i), path2.segment(i)); 46 if (value != 0) 47 return value; 48 } 49 return path1.segmentCount() - path2.segmentCount(); 50 } 51 } 52 | Popular Tags |