1 11 package org.eclipse.help.ui.internal.views; 12 13 import org.eclipse.help.IHelpResource; 14 import org.eclipse.help.search.ISearchEngineResult; 15 import org.eclipse.jface.viewers.Viewer; 16 import org.eclipse.jface.viewers.ViewerComparator; 17 18 public class FederatedSearchSorter extends ViewerComparator { 19 public FederatedSearchSorter() { 20 super(ReusableHelpPart.SHARED_COLLATOR); 21 } 22 23 public int category(Object element) { 24 if (element instanceof ISearchEngineResult) { 25 ISearchEngineResult r = (ISearchEngineResult)element; 26 IHelpResource c = r.getCategory(); 27 if (c!=null) { 28 String label = c.getLabel(); 29 if (label.length()==0) 30 return 10; 31 return 5; 32 } 33 } 34 return super.category(element); 35 } 36 37 38 41 public int compare(Viewer viewer, Object e1, Object e2) { 42 int cat1 = category(e1); 43 int cat2 = category(e2); 44 45 if (cat1 != cat2) 46 return cat1 - cat2; 47 try { 48 ISearchEngineResult r1 = (ISearchEngineResult) e1; 49 ISearchEngineResult r2 = (ISearchEngineResult) e2; 50 IHelpResource c1 = r1.getCategory(); 51 IHelpResource c2 = r2.getCategory(); 52 if (c1!=null && c2!=null) { 53 int cat = super.compare(viewer, c1.getLabel(), c2.getLabel()); 54 if (cat!=0) return cat; 55 } 56 float rank1 = ((ISearchEngineResult) e1).getScore(); 57 float rank2 = ((ISearchEngineResult) e2).getScore(); 58 if (rank1 - rank2 > 0) { 59 return -1; 60 } else if (rank1 == rank2) { 61 return 0; 62 } else { 63 return 1; 64 } 65 } catch (Exception e) { 66 } 67 return super.compare(viewer, e1, e2); 68 } 69 } 70 | Popular Tags |