Wednesday, 30 December 2015

Create (pulldown) Menu in Toolbar in Eclipse RCP

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 "" 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 ""
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 file

Code :
public void createContributionItems(IServiceLocator serviceLocator,IContributionRoot additions) {

CommandContributionItemParameter commandContributionItemParameter = new CommandContributionItemParameter(
                serviceLocator, "",
commandContributionItemParameter.label = "Exit the application";
commandContributionItemParameter.icon = Activator.getImageDescriptor("icons/alt_window_16.gif");

        CommandContributionItem commandContributionItem = new CommandContributionItem(commandContributionItemParameter);
        additions.addContributionItem(commandContributionItem, null);


Step 4. Run the application

Run your application and your toolbar with Menu is ready.