Lubos Eclipse Weblog

Blog about Eclipse and related technology

Eclipse plugin and RCP development notes

This page contains my Eclipse plugin and RCP development notes. I am not developing Eclipse plugin often enough to stay current so this should help me to get re-started with Eclipse plugin development.

I use Diigo to store my links about Eclipse here.

Eclipse Plugins

For Eclipse plugin development I strongly recommend the book Eclipse Plug-ins (third edition), get the book or at least install the examples and use them for development! You can download/install the examples from the update site and Open the QualityEclipse Book Samples View and load the appropriate chapter project. Additional code examples can be found here.

Learn form mistakes here is Top 10.

Check the official Plugins Development documentation, FAQ and the API Reference. Use Plug-In Spy by selecting en Eclipse window (view, editor,…) ore resource (file, project) and pressing Alt-Shift F1. The popup window will display information about the contributing plug-in and much more; click on the links to learn more! Since Eclipse 3.5 Plug-In Spy can be used to explore menus by pressing Alt-Shift-F2, see second part of this excellent blog.

Check following tutorials:

You will need some Eclipse compliant icons for plugin development, here are some:

To leverage Eclipse SDK and use plugins/tools already available in Eclipse, you need to know extension point, here is the documentation.
To learn how to use JFace Views you can use Eclipse JFace TableViewer – Tutorial . To learn how to use wizards, check Creating JFace Wizards.
To learn how to use Eclipse Preferences and Preference Pages you can use Eclipse Preference.

Good background information on internationalizing plug-ins can be found in the Eclipse Foundation’s articles “How to Internationalize your Eclipse Plug-In“, “How to Test Your Internationalized Eclipse Plug-In” or here.

Pay attention to plugin activation. Eclipse plugins are by default lazily initialized (only when needed), see check “Activate this plugin when one of its classes is loaded” on plugin editor Overview page. You plugin activator, usually subclass of AbstractUIPlugin start() method is only called when the plugin is activated, so if you store static reference to plugin like:

public void start(BundleContext context) throws Exception {
super.start(context);
 plugin = this;
}
public static PluginActivator getDefault() {
 return plugin;
 }

getDefault() method can return null if referenced before the plugin is activated (for example from your perspective that is restored form workspace instead of created from the perspective factory).

Eclipse plugins menus are implemented using Actions (older) or Commands, check following links:

Four good articles by Prakash G.R.:

and the standard set of references:

Credit for links to How to Eclipse Commands blog.

Eclipse Menu Contributions are documented here. If you use Commands you will probably have to use custom property testers to set command visibility visibleWhen and/or handler active state activeWhen and enabled state enabledWhen. To learn more check great screencast from Robert Konigsberg. You will need to declare command handlers, the class org.eclipse.ui.handlers.HandlerUtil provides several convenience methods useful from within the handler execute() method.

Note. Eclipse Search menu (org.eclipse.search.menu) doesn’t support Command contributions, so you cannot use org.eclipse.ui.menus extension point to make Search menu contribution. You have to use action sets and org.eclipse.ui.actionSets extension point and use menubarPath org.eclipse.search.menu/dialogGroup (for example) for your action.

If you wish to contribute to already existing Eclipse menus, you will have to make menu contributions. Check Eclipse Plugins Exposed page 1, page 2.

If you need to take a look at Eclipse source, here is Eclipse CVS Howto. I highly recommend to put the repository :pserver:anonymous@dev.eclipse.org:/cvsroot/eclipse into Eclipse CVS perspective, and use the repository (directly without downloading the source code projects) to explore Eclipse source code.

Extension points and Extensions

Adding an extension point (publish extension) and load (consume) the extensions defined by the extension is a fairly involved and not very well documented procedure.

Old way to load extensions was static and usually happened only while your plugin was being loaded. New approach uses IExtensionChangeHandler to load or remove the extension during the lifetime of your plugin. See the article OSGi, Dynamics and Eclipse « EclipseSource Blog for excellent explanation how to dynamically add/load or remove extensions based on your extension point.

Tips, Tricks and Howto

Following notes contain small code howto snippets useful for Eclipse plugin development :

  • To get all projects in workbench:
IProject[] projects = ResourcePlugin.getWorkspace().getRoot().getProjects();
  • To get Eclipse installation configuration location:
Location loc = Platform.getConfigurationLocation();
public static MessageConsole findConsole(String name) {
 ConsolePlugin plugin = ConsolePlugin.getDefault();
 IConsoleManager conMan = plugin.getConsoleManager();
 IConsole[] existing = conMan.getConsoles();
 for (int i = 0; i < existing.length; i++)
 if (name.equals(existing[i].getName()))
   return (MessageConsole) existing[i];
 //no console found, so create a new one
 MessageConsole myConsole = new MessageConsole(name, null);
 conMan.addConsoles(new IConsole[]{myConsole});
 return myConsole;<br /> }
 public static void writeToConsole(String message) {
 MessageConsole myConsole = findConsole(CONSOLE_NAME);
 MessageConsoleStream out = myConsole.newMessageStream();
 out.println(message);
 // Make console visible
 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
 try {
   IConsoleView view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
   view.display(myConsole);
 } catch (Exception e) {
   Log.logError("Unable to display Console View", e);
 }
 }

Eclipse RCP

To get started with Eclipse RCP development you should install Eclipse RCP delta pack to support multiple platforms, here are some useful links:

Note, do not unzip deltapack directly into Eclipse install, use Eclipse/Preferences/PDE Development as described in Using deltapack in Eclipse 3.5.

Review the older but still very useful Eclipse RCP tutorial from Ed Brunette:

Another useful RCP tutorials:

And check the official Eclipse RCP web site RCP FAQ.

If you need to create a welcome page for your RCP application read “Get to know Eclipse User Assistance.”

Debugging and testing Plugin or RCP

You can run or debug the plugin or RCP application from the Overview tab of the plugin or RCP.  It will create a launch configuration if it doesn’t exist. If you need to start from scratch, you can reset the workspace before the launch. To do that, check Clear workspace (on Main tab). Optionally, you can check “Clear the configuration area before launching” in Configuration tab.

Make sure you have -consoleLog as a Program Argument in your launch configuration. You may also want to take a look at these runtime tools.

Building plugins, features

Automated build of plugins and features without Eclipse IDE is challenge task. Check bottom of this blog and P2 Publisher (new in Eclipse 3.5).

Adding Update Support

There is a great tutorial Adding Self-Update to an RCP Application at Eclipse Wiki. You can also check EclipseSource Equinox p2 website and Eclipse p2 website.

4 Comments »

  1. [...] the delta pack is slightly different, and is described by Andrew Niefer (via Lubos’s excellent list of Eclipse plugin and RCP development [...]

    Pingback by Installing the RCP Delta Pack for Eclipse « Eclipse, Java and more | July 9, 2009 | Reply

  2. Thanks for the link to my delta pack post, which I’ve updated to link to Andrew Niefer’s “Using deltapack in Eclipse 3.5″ post.

    This is a great list of resources; thanks very much!

    Comment by Louis Rose | July 9, 2009 | Reply

  3. Thanks. Nice collection of articles.

    Comment by Lars Vogel | July 18, 2009 | Reply

    • Thanks, Lars,

      you deserve credit for quite a few of them, you have created quite a few very useful tutorials! I use them a lot to refresh my knowledge of Eclipse plugin/RCP development! Great job!

      Comment by lubosp | July 18, 2009 | Reply


Leave a comment