Recipe 12.3 Creating a Menu-Based Plug-in Using Wizards


12.3.1 Problem

You want to create a plug-in that can add menus and menu items to the Eclipse IDE.

12.3.2 Solution

Use one of the plug-in templates available in the PDE to create a menu-supporting plug-in.

12.3.3 Discussion

With the Eclipse PDE, it's easy to build and modify your own plug-ins. Here are the types of projects the PDE can create for you:

Plug-in projects

A standard plug-in project

Fragment projects

A project that acts as an add-on or addition to a plug-in

Feature projects

Projects that contain one or more plug-ins

Update Site projects

Web projects that can update features automatically

As an example, we're going to create a new plug-in in a project named MenuPlugIn that adds both a menu and a toolbar button to the Eclipse IDE. To create the plug-in project, select File New 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 Figure 12-2. Then click Next .

Figure 12-2. Creating a new plug-in project

The following pane of the dialog asks for the plug-in's project name . Call it org.cookbook.ch12.MenuPlugIn (this also will be the ID of the plug-in when it comes time to use it in Eclipse), as shown in Figure 12-3. Click Next.

Figure 12-3. Creating a name for the plug-in

In the following pane, accept the defaults shown in Figure 12-4, and click Next, making this a Java-based project.

Figure 12-4. Making the project Java-based

In the next pane, you select the wizard to use to create the project. In this case, click Hello, World in the left box, as shown in Figure 12-5, and click Next.

Figure 12-5. Selecting a wizard

The next pane configures the plug-in. For the provider name we'll enter Eclipse Cookbook ; accept the other defaults, as shown in Figure 12-6.

Figure 12-6. Configuring a plug-in

Click Next, and enter the text the plug-in displays when its menu item or toolbar button is selected: This plug-in is functional. , as shown in Figure 12-7. Click Finish to generate the code for the plug-in project.

Figure 12-7. Setting the plug-in's display text

Finally, click Finish to open the PDE, which displays a Welcome page, as shown in Figure 12-8.

Figure 12-8. The PDE

Opening a plug-in's manifest in an editor such as this looks fairly simple, but a lot is going on here. This editor is designed to make it easy to work with manifests without going to the raw XML. Take a look at the tabs at the bottom of the editor. They are as follows :


This page describes a plug-in, and you can see an example in Figure 12-8.


This displays summary information for the plug-in (including plug-in name, version, provider, and so forth).


This details the plug-ins that are required to run this plug-in.


This details the libraries needed to run this plug-in.


This details the extensions used by the plug-in to build on other plug-ins.

Extension Points

This details the extension points defined by the plug-in.


This is the source for plugin.xml , which you can edit directly in an XML editor.

When we start adding our own functionality to plug-ins, we'll come back to the manifest editor. Eclipse 3.0

As you'd expect, the PDE is being expanded in Eclipse 3.0. For example, the PDE's Plug-in Project creation wizard has an option for creating plug-ins with OSGi bundle manifests (recommended only for plug-ins using the capabilities of the new OSGi-based Platform Runtime). And there's a new build configuration editor in the PDE, which means that if you want to use a file, the PDE gives you a specialized build configuration editor that facilitates the process.

12.3.4 See Also

Recipe 12.2 on creating plugin.xml ; Recipe 12.4 on testing plug-ins with the Run-time Workbench; Chapter 11 of Eclipse ( O'Reilly).

Eclipse Cookbook
Inside XML (Inside (New Riders))
ISBN: 596007108
EAN: 2147483647
Year: 2006
Pages: 232
Authors: Steve Holzner

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: