/** * 对首选项菜单排序时,需要覆盖该方法 */ public ContributionComparator getComparatorFor(String contributionType) { if (contributionType.equals(IContributionService.TYPE_PREFERENCE)) { return new PreferencesComparator(); } else { return super.getComparatorFor(contributionType); } }
@Override protected Control createTreeAreaContents(Composite parent) { // 创建左侧树 Control result = super.createTreeAreaContents(parent); TreeViewer treeViewer = getTreeViewer(); // 设置排序器 IContributionService cs = (IContributionService) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getService(IContributionService.class); treeViewer.setComparator(cs.getComparatorFor(IContributionService.TYPE_PREFERENCE)); treeViewer.expandAll(); // 展开所有 return result; }
@Override public ContributionComparator getComparatorFor(String contributionType) { if (contributionType.equals(IContributionService.TYPE_PROPERTY)) { return new MaruPropertyPageComparator(); } else { return super.getComparatorFor(contributionType); } }