1 11 package org.eclipse.help.ui.internal.views; 12 13 import org.eclipse.help.IContext2; 14 import org.eclipse.help.IHelpResource; 15 import org.eclipse.jface.viewers.Viewer; 16 import org.eclipse.jface.viewers.ViewerComparator; 17 18 public class ContextHelpSorter extends ViewerComparator { 19 private IContext2 context; 20 21 public ContextHelpSorter(IContext2 context) { 22 super(ReusableHelpPart.SHARED_COLLATOR); 23 this.context = context; 24 } 25 26 public int category(Object element) { 27 if (element instanceof IHelpResource) { 28 IHelpResource r = (IHelpResource)element; 29 String c = context.getCategory(r); 30 if (c!=null) { 31 return -5; 32 } 33 } 34 return super.category(element); 35 } 36 37 40 public int compare(Viewer viewer, Object e1, Object e2) { 41 int cat1 = category(e1); 42 int cat2 = category(e2); 43 44 if (cat1 != cat2) 45 return cat1 - cat2; 46 IHelpResource r1 = (IHelpResource) e1; 47 IHelpResource r2 = (IHelpResource) e2; 48 String c1 = context.getCategory(r1); 49 String c2 = context.getCategory(r2); 50 if (c1!=null && c2!=null) { 51 int cat = super.compare(viewer, c1, c2); 52 if (cat!=0) return cat; 53 } 54 return 0; 55 } 56 } 57 | Popular Tags |