1 11 package org.eclipse.search.internal.ui.text; 12 13 import org.eclipse.jface.viewers.ILabelProvider; 14 import org.eclipse.jface.viewers.Viewer; 15 import org.eclipse.jface.viewers.ViewerSorter; 16 17 import org.eclipse.search.ui.ISearchResultView; 18 import org.eclipse.search.ui.ISearchResultViewEntry; 19 import org.eclipse.search.ui.SearchUI; 20 21 import org.eclipse.search.internal.ui.util.FileLabelProvider; 22 23 26 public class ResourcePathSorter extends ViewerSorter { 27 28 31 public int compare(Viewer viewer, Object e1, Object e2) { 32 String name1= null; 33 String name2= null; 34 35 if (e1 instanceof ISearchResultViewEntry) 36 name1= ((ISearchResultViewEntry)e1).getResource().getFullPath().toString(); 37 if (e2 instanceof ISearchResultViewEntry) 38 name2= ((ISearchResultViewEntry)e2).getResource().getFullPath().toString(); 39 if (name1 == null) 40 name1= ""; if (name2 == null) 42 name2= ""; return getCollator().compare(name1, name2); 44 } 45 46 49 public boolean isSorterProperty(Object element, String property) { 50 return true; 51 } 52 53 56 public void sort(Viewer viewer, Object [] elements) { 57 ISearchResultView view= SearchUI.getSearchResultView(); 59 if (view != null) { 60 ILabelProvider labelProvider= view.getLabelProvider(); 61 if (labelProvider instanceof FileLabelProvider) 62 ((FileLabelProvider)labelProvider).setOrder(FileLabelProvider.SHOW_PATH_LABEL); 63 } 64 super.sort(viewer, elements); 65 } 66 } 67 | Popular Tags |