Eclipse Papercut #7 – Adding the PDE Plugin creation wizard to the Eclipse toolbar

Its been a while since I wrote my last Eclipse papercut blog entry.

Today I demonstrate how to add the PDE wizard for creating new plugins to the Eclipse toolbar. I personally create plugin projects on a regular basis therefore it is annoying to select the wizard via File-> New -> blablabla.

I know that I can use Ctrl+3 to select the wizard but I want to be able to select this wizard from the main toolbar.

This is really easily. First find the related Wizard via the Plugin Spy. We see that the wizard is called NewPluginProjectWizard.

Then create a command with the following default handler.


package de.vogella.plugin.pdewizard.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.pde.internal.ui.wizards.plugin.NewPluginProjectWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveShell(event);
		WizardDialog wizard = new WizardDialog(shell,
				new NewPluginProjectWizard());
		wizard.open();
		return null;
	}
}

Via the plugin menu spy you also find quickly a nice place to put your new toolitem to the main toobar

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.commands">
      <command
            defaultHandler="de.vogella.plugin.pdewizard.handlers.NewPluginWizardHandler"
            id="de.vogella.plugin.pdewizard.commands.pluginwizard"
            name="New Plugin Wizard">
      </command>
   </extension>
   <extension
         id="toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown"
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.workbench.file">
            <command
                  commandId="de.vogella.plugin.pdewizard.commands.pluginwizard"
                  icon="icons/sample.gif"
                  tooltip="Create new plugin">
            </command>
      </menuContribution>
   </extension>

</plugin>

If you also add the dependencies to org.eclipse.ui, org.eclipse.pde.ui, org.eclipse.pde.ui.templates and org.eclipse.core.runtime then you should be able to create a new plugin project via your new button in the main toolbar.

I hope this help. You can follow me on Twitter.

EDIT: A simpler solution was proposed by Remy Suen: Since the new/import/export wizards are parameterized commands, the same effect can actually be achieved with pure XML.

<extension
id="toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown"
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.workbench.file">
<command
commandId="org.eclipse.ui.newWizard">
<parameter
name="newWizardId"
value="org.eclipse.pde.ui.NewProjectWizard">
</parameter>
</command>
</menuContribution>
</extension>

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse, Papercut and tagged , , , . Bookmark the permalink.

2 Responses to Eclipse Papercut #7 – Adding the PDE Plugin creation wizard to the Eclipse toolbar

  1. Dennis Doubleday says:

    Lars,

    I knew about the Plugin Spy, but not the Plugin Menu Spy. I always learn something new when I read your site. Thanks!

Comments are closed.