June 23, 2018
Hot Topics:

Developing Eclipse Plug-ins

  • September 29, 2005
  • By Peter Nehrer
  • Send Email »
  • More Articles »

The Dependencies page allows you to specify what other plug-ins yours depends on, for building as well as at run-time. Adding a plug-in dependency means that all Java packages that the chosen plug-in exports, as well as any Extension Points, are made available to your own code. You may choose to add any plug-in available in your SDK installation, as well as your workspace (in other words, other plug-ins you're currently working on). In this exercise, you have org.eclipse.core.runtime and org.eclipse.ui listed as your dependencies. Each dependency may be optional (just make sure your code is ready for it), and you may choose to re-export a dependency (select a plug-in in the list and click Properties...). You also may request that specific Java packages be made visible to your classloader, regardless of their origin. This is an advanced topic discussed in more detail in your Platform documentation. On this page, you may also perform various types of dependency analysis, which will give you a better idea of what exactly your plug-in depends on.

The Runtime page allows you to specify Java packages you want to export (in other words, make visible to plug-ins listing your plug-in among their own dependencies). In this exercise, you don't have anything to export because you don't provide any functionality that you intend to make available as public API. If you did, you could also qualify their visibility with respect to downstream plug-ins (also a more advanced topic). The Classpath section is used to specify which class folders or JAR files should be on your run-time classpath, if there are multiple (by default, only the root of your plug-in is included in its classpath).

The Extensions page is where you specify all your plug-in's Extensions. It consists of a tree of Extensions implemented by your plug-in (you can choose from the Extension Points published by plug-ins listed in your Dependencies), and a detail form with fields reflecting the current tree selection. To create new Extension elements, right-click an element in the tree and choose from the New sub-menu. The choice of elements, as well as each element's set of properties, depends on the associated Extension Point's schema. You can obtain your Extension Point's documentation by right-clicking the Extension in the tree, then choosing Show Description. In fact, to continue with our example, we will add a new Extension to provide our Superview implementation:

  1. Click Add. In the New Extension dialog, select extension point org.eclipse.ui.views. Click Finish.
  2. Right-click the Extension in the list; choose New -> category. Enter Developer.com as the name.
  3. Right-click the Extension again, choose New -> view. Enter Superview as the name and com.developer.superview.category1 as the category (to match the ID of the category created in the previous step).
  4. Click the class link. Enter Superview as the class name and click Finish. This will create a new class implementing the required interface and open it up in the Java Editor.

You will return to implementing the view in a moment. For now, activate the Plug-in Manifest Editor and click the Extension Points tab. If applicable, this is where you would list the Extension Points published by your plug-in. The details of each Extension Point schema is specified using the Extension Point Schema Editor (not discussed in this article).

The Build page allows you to specify your plug-in's build configuration (or check Custom Build for a completely custom build process, which you'd have to implement). This information is used by the incremental builder (your project's build path is updated accordingly, which is one reason you should not alter it directly, but let PDE do it for you), as well as an Ant build script, should you choose to generate one. In this exercise, you have no special build requirements. If you did, for example, use a custom icon for your view, then you'd have to ensure that its path is checked in the Binary Build section to make it accessible to your code at run-time.

The MANIFEST.MF, plugin.xml, and build.properties pages allow you to edit the source of each respective file. This is, however, not recommended for anyone but the more experienced Eclipse developers.

Now that you're familiar with the Plug-in Manifest Editor, you can continue developing your example:

  1. Activate the Superview.java editor. You'll see that, to complete the view implementation, you have to implement at least two methods: createPartControl(Composite) and setFocus(). At this time, I will not go into the details of the underlying API (JFace, in this case). For now, it should be enough for you to know that you create a table-like visual component—table viewer—to display your view's contents. You then configure it with a content provider to give it the ability to navigate your model (or more specifically, to extract your model's structural elements suitable for inclusion in a table), and a label provider, to give it the ability to convert your model's elements into table cells with textual labels and optional images. You also configure it with a sorter to display the entries in alphabetical order. Lastly, you give it an input—your model object, which is an array of descriptors of all views available in the workbench at run-time. The full implementation is shown in Listing 2.
Listing 2: Initial view implementation:

public class Superview extends ViewPart {

    private TableViewer viewer;

    public void createPartControl(Composite parent) {
        viewer = new TableViewer(parent);
        viewer.setContentProvider(new ArrayContentProvider());
        viewer.setLabelProvider(new LabelProvider());
        viewer.setSorter(new ViewerSorter());

    public void setFocus() {

This gives you enough to run the example. Save all unsaved files and do the following:

  1. Right-click the plug-in project in your Package Explorer and choose Run As -> Eclipse Application. This will create a new Eclipse Launch Configuration with default values (which are sufficient for this example), and launch it.
  2. When the run-time workbench comes up, you should be greeted by the Welcome view. Click Window -> Show View -> Other... and select Developer.com -> Superview. Click OK.

What you should see is the Superview showing a list of entries in the form "View(<view id>)" (refer to Figure 2). This result is acceptable for the purpose of this exercise—you demonstrated the process of developing a simple visual plug-in using PDE, without going into too much API detail. However, if you want to delve deeper into JFace before the next installment of the series comes out, read on to see how you can make the view's contents more human-readable.

At this point, each entry in the table represents a workbench view; the model object you provided as the viewer's input is an array of view descriptors (IViewDescriptor), and the content provider you used turns any array object into a list of its elements (basically, given the array object as the parent, it returns its elements as the children). But, the label provider you installed simply uses each element's toString() method as its label. Interface IViewDescriptor does provide a method to get the view's label (getLabel()), and even the view's icon image (getImageDescriptor()). All you need to do to take advantage of them is override two of the label provider's methods:

  1. Close runtime workbench. In the Superview.java editor, subclass new LabelProvider() as shown in Listing 3:
Listing 3: Label provider customization:

viewer.setLabelProvider(new LabelProvider() {
    private final Map images = new HashMap();
    public String getText(Object element) {
        return ((IViewDescriptor) element).getLabel();
    public Image getImage(Object element) {
        Image image = (Image) images.get(element);
        if (image == null) {
            IViewDescriptor view = (IViewDescriptor) element;
            ImageDescriptor desc = view.getImageDescriptor();
            image = desc.createImage();
            images.put(element, image);
        return image;
    public void dispose() {
        for (Iterator i = images.values().iterator(); i.hasNext();)
            ((Image) i.next()).dispose();

Page 2 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date