Just An Application

November 5, 2009

An Extended NewAnnotation Wizard For Eclipse: Defining The NewWizard Extension

To make Eclipse aware that the fragment contains a wizard we have to define an extension corresponding to the Eclipse defined extension point

    org.eclipse.ui.newWizards

As it says in the documentation for this extension point, which can be found here Platform Plug-in Developer Guide:Reference:Extension Points Reference:org.eclipse.ui.newWizards

This extension point is used to register resource creation wizard extensions. Creation wizards appear as choices within the “New Dialog”, and are typically used to create folders and files.

In the “New Dialog”, wizards are organized into categories which usually reflect a particular problem domain. For instance, a Java oriented plugin may define a category called “Java” which is appropriate for “Class” or “Package” creation wizards. The categories defined by one plug-in can be referenced by other plug-ins using the category attribute. Uncategorized wizards, as well as wizards with invalid category paths, will end up in an “Other” category.

An extension can be defined by simply adding a piece of XML conforming to the schema for the corresponding extension point to the fragment.xml file.

There are two ways to do this. The first is to use the ‘Extensions’ tab of the ‘Fragment’ view which you can bring-ip by double-clicking the MANIFEST.MF file in the ‘Package Explorer’ view.

Extensions

Click Add to bring up the ‘New Extension’ dialog

ExtensionPointSelection

Enter org.eclipse.ui.newWizards in the ‘Extension Pointer filter’ text field. It will appear as the sole element in the list below it. Select it and hit ‘Finish’.

Extensions2

Control-click or right-click the org.eclipse.ui.newWizards element then select New > wizard from the pop-menu.

Extensions3

Then fill in the fields of the resulting editor.

Extensions4

Alternatively you can create a file called fragment.xml in the root directory of the project and put something like this in it.


    <?xml version="1.0" encoding="UTF-8"?>
    <?eclipse version="3.4"?>
    <fragment>
        <extension
            point = "org.eclipse.ui.newWizards">
            <wizard
                name     = "%NewAnnotationType.label"
                icon     = "$nl$/icons/full/etool16/newannotation_wiz.gif"
                category = "org.eclipse.jdt.ui.java"
                id       = "xper.eclipse.plugin.jdt.ui.wizards.NewAnnotationCreationWizard">
                <class 
                    class = "xper.eclipse.plugin.jdt.ui.annotation.NewAnnotationWizard">
                    <parameter 
                        name  = "javatype" 
                        value = "true"/>
                </class>
            </wizard>
        </extension>
    </fragment>

In this case, the name is the same as that of the Eclipse supplied wizard and is in fact a property. The existing value is accessible because the fragment is hosted by the bundle defining. Using the same value however results in two wizards with the same name appearing in menus, etc., which is a bit confusing so I defined a new value in the fragment.properties file.

The fragment.properties file should be in the root directory of the project. In this case it simply contains a single entry.

    NewAnnotationType.label = Annotation [extended]

The icon is that of the Eclipse suppiied wizard and is accessible for the same reason as the name.

The category is the same as that for the Eclipse supplied Java type creation wizards which ensures that the new wizard appears in all the same places that they do.

Note that If you do create the fragment.xml file by hand, and/or a fragment.properties file you will need to add them to the list of files to be included in the binary build, which is configurable from the ‘Build ‘ tab of the ‘Fragment’ view.

Running the fragment using the Eclipse Application configuration results in the new wizard being available. For example, from the drop-down menu of the Java creation button

DropDown


Copyright (c) 2009 By Simon Lewis. All Rights Reserved

Advertisements

Create a free website or blog at WordPress.com.

%d bloggers like this: