Using extension point schema
Extension points defined by the plug-ins in your workspace are readily available
to your own plug-in and other plug-ins. If an extension point schema has been
defined for it, PDE can provide assistance when creating new extensions.
This assistance includes:
- Providing choices for the New pop-up menu so that only valid child elements
are added
- Providing attribute information for the property sheet so that only valid
attributes are set
- Providing correct attribute property editors that match the attribute types (boolean,
string, and enumeration).
- Providing additional support for special attribute types ("java"
and "resource").
- Using the status line to show the first sentence of the documentation
snippet for attributes when selected in the property sheet.
Example: Using the "Sample Parsers" extension point
Before trying to use the extension point we defined before, we still need to
define the expected interface. Select the com.example.xyz project in the Navigator
and press the
tool bar button to create a new Java interface.
Be sure to set the package name to com.example.xyz and interface name to
IParser before pressing Finish. Edit the interface to look like this:
package com.example.xyz;
public interface IParser {
/**
* Run the parser using the provided mode
*/
public void parse(int mode);
}
We now have the extension point, an XML schema for it, and the required
interface. Be sure to save all of your open editors. Everything is now
ready for our own plug-in or other plug-ins to
contribute to the extension point.
- Open the manifest editor for the com.example.xyz plug-in.
- Switch to the Extensions page and press New-> Extension.
- You should have "com.example.xyz.parsers" available as a choice. Select
it and press Finish.
- Select the newly added "com.example.xyz.parsers" element and popup the New->parser
menu. (We specified that our extension point can accommodate any
number of "parser" elements.)
- Select the new parser element. The Extension Element Details section should show four
attributes: id, name, class and mode. Note how the status line shows the
short information about attributes as you select them. This information
comes directly from the extension point schema.
- Change the name to "Default Parser". Change the mode to
"manual."
- Click on the class hyperlink in the Extension Element Details section. Here you will see that PDE is seamlessly integrated with
JDT's "New Java Class" wizard and utilizes schema attributes to automatically implement your IParser interface.
Create your class with "com.example.xyz/src" as your source folder, "com.example.xyz" as the package, and DefaultParser as the class name.
Press Finish.
- You should now be in the Java editor for the DefaultParser class. Notice
how it has implemented the right interface (IParser) and already has the stub
implementation of the "parse" method.
Note that if you close the editor and click on the class hyperlink again,
the editor will reopen the DefaultParser class. The "New Java Class" wizard will only appear
when the class specified in the class attribute text field cannot be found; otherwise, the link will
open the class in an editor.
As you can see, when you provide a complete XML schema for your extension
point, it will help all your potential users by letting PDE to assist them and
prevent them from making errors.
