I am working with an RCP application menu. As seen in the image below I am trying to move my newly added Help menu at the end of the freebies menus that come with my RCP application. Currently the code just adds it to the menubar by using a class that was created derived from ActionBarAdvisor .
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
Looking at the other methods available I see an appendToGroup method that might be interesting to use. Only thing is that it requires a groupName and I don't have one. The menu ids I have been using don't seem to suffice as a groupName.
Here is my code
#Override protected void fillMenuBar(IMenuManager menuBar)
{
MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
//menuBar.appendToGroup(menuBar.getId(), helpMenu);
menuBar.add(helpMenu);
helpMenu.add(aboutAction);
}
Fixed it
If you are adding to an RCP which uses the normal Eclipse ActionBarAdvisor (WindowActionBuilder) then there is a group marker with id IWorkbenchActionConstants.MB_ADDITIONS positioned before the existing Window and Help menus.
There is an existing Help menu which has id IWorkbenchActionConstants.M_HELP so you can find this menu using:
IMenuManager helpMenu = menuBar.findMenuUsingPath(IWorkbenchActionConstants.M_HELP);
If you are writing your own action bar builder based on ActionBarBuilder then there are no groups defined in the menu manager and you can't use appendToGroup. You just call add in the order you want the menus to appear.
Creating a custom menu programmatically is not the best way to go about this. Use the plugin.xml extensions tab to create menus then you can easily use the up and down buttons at the right of the text field with All Extensions to rearrange where you want each menu to be. So in this case, it's much easier to use the built-in Help menu of Eclipse. This whole action is resumed by adding the help menu right after the other menus in the plugin.xml file
``` <extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
label="File">
<command
commandId="org.eclipse.ui.file.exit"
label="Exit">
</command>
<command
commandId="org.eclipse.ui.file.save"
label="Save"
style="push">
</command>
</menu>
<menu
label="Help">
<command
commandId="org.eclipse.ui.help.aboutAction"
label="About">
</command>
<command
commandId="org.eclipse.ui.help.helpSearch"
label="Search">
</command>
</menu>
</menuContribution>```
Final Result picture in question area :) I can't load it here
Related
I have created a tool bar with few Tool bar items in my Application.
Menu:
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:main">
<command
commandId="com.test.myapp.ui.commands.TestCommand"
style="push"
tooltip="My Tool Items 1">
</command>
Command configuration:
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="com.test.myapp.ui.commands.TestCommand"
helpContextId="test"
id="com.test.myapp.ui.commands.TestCommand"
name="Open Test View">
</command>
Below is my TestCommand class.
public class TestCommand extends AbstractHandler{
//Overridden the execute method here....
}
So now if I click on my Tool bar this will execute my Command class. I would like to know how can I add mouse listener to this Tool bar item so that we can do some stuff when mouse over on the tool bar item (Ex:Mouse over to tool bar item, it generally shows tool tip, So now if I press some key it should open some other page for this. So to do that if I can get the control of this event I can add some stuff to it)
Is it possible to have nested context menus? I am working on an app which needs to provide the users with various functionality, and after much thought I came to the conclusion that using a context menu would be quite advantageous (would allow me to clean up my screen by getting rid of a few spinners etc)
However I was wondering if its even possible to have a context menu pop up, and then on the item select present the user with even more choices.
Something along these lines:
Context Menu 1
-> Change Font Color (on select generate context menu 2)
->Red
->Green
-> Change Background Color (on select generate context menu 3)
->Red
->Green
Would something like this be possible?
What IDE are you using? Do you what to do this in xml or Java? If you are using eclipse you could just create a menu in your "menu" folder which contains an xml file and then use their "manager" to create a sub menu.
Here's an example menu named game_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/ic_new_game"
android:title="#string/new_game"
android:showAsAction="ifRoom"/>
<item android:id="#+id/help"
android:icon="#drawable/ic_help"
android:title="#string/help" />
</menu>
To create submenu you have to "nest <menu> elements"
http://developer.android.com/guide/topics/ui/menus.html
Go to Defining a Menu in XML
I've added a pulldown command to my toolbar
<command
commandId="my.uri.Options"
label="%Options.label"
icon="icons/properties.png"
style="pulldown">
</command>
that under a pull down menu have some toggle options.
I would like to get to those option by pushing the button as well, and not just the menu triangle. Is that possible? Or my approach is all wrong?
Perhaps you could use the onclick event handler, or the you could explore the addEventListener() to change the action for when the menu is clicked.
I have two views in my application.there are treeviewer in both the views on which i want to add context menus.
I registered the context menues using
getsite().registerCOntextMenu(menu,treeviewer);
in both the views
Now i added the menu contribution in plugin.xml file as
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?before=editions">
<command
commandId="com.eclipse.command1"
label="action"
style="push">
</command>
</menuContribution>
but this menu is shown in only one of the context menu not in both.
so is there any way to add this menu to all the registered context menus or using the id for menu so that they can be identified.
If you are referring to a group in locationURI then this group has to be present in the menu.
In general:
Any pop-up menu which is registered with the workbench should also define a GroupMarker in the registered menu with id IWorkbenchActionConstants.MB_ADDITIONS[="additions"].
In your case, the group should be named "editions".
At the moment I have two menus in my RCP application:
File and Help.
The File menu is created via a command:
<extension point="org.eclipse.ui.menus">
<menuContribution allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="fileMenu"
label="File"
mnemonic="F"
tooltip="Main Menu">
<command
commandId="myPlugin.bundle.menuCommands.Exit"
label="Exit"
mnemonic="E"
style="push"
tooltip="Exits MyPlugin">
</command>
</menu>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command defaultHandler="myPlugin.bundle.commands.exit.ExitHandler"
id="myPlugin.bundle.menuCommands.Exit"
name="Exit">
</command>
</extension>
The Help menu (with only the About menu item) is created via the respective action in ApplicationActionBarAdvisor:
protected void makeActions(IWorkbenchWindow window) {
aboutAction = ActionFactory.ABOUT.create(window);
register(aboutAction);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
helpMenu.add(aboutAction);
menuBar.add(helpMenu);
}
Now, the Help menu comes before the File menu in the menu bar. This is obviously not how it's supposed to be. How can I change the order of the menus?
Many thanks!
Ah, solved this by simply adding a MenuManager in the ApplicationActionBarAdvisor for the File menu:
MenuManager helpMenu = new MenuManager("&Help", "helpMenu");
MenuManager fileMenu = new MenuManager("&File", "fileMenu");
...
menuBar.add(fileMenu);
menuBar.add(helpMenu);
Can I hear you go "d'uh!"? Cos that's what I did ;).
UPDATE:
Is this really how it should be done though? That'd mean that for every new menu I create in the Extension Wizard, I'll have to add a new line to ApplicationActionBarAdvisor...
Perhaps you could share your thoughts on this, or whether it's just an avoidable hack.
Thanks!