Tech-Today
Add eclipse-rcp's views short list, perspective short list in the org.eclipse.ui.menus plugin via dynamic CompoundContributionItem class
Recently, I've encountered a problem wherein I wanted to display the eclipse-rcp's list of view, perspective etc using the extension org.eclipse.ui.menus. The problem can easily solved by the ApplicationActionBarAdvisor, see the code below:
private IContributionItem showViewItem;
protected void makeActions(final IWorkbenchWindow window) {
listView = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
}
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager windowMenu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);
MenuManager viewManager = new MenuManager("Show View", "showView");
viewManager.add(listView);
windowMenu.add(viewManager);
menuBar.add(windowMenu); //adds the Window menu to the horizontal toolbar
}
Unfortunately, this is not what I want and I want to take advantage of the eclipse-rcp's plugin system. So I ended up peeking into the rcp's core classes and found out a solution:
What to do:
1.) Create a new plugin project, Hello World will do.
2.) Open plugin.xml and in the Extensions tab add org.eclipse.ui.menus
a.) add menuContribution and sets its locationURI=menu:org.eclipse.ui.main.menu
b.) right click contribution and select New->menu, change the label=File
c.) right click File menu and select New->menu, change the label=Show View
d.) right click Show View menu and select New->dynamic
d.i) select dynamic and right click class*, name the class and select CompoundContributionItem as its super class
d.ii) example: public class ListView extends CompoundContributionItem { }
3.) Now all we have to do is override the CompoundContributionItem's getContributionItems method, like this:
@SuppressWarnings("unchecked")
@Override
protected IContributionItem[] getContributionItems() {
List menuContributionList = new ArrayList();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IContributionItem item = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
menuContributionList.add(item); //add the list of views in the menu
return menuContributionList.toArray(new IContributionItem[menuContributionList.size()]);
}
-
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...
-
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...
-
Execute An Eclipse-rcp Command And Open An Eclipse-rcp View In Code
Objective: 1.) To execute an eclipse rcp command in code 2.) To open an eclipse rcp view in command Most of the time you will just use the extension tab in the plugin.xml but for those who chose to implement in code here's how they're done: Solution:...
-
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,...
Tech-Today