<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML> | |
<HEAD> | |
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > | |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> | |
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> | |
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css"> | |
<title>Using extension point schema</title> | |
</head> | |
<BODY BGCOLOR="#ffffff"> | |
<h2>Using extension point schema</h2> | |
<p>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:</p> | |
<ul> | |
<li>Providing choices for the <b>New</b> pop-up menu so that only valid child elements | |
are added</li> | |
<li>Providing attribute information for the property sheet so that only valid | |
attributes are set</li> | |
<li>Providing correct attribute property editors that match the attribute types (boolean, | |
string, and enumeration).</li> | |
<li>Providing additional support for special attribute types ("java" | |
and "resource").</li> | |
<li>Using the status line to show the first sentence of the documentation | |
snippet for attributes when selected in the property sheet.</li> | |
</ul> | |
<h3>Example: Using the "Sample Parsers" extension point</h3> | |
<p>Before trying to use the extension point we defined before, we still need to | |
define the expected interface. Select the <b>com.example.xyz</b> project in the Navigator | |
and press the <img src="images/java-interface.png" alt="Create a Java Interface" > tool bar button to create a new Java interface. | |
Be sure to set the package name to <b>com.example.xyz</b> and interface name to | |
<b>IParser</b> before pressing <b>Finish</b>. Edit the interface to look like this:</p> | |
<font color='#4444CC'><pre> package com.example.xyz; | |
public interface IParser { | |
/** | |
* Run the parser using the provided mode | |
*/ | |
public void parse(int mode); | |
} | |
</pre></font> | |
<p>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.</p> | |
<ol> | |
<li>Open the manifest editor for the <b>com.example.xyz</b> plug-in.</li> | |
<li>Switch to the Extensions page and press <b>New-> Extension</b>.</li> | |
<li>You should have "com.example.xyz.parsers" available as a choice. Select | |
it and press <b>Finish</b>.</li> | |
<li>Select the newly added "com.example.xyz.parsers" element and popup the <b>New->parser | |
</b>menu. (We specified that our extension point can accommodate any | |
number of "parser" elements.)</li> | |
<li>Select the new parser element. The Extension Element Details section should show four | |
attributes: <b>id</b>, <b>name</b>, <b> class</b> and <b>mode</b>. Note how the status line shows the | |
short information about attributes as you select them. This information | |
comes directly from the extension point schema.</li> | |
<li>Change the <b> name</b> to "Default Parser". Change the <b>mode</b> to | |
"manual." </li> | |
<li>Click on the <b>class</b> 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 <b>DefaultParser</b> as the class name. | |
Press <b>Finish</b>. | |
</li> | |
<li>You should now be in the Java editor for the <b> DefaultParser</b> class. Notice | |
how it has implemented the right interface (<b>IParser</b>) and already has the stub | |
implementation of the "parse" method.<br> | |
Note that if you close the editor and click on the <b>class</b> hyperlink again, | |
the editor will reopen the <b>DefaultParser</b> 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.</li> | |
</ol> | |
<p>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.</p> | |
<p align="center"><font SIZE="2" COLOR="#3f7f5f"> | |
<img border="0" src="images/schema-usage.png" alt="Restriction choices appearing as choices in the property sheet cell editor" ></font></p> | |
</body> | |
</html> |