1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.resources.IProject; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.search.ui.ISearchResultViewEntry; 18 19 22 public class PathNameSorter extends JavaSearchSorter { 23 24 27 public int compare(Viewer viewer, Object e1, Object e2) { 28 String name1= null; 29 String name2= null; 30 ISearchResultViewEntry entry1= null; 31 ISearchResultViewEntry entry2= null; 32 33 if (e1 instanceof ISearchResultViewEntry) { 34 entry1= (ISearchResultViewEntry)e1; 35 name1= getLabel(e1); 36 } 37 if (e2 instanceof ISearchResultViewEntry) { 38 entry2= (ISearchResultViewEntry)e2; 39 name2= getLabel(e2); 40 } 41 if (name1 == null) 42 name1= ""; if (name2 == null) 44 name2= ""; 46 IResource resource= null; 47 if (entry1 != null) 48 resource= entry1.getResource(); 49 if (resource != null && entry2 != null && resource == entry2.getResource()) { 50 51 if (resource instanceof IProject || resource.getFileExtension().equalsIgnoreCase("jar") || resource.getFileExtension().equalsIgnoreCase("zip")) return getCollator().compare(name1, name2); 54 55 int startPos1= -1; 57 int startPos2= -1; 58 IMarker marker1= entry1.getSelectedMarker(); 59 IMarker marker2= entry2.getSelectedMarker(); 60 61 if (marker1 != null) 62 startPos1= marker1.getAttribute(IMarker.CHAR_START, -1); 63 if (marker2 != null) 64 startPos2= marker2.getAttribute(IMarker.CHAR_START, -1); 65 return startPos1 - startPos2; 66 } 67 68 return getCollator().compare(name1, name2); 69 } 70 71 protected int getLabelAppearance() { 72 return JavaSearchResultLabelProvider.SHOW_PATH; 73 } 74 } 75 76 | Popular Tags |