Using the Plug-in Development Environment

The Eclipse platform is already a conglomeration of over a hundred plug-ins, and they build on each other using extension points. An extension point lets one plug-in build on what another plug-in exports. In this chapter, we're going to use extension points to add new menus, buttons, and so on to Eclipse in a plug-in.

Screenshot

Plug-ins can only make use of classes exported by other plug-ins, which makes extension points especially important. For example, to let a plug-in make use of prebuilt Java code, you can wrap JAR files inside plug-ins and let other plug-ins depend on it. Much support for custom plug-ins is already built into several standard plug-ins that come with Eclipse.


Using the Eclipse Plug-in Development Environment (PDE), you can build plug-ins that will build on the standard extension points available. Here are the types of plug-in projects that the PDE will create for you:


Plug-in projects

A standard plug-in


Fragment projects

An add-on or addition to a plug-in (sometimes used for internationalization)


Feature projects

Projects that contain one or more plug-ins


Update site projects

Web site that can automatically install features

The PDE has a number of built-in Wizards, and we're going to make use of that support in our next example. This example will create a simple plug-in that supports both a menu item and a button in the toolbar. To create the plug-in project, select FileScreenshot NewScreenshot Project. Select Plug-in Development in the left box of the New Project dialog and Plug-in Project in the right box, as shown in Screenshot-2. Then click Next.

Screenshot-2. Creating a plug-in project
Java figs/ecps_1102.gif

In the next pane, name the project org.eclipsebook.ch11.Ch11_01, as you see in Screenshot-3, and click Next. This project name will also be the ID of the plug-in when it comes time to use it in Eclipse.

Screenshot-3. Naming the project
Java figs/ecps_1103.gif

In the next pane, make sure the "Create a Java project" radio button is selected, as you see in Screenshot-4, and click Next.

Screenshot-4. Setting the project type
Java figs/ecps_1104.gif

The next pane is the Plug-in Code Generators pane, shown in Screenshot-5. We're going to select the built-in "Hello, World" example here, so select the "Hello, World" item in the left box and click Next. (This pane also allows you to create other types of plug-in projects, such as plug-ins with editors, views, and so on.)

Screenshot-5. Creating a Hello, World example
Java figs/ecps_1105.gif

In the following pane you can configure the plug-in. Enter a provider name—we'll use Eclipse Book—and accept the other defaults, which appear in Screenshot-6. Click Finish to create the code for this plug-in (clicking Next here would let you set the text the plug-in displays in its message box, but the default text is fine).

Screenshot-6. Configuring the plug-in
Java figs/ecps_1106.gif

Clicking Finish opens the plug-in manifest editor, as you see in Screenshot-7, where it's displaying a Welcome page. You can open the editor later yourself by double-clicking plugin.xml in the Package Explorer.

Screenshot-7. The plug-in manifest editor
Java figs/ecps_1107.gif

The plug-in manifest editor looks simple, but there's a lot going on here. Note, in particular, the tabs at the bottom of the editor:


Welcome

The Welcome page you see in Screenshot-7, describing the plug-in


Overview

Holds summary information for the plug-in, such as name, version, provider name, and so on


Dependencies

Indicates the plug-ins required for this plug-in


Runtime

Indicates the libraries needed to run this plug-in


Extensions

Indicates the extensions points used by the plug-in


Extension Points

Indicates the extension points defined by the plug-in


Source

An XML editor that lets you edit the source code for plugin.xml

The manifest editor lets you edit plugin.xml, either directly by clicking the Source button, or by using the various tabs in the editor. For example, to build on the standard extension points, you can click the Extensions tab and use the Add button to add functionality to your plug-in, as we'll do later in this chapter. When you make changes this way, the PDE edits plugin.xml for you automatically, saving you the trouble of editing raw XML.

      
Comments