This is a general question but my current problem revolves around menu handling.
In a normal plugin with contributes menu actions you would configure ActionSets etc in the plugin.xml configuration. This is obviously sensible.
I am working on a RCP application (actually RAP) and I'm wondering if it's worth the effort to configure everything via plugin.xml. My plugin does not have to interact with an other unknown plugins so, theoretically, I have control. I can add menus and actions programmatically.
I have been trying to configure a menu which contains a submenu. I have tried defining ActionSets and linking one inside the other but without success. Some items need to be disabled depending on the user role.
I figure I could have coded the whole lot in a few minutes but I'm not sure if that fits with the eclipse 'ethos'.
What opinions are out there? The application will get fairly big so I'd like to get the approach right from the start. Perhaps someone can point me at an example for configuring a nested menu :-)
For Eclipse there are two different ways to contributing to the Workbench: Actions and Commands.
I definitely recommend the Commands as the newer and more advanced than Actions. The drawbacks of Actions as specified here (1):
Another issue with duplicating Actions in plugin.xml is that multiple instance of the same Actions will be created in the memory
(1) Actions vs Commands
If you are writing the RCP application, the good practice is to create the place holders in your ActionBarAdvisor. While that would define the basic structure of your menus and toolbars, you can extend menuContributions and using commands to contribute the actual menu/tool items.
For adding actions in RCP you can also use ApplicationActinBarAcvisor.It is more easy than the above mentioned solution In this u just have to first declare the action as an object of IWorkbenchAction, then in method "protected void makeActions(IWorkbenchWindow window)" u can register it. And the last step is to add it into menu. Following code will help u out.
1.First declare the action :-
2.Registering action :-
3.Last step is to add the action in menu:-
You can also add the action in toolbar as follows:-
My opinion is that the plugin.xml implementation is the way to go.
My main two reasons for using this method:
Here is a code snippet that implements menus and submenus. In this example, they are added to the main menu.
You can paste this into your plugin.xml:
For activating/deactivating a menu, you have to use Core Expressions to enable/disable command handlers. If a command doesn't have any active handlers attached, it will be disabled. So, the menu item that calls that command will also be disabled.
The following code snippets show how to create a button on the toolbar of a view and have it be enabled/disabled depending of a variable's value. Bare in mind that you will have to change some things in this code to make it work. Most of the changes are for reference names and class implementation.
Create the button in the toolbar (plugin.xml):
Create the command (plugin.xml):
Create the command handler (plugin.xml):
Create the state variable for the command (plugin.xml):
Implement the class that changes the variable's state:
More details on how to implement these features can be found at these locations: