Eclipse插件 - 动态地向工具栏添加菜单贡献

时间:2016-06-27 19:06:00

标签: eclipse eclipse-plugin eclipse-rcp

是否可以动态地将menucontribution(基本上是新按钮)添加到toolbar:org.eclipse.ui.main.toolbar

我尝试使用AbstractContributionFactory但似乎有问题,因为createContributionItems is never called

我的代码到目前为止尝试在按下另一个按钮后向Eclipse工具栏添加一个新按钮。问题是createContributionItems永远不会被称为"创建东西"永远不会出现:

//If a certain button is pressed run will be executed
public void run(IAction action) {

        MessageDialog.openInformation(
            window.getShell(),
            "Runtimecommands",
            "Hello, Eclipse world");



          IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);

          AbstractContributionFactory factory = new AbstractContributionFactory("toolbar:org.eclipse.ui.main.toolbar", null) 

            @Override
            public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {

            System.out.println("Creating Stuff");


          };    
          menuService.addContributionFactory(factory); 

}

我当前的plu​​gin.xml

<plugin>

   <extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            label="Sample Action Set"
            visible="true"
            id="com.dynamo.actionSet">
         <menu
               label="Sample &amp;Menu"
               id="sampleMenu">
            <separator
                  name="sampleGroup">
            </separator>
         </menu>
         <action
               label="&amp;Sample Action"
               icon="icons/sample.gif"
               class="com.dynamo.actions.SampleAction"
               tooltip="Hello, Eclipse world"
               menubarPath="sampleMenu/sampleGroup"
               toolbarPath="sampleGroup"
               id="com.dynamo.actions.SampleAction">
         </action>
      </actionSet>
   </extension>

</plugin>

请你注意。

0 个答案:

没有答案