1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.IType; 16 import org.eclipse.jface.viewers.Viewer; 17 18 public class ParentSorter extends NameSorter { 19 public int compare(Viewer viewer, Object e1, Object e2) { 20 String leftParent= getParentName(e1); 21 String rightParent= getParentName(e2); 22 int result= collator.compare(leftParent, rightParent); 23 if (result == 0) 24 return super.compare(viewer, e1, e2); 25 else 26 return result; 27 } 28 29 private String getParentName(Object element) { 30 if (element instanceof IJavaElement) { 31 IJavaElement parent= ((IJavaElement)element).getParent(); 32 if (parent instanceof IType) 33 return ((IType)parent).getFullyQualifiedName(); 34 if (parent != null) 35 return parent.getElementName(); 36 } 37 if (element instanceof IResource) { 38 IResource parent= ((IResource)element).getParent(); 39 if (parent != null) 40 return parent.getName(); 41 } 42 return ""; } 44 } 45 | Popular Tags |