How to add and enable a menu button using the eclipse rcp extension (by code and using the plugin UI Interface)
Tech-Today

How to add and enable a menu button using the eclipse rcp extension (by code and using the plugin UI Interface)


How to add and enable a menu button using the eclipse rcp extension (by code and using the plugin UI Interface)

To learn eclipse-rcp, I keep on reading, try some tutorials available on the net. My favorite is this one: http://www.vogella.de/articles/RichClientPlatform/article.html, it's very informative and covers a lot of topic.

Since eclipse is constantly updating, I found some features that are already updated in eclipse. For example the Command-Menu mapping.

Consider the default Hello RCP Example which has the default classes: ApplicationActionBarAdvisor, etc. To add a main menu, which has an Exit Button, we simply edit this class like this:
package de.vogella.rcp.intro.dialogs.standard;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
private IAction exitAction;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}

protected void makeActions(IWorkbenchWindow window) {
exitAction = ActionFactory.QUIT.create(window);
register(exitAction); //this line enables the menu
}

protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File");
fileMenu.add(exitAction);
menuBar.add(fileMenu); //add the File Menu group to the main horizontal menu
}
}
This set of action can easily be done using the plugin interface already available in eclipse with plugin development tools. Following the tutorial on de.vogella we should arrive at the screen similar to the image attached.


The menu should look like this:
+Horizontal Menu
+File
+Exit //if you will notice this menu is disable by default

To enable the menu we have to look at the defaulthandler class associated with the Exit Menu, as of eclipse-rcp 3.5 there are 2 methods that we should be concerned with isEnabled and isHandled:

+isEnabled - makes the menu enabled
+isHandled - triggers the event in the execute method

These 2 methods must be enabled to complete add and execute a command in the main menu.

Also take note, that the action now implements the interface IHandler and not extend the AbstractHandler class.




- How To Open A View Using The Eclipse-rcp's Plugin.xml's Extension Tab. Passing The View Id As A Command Parameter.
1.) Create a new HelloWorld RCP project 2.) Open the plugin.xml file and click the Extension tab 3.) Add the extension org.eclipse.ui.commands a.) right click and select New->command b.) set the command's id to command.showView c.) set the defaultHandler...

- How To Show Dynamic Command Based On Perspective In Eclipse-rcp, Does Not Work On Toolbar And Main Menu
1.) Using the HelloWorld project template, add org.eclipse.core.expressions in your application's plugin.xml's Dependencies tab. 2.) In the extension tab do the following: a.) add org.eclipse.core.expressions.definition, set its id to onValidationPerspective...

- Open A View In The Eclipse-rcp's Extension Tab Using The Showviewhandler Class
Let's do this quick. 1.) Create a new HelloWorld Plug-in Project and name it CommandParameter. 2.) Open the plugin.xml and click the Extensions tab. 3.) In the All Extensions tab click the Add button and under the Extension Point Filter: search "view"....

- Menu Contribution Location In Eclipse-rcp
There are 3 main location where a menu can be added (Menu Codes): 1.) menu - menu:org.eclipse.ui.main.menu 2.) toolbar - toolbar:org.eclipse.ui.main.toolbar 3.) popup - popup:org.eclipse.ui.popup.any To add a menu: 1.) open plugin.xml 2.) go to extension...

- Create A New Eclipse-rcp Preference Page By Code When A Listener Is Invoked
Objective: -To create an eclipse-rcp preference page without using the preference extension, all is done in code. This is done by creating a customized button with a SelectionListener, and eventually that action will call a customized preference page....



Tech-Today








.