我找遍了网,但无法找到工作解决方案如何在Eclipse工具栏以编程方式来创建一个菜单项下拉菜单项。使用plugin.xml
创建它们很流畅,但是有什么方法可以通过代码实现?为什么要这样做?创建工具栏项下拉菜单条目编程
我想创建一个小插件,它为用户提供了创建这应该是通与主工具栏下拉菜单中的单个菜单项(按钮)访问条目的随机数的可能性。
我是很新的Eclipse插件开发。正如我已经说过plugin.xml中这样做是没有问题的:
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar id="pulldown.items.toolbars.sampleToolbar">
<command
commandId="pulldown.items.commands.sampleCommand"
icon="icons/sample.gif"
tooltip="Say hello world"
id="pulldown.items.toolbars.sampleCommand"
style="pulldown">
</command>
</toolbar>
</menuContribution>
<menuContribution locationURI="menu:pulldown.items.toolbars.sampleCommand">
<command
commandId="pulldown.items.commands.sampleCommand"
label="Message 1" style="push">
<parameter name="pulldown.items.msg" value="Some message"/>
</command>
<separator name="nothing" visible="false"/>
<command
commandId="pulldown.items.commands.sampleCommand"
label="Message 2" style="push">
<parameter name="pulldown.items.msg" value="Some other message"/>
</command>
</menuContribution>
</extension>
我试图找到有关这个中的下列对象命令,但找不到任何。不要打扰我使用getWorkbenchWindows()[0]
此代码在插件启动时执行,并且没有可用的活动窗口。
Activator act = Activator.getDefault();
IWorkbench workbench = act.getWorkbench();
WorkbenchWindow window = (WorkbenchWindow)workbench.getWorkbenchWindows()[0];
CoolBarManager cbm = window.getCoolBarManager();
ToolBarContributionItem item =
(ToolBarContributionItem)cbm.find("pulldown.items.toolbars.SampleToolbar");
IToolBarManager tbm = item.getToolBarManager();
CommandContributionItem citem =
(CommandContributionItem)tbm.find("pulldown.items.toolbars.sampleCommand");
ParameterizedCommand cmd = citem.getCommand();
所有对象都有效,但它们都不包含上述定义的参数化命令之一。我能找到的命令中的所有参数都只包含定义,但没有指定值。
对不起,weired代码,这只是调试和浏览通过这个所有对象,以查找上述我。 – jdc 2012-02-04 01:25:46