在Eclipse中以编程方式向下拉按钮添加选项 [英] Programmatically add options to pulldown button in eclipse

查看:828
本文介绍了在Eclipse中以编程方式向下拉按钮添加选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中,我有一个命令定义为他们拥有的主按钮工具栏中的按钮。我有一个命令/按钮设置为下拉按钮,我想以编程方式添加选项。 Kinda喜欢如何在eclipse中的播放按钮上点击下拉按钮,看到不同的运行场景。我想要将这样的选项添加到我的下拉菜单中。我不能通过插件编辑器来做,因为我需要动态生成菜单选项。

In eclipse I have commands defined for buttons in the main button toolbar they have. I have one command/button in there that's set as a pulldown button and I'd like to programmatically add options to it. Kinda like how you can hit the little drop down button on the play button in eclipse and see different run scenarios. I want to be able to add options like that to my pulldown menu. I can't do it through the plugin editor because I need to generate the menu options dynamically.

所以说我在我的plugin.xml文件中定义了下面的下拉按钮。如何以编程方式向下拉添加选项?

So say I have the following pulldown button defined in my plugin.xml file. How do I add options to the pull down programmatically?

 <menuContribution
        allPopups="false"
        locationURI="toolbar:org.eclipse.ui.main.toolbar">
     <toolbar
           id="com.company.gui.base.toolBarMain">
        <command
              commandId="com.company.gui.base.command1"
              icon="icons/magnifier.png"
              id="com.company.gui.base.toolBarMain.monitor"
              label="Im a pulldown menu"
              style="pulldown">
        </command>
     </toolbar>
  </menuContribution>


推荐答案

请查找以下代码。

private void addContextMenu(SampleContributionFactory fac) {
     final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService (IMenuService.class);
     menuService.addContributionFactory(fac);
}

class SampleContributionFactory extends AbstractContributionFactory{

    SampleContributionFactory(final String menuID) {
        super("menu:" + menuID, null);
    }

    @Override
    public void createContributionItems(IServiceLocator serviceLocator,
            IContributionRoot additions) {      
        // add Command Contribution item
        additions.addContributionItem(<YOUR CONTRIBUTION ITEM>, null);
    // add one more Command Contribution item
    ....
    } 
}

现在创建一个SampleContributionFactory的对象如下。

Now create an object of SampleContributionFactory as below.

  SampleContributionFactory fac = new SampleContributionFactory ("com.company.gui.base.toolBarMain.monitor");

并调用方法

addContextMenu(fac);

TODO:根据您的要求在SampleContributionFactory中添加命令贡献项。

TODO : add command contribution items in the SampleContributionFactory as required by you.

这篇关于在Eclipse中以编程方式向下拉按钮添加选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆