我找遍了網,但無法找到工作解決方案如何在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