1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.jface.viewers.Viewer; 14 import org.eclipse.jface.viewers.ViewerSorter; 15 import org.eclipse.ui.internal.registry.Category; 16 import org.eclipse.ui.internal.registry.ViewRegistry; 17 import org.eclipse.ui.internal.registry.ViewRegistryReader; 18 import org.eclipse.ui.views.IViewCategory; 19 import org.eclipse.ui.views.IViewDescriptor; 20 21 24 public class ViewSorter extends ViewerSorter { 25 private ViewRegistry viewReg; 26 27 32 public ViewSorter(ViewRegistry reg) { 33 super(); 34 viewReg = reg; 35 } 36 37 42 public int compare(Viewer viewer, Object e1, Object e2) { 43 if (e1 instanceof IViewDescriptor) { 44 String str1 = DialogUtil.removeAccel(((IViewDescriptor) e1) 45 .getLabel()); 46 String str2 = DialogUtil.removeAccel(((IViewDescriptor) e2) 47 .getLabel()); 48 return collator.compare(str1, str2); 49 } else if (e1 instanceof IViewCategory) { 50 IViewCategory generalCategory = viewReg.findCategory(ViewRegistryReader.GENERAL_VIEW_ID); 51 if (generalCategory != null){ 52 if (((IViewCategory)e1).getId().equals(generalCategory.getId())) { 53 return -1; 54 } 55 if (((IViewCategory)e2).getId().equals(generalCategory.getId())) { 56 return 1; 57 } 58 } 59 Category miscCategory = viewReg.getMiscCategory(); 60 if(miscCategory != null){ 61 if (((IViewCategory)e1).getId().equals(miscCategory.getId())) { 62 return 1; 63 } 64 if (((IViewCategory)e2).getId().equals(miscCategory.getId())) { 65 return -1; 66 } 67 } 68 String str1 = DialogUtil.removeAccel(((IViewCategory) e1).getLabel()); 69 String str2 = DialogUtil.removeAccel(((IViewCategory) e2).getLabel()); 70 return collator.compare(str1, str2); 71 } 72 return 0; 73 } 74 } 75 | Popular Tags |