Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating toolbar items pulldown menu-entries programmatically
    primarykey
    data
    text
    <p>I searched all over the net but couldn't find a working solution how to create pull-down menu entries for a menu item in a toolbar in Eclipse programmatically. To create them using <code>plugin.xml</code> is smooth, but is there some way to do it from code? Why to do that?</p> <p>I want to create a little plugin which offers the user the possibility to create a random number of entries which should be accessible thru a single menu item (button) with a pull-down menu in the main toolbar. </p> <p>I'm quite new to Eclipse plugin development. As I already said doing in plugin.xml is no problem :</p> <pre class="lang-xml prettyprint-override"><code> &lt;extension point="org.eclipse.ui.menus"&gt; &lt;menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions"&gt; &lt;toolbar id="pulldown.items.toolbars.sampleToolbar"&gt; &lt;command commandId="pulldown.items.commands.sampleCommand" icon="icons/sample.gif" tooltip="Say hello world" id="pulldown.items.toolbars.sampleCommand" style="pulldown"&gt; &lt;/command&gt; &lt;/toolbar&gt; &lt;/menuContribution&gt; &lt;menuContribution locationURI="menu:pulldown.items.toolbars.sampleCommand"&gt; &lt;command commandId="pulldown.items.commands.sampleCommand" label="Message 1" style="push"&gt; &lt;parameter name="pulldown.items.msg" value="Some message"/&gt; &lt;/command&gt; &lt;separator name="nothing" visible="false"/&gt; &lt;command commandId="pulldown.items.commands.sampleCommand" label="Message 2" style="push"&gt; &lt;parameter name="pulldown.items.msg" value="Some other message"/&gt; &lt;/command&gt; &lt;/menuContribution&gt; &lt;/extension&gt; </code></pre> <p>I tried to find the information about this commands in the following objects but couldn't find any. Don't bother me using <code>getWorkbenchWindows()[0]</code> this code is executed on plugin startup and there is no active window available.</p> <pre class="lang-java prettyprint-override"><code>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(); </code></pre> <p>All objects are valid but they contain neither one of the above defined parameterized commands. All parameters in the commands I could find are only containing the definition but no value is specified.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload