Create (pulldown) Menu in Toolbar
Step 1. Create Toolbar with PullDown
Step 2. Create MenuContribution
Step 3. Add items to MenuContribution
Step 4. Run the application
Step 1. Create Toolbar with PullDown
Create your Eclipse RCP application ( with mail template).
Suppose open command id is "HarikrushnaVToolbar.open" then create a toolbar with command in it,
as shown below:
now, convert the style to "pulldown".
Now, if you run the application, you will see a pulldown button next to toolbar icon as follow :
Step 2: Create MenuContribution
Now, create a MenuContribution, which will define the items for pulldown menu.
Define, locationURI to the same name as the menu:commandId , here we provide the LocationURI as "menu:HarikrushnaVToolbar.open"
Also Define Class name as "AllMenuItems".
Step 3. Add items to MenuContribution
Click on "class", you will see the dialogbox as shown below :
Click on Finish.
Now, go to MANIFEST.MF and add "org.eclipse.core.expressions" to "Required Plug-ins".
Enter code as follow in the AllMenuItems.java file
Code :
===========
public void createContributionItems(IServiceLocator serviceLocator,IContributionRoot additions) {
CommandContributionItemParameter commandContributionItemParameter = new CommandContributionItemParameter(
serviceLocator, "",
"org.eclipse.ui.file.exit",
SWT.PUSH);
commandContributionItemParameter.label = "Exit the application";
commandContributionItemParameter.icon = Activator.getImageDescriptor("icons/alt_window_16.gif");
CommandContributionItem commandContributionItem = new CommandContributionItem(commandContributionItemParameter);
commandContributionItem.setVisible(true);
additions.addContributionItem(commandContributionItem, null);
}
============
Comments
Post a Comment