This being my first entry of my first web log, readers must bear with me for any ramblings.
As a new member of the Platform UI team, my first task was to implement new templates for some of the extension points. Since no one on the team had done anything like this, I began to research the templates already in existence (i.e. Action Sets, Editors, Property Pages, etc...). What I discovered was that all the current templates are owned and maintained by the PDE UI team and that a lot of the code they reference is internal. This isn’t a problem if the desire is to create a patch for the PDE UI team, however certain problems arise if one wishes to develop templates in a separate plug-in (as was our intention in the beginning).
To shorten this blog entry I will explain how to develop a new template from an internal standpoint and then in a different entry I will go over the necessary changes to separate the template into an external plug-in. Fittingly, the creation of an extension point template requires the use of two other extension points provided by org.eclipse.pde.ui: newExtensions and templates. org.eclipse.pde.ui.templates is responsible for using contributingId to link to the extension point you’re creating a sample of (e.g. org.eclipse.pde.ui.decorators) and, most importantly, for associating the template with the class file that’s going to do all the work. Then, org.eclipse.pde.ui.newExtensions is responsible for the appearance of the new template in the Extension Wizards tab when adding a New Extension. The settings for newExtension are fairly straightforward; a wizard element defines what name and icon will appear, and links to the newly created template element, then a corresponding description element defines what explanation text will appear.

If you are new to eclipse (as I was) and are looking at templates that have already been created then it is important to note that some of the values (i.e. name and the description) have been externalized to a properties file. When I was first examining the templates already in existence it took me a little while to discover that %newExtension.templates.hello.name referred to a variable within plugin.properties aptly named newExtension.templates.hello.name.
The next step is to develop the class file that will build the template wizard and will perform the generation of the new extension point sample. These tasks are greatly simplified by creating the new file as a subclass of PDETemplateSection. Then the easiest thing to do is to copy the code from another template file and modify it to meet your needs. While most of the methods you copy will be important, a lot of them may be left “as is” or will only require slight modifications to be correct for to your template (i.e. getSectionId). The two methods that will require specific tailoring are createOptions and updateModel. createOptions is responsible for adding the various fields to your wizard page and there are four types of fields that may be invoked; the string option provides space for a user to specify text, the Boolean option creates a checkbox, the choice options creates a combo box when one out of many choices needs to be selected or radio buttons if there are only two choices, and the blank field may be added to provide spacing on the wizard page. The first three options may be given a label and an initial value to be shown on the page. updateModel is then responsible for creating the elements that will appear in the plugin.xml file. Each element is created using an IPluginElement object which is then given the name of the desired element (@see IPluginElement#setName(String name)) and is then assigned attributes for each of the fields that need a value to be set (i.e. id, label, class, etc…). The elements must be created as an instance for the provided parent and then added to the parent (@see IPluginParen#add(IPluginObject child)) once all the attributes have been set. Also worthy of note is the use of externalized strings as defined in PDEUIMessages and whose values are set in pderesources.properties.

The last step is to add any binary files, such as icons, and java files that need to be associated with the extension point. Once the user hits the finish button, AbstractTemplateSection will look in a templates_3.X folder (usually templates_3.0 unless the extension point is only supported in later versions) for a folder with the same name as given in getSectionId and then generate any files and folders found within. Files and folders found in the directory bin are copied into the target project without modification while files found in the directory java are copied into the java source folder by creating the folder structure that corresponds to the package name (variable packageName). The java files are subject to conditional generation and variable replacement (i.e. referring to $pluginId$ will cause a replacement with a variable with the name pluginId as defined in the template class file). This functionality is usually used to set the package name of any required files with a name defined by the user on the template wizard page.
Armed with the templates that have already been created plus the above descriptions, you should now be able to go forth and create your own templates for any one of those wonderful extension points that exist out there. All you need now is committer rights for PDE UI or someone willing to apply your changes in the form of a patch. Failing that, there are indeed ways to perform the creation process from an external plug-in but I’ll save those details for a different entry.