2011-12-21 8 views
1

私はEclipse用のカスタムエディタを持っています。特別な理由から、このエディタは、エディタ用のeclipseによって提供される標準のアクションバーに基づいていない2つのツールバー領域を提供します。この2つの場所は他のプラグインが貢献するために用意されています。私の意図は、カスタムのmenuContribution/locationURIを持つ "org.eclipse.ui.menus"拡張ポイントを利用して、他のプラグインがこの拡張子を使って貢献でき、toolbar:my.editor.toolbar1toolbar:my.editor.toolbar2locationURIとして関連付けます。既存のorg.eclipse.ui.menus拡張機能を活用したツールバーの作成

私の問題は、ツールバーを特定の場所に「接続」する方法です。私はアプローチに従いましたが、結果は良くありません。私はカスタムToolbarContributionRootイベントを作成してください。CustomContributionFactoryを作成してExtensionContributionFactoryを作成してください。それはかなりうまくいくが、問題は、サブメニューが正しく解決されていないプルダウンコマンドである。 「ユーザー」の

toolbarManager = new ToolBarManager(SWT.FLAT);               
ToolbarContributionRoot toolbarRoot = new ToolbarContributionRoot(toolbarManager);      

IServiceLocator workbench = PlatformUI.getWorkbench();             

IConfigurationElement[] allMenuElements                
     = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.menus");   
for (IConfigurationElement menuContribution : allMenuElements) {          
    String locationURI = menuContribution.getAttribute("locationURI");         

    if ("toolbar:my.editor.toolbar1".equals(locationURI)) {              
     try {                       
      ExtensionContributionFactory factory = CustomContributionFactory.create(menuContribution); 
      factory.createContributionItems(workbench, toolbarRoot);         
     } catch (CoreException e) {                 
      e.printStackTrace();                  
     }                        
    }                         
}                          


toolbar = toolbarManager.createControl(root);               
GridData gridData = new GridData(GridData.FILL, GridData.FILL, false, false, 1, 1);     
toolbar.setLayoutData(gridData);                  
toolbar.pack();                      

のplugin.xmlは、次のようになります。

<extension point="org.eclipse.ui.menus" id="my.helper.id"> 
    <menuContribution locationURI="toolbar:my.editor.toolbar1"> 
     <command commandId="my.editor.special.command1" />... 

あなたが一緒に私のカスタムツールバーと"org.eclipse.ui.menus"拡張子をブレンドする方法任意の提案を持っていますか?

答えて

4

それがどのように行うための正しい方法:

toolbarManager = new ToolBarManager(SWT.FLAT);     
IServiceLocator workbench = PlatformUI.getWorkbench(); 
IMenuService menuService = (IMenuService) workbench.getService(IMenuService.class); 
menuService.populateContributionManager(toolbarManager, TOOLBAR_LOCATION); 

toolbar = toolbarManager.createControl(root); 
+0

私はこのコードを使用しようとしている、そしてそれは、コールworkbench.getService(IMenuServiceから返されるWorkbenchMenuServiceのバージョンので動作しません。 .class)に欠陥があります。欠点は、メソッドpopulateContributionManager(toolbarManager、TOOLBAR_​​LOCATION)が実装されておらず、その中に// TODOメッセージがあることです。この実装されていないメソッドは、org.eclipse.ui.workbench_3.104.0.v20130204_164612.jarから来ています。どのようにコードを動作させましたか? – twindham

+0

このコードは、EclipseのIndigoリリースを使用して完全に動作します。しかし、これまでのところJunoではうまくいきません。 –

関連する問題