[Previous] [Next]



How to develop templates

Templates form an important part of the drive to support automatic GUI generation of various user interface types as supported in Eclipse frame work. These templates are often referred as project templates, as they are used to support the creation of ready-made projects. For example, you can define a template to create a simple GUI based EXE application for a set of Build Configurations.

The project templates are simple XML files, which follow a structure or schema defined in the TemplateDescriptorSchema.xsd file. These templates define the inputs and processes required to create a project for a particular platform. Inputs define the type of inputs required such as, files, settings etc. The processes define what to do with those inputs to create a particular type of project.

The New Project wizard lists all the templates available based on the matching criteria defined by the templates. Once the user selects a template from the list, the Template Engine plug-in processes the selected template. The plug-in generates the subsequent wizard pages based on whether the template needs user input or not.

This document details the schema for writing project templates. The schema file TemplateDescriptorSchema.xsd, which defines the structure for the project templates, is part of org.eclipse.cdt.templateengine plug-in.

The structure or schema for a project template is as follows:

<template
type="TemplateType"
version="Version"
supplier="Supplier"
revision="Revision"
author="Author"   
id="TemplateId"
label="Template label visible to the user"
description="A brief description of the template"
help="help.html"
preview-icon="icon.gif">

<property-group
id="properyGroupId"
label="Property group label"
description="A simple description of the property group"
type=" Type of UIElement group"
help="help.html"
branding-icon="icon.gif">
...
</property-group>

<process>
...
</process>

</template>

The root element for a project template is template, which provides the following properties or attributes to describe the template:

The template element includes the following child elements:

property-group

As mentioned earlier, a property-group includes the property elements that specify all the input fields required for a wizard page. A property-group can include any number of property elements. The following attributes can be used to describe a property group:

property

The syntax for the property elements included by the property-group element is as follows:

<property
id="propertyId"
label="User visible label of the property"
description="A brief description of the property"
type="type of the property"
pattern="Regular expression of the expected property"
default="Default value of the property"
size="size"
mandatory="true|false"
hidden="true|false"
persist="true|false">

     <item
     name="name of the item"
     label="User visible label of the item"
     selected="true|false">
     ...
     </item>
</property>

Here is a list of attributes of the property element:

If the property type is select or stringlist, you can include the item element to specify the items to be listed. There is no limitation on the number of items that can be listed. Here is the syntax for the item element:

<item
name="name of the item"
label="User visible label of the item"
selected="true|false">
</item>

Here is a list of attributes of the item element:

process

The process element within the root element of a project template defines the processes to be followed to create a project, based on the inputs taken. Here is the syntax for this element:

<process type="org.eclipse.cdt.templateengine.<process type>">
    <simple name="name" value=""/>

    <complex name="name">
        ...
    </complex>

    <simple-array name="values">
        ...
    </simple-array>

    <complex-array name="name">
        ...
    </complex-array>

</process>

A process element defines a single process. A process is like a procedure with a set of parameters. In similar terms, the process element defines the procedure. You need to specify all the parameters expected by a process. In the project template, you need to specify arguments for the process matching their types and in the order specified.

You can specify the process type using the type attribute. For example, to add files to a project you can use org.eclipse.cdt.templateengine.AddFiles as the process type.

A process element may include the following child elements:

Process types

A process type is a prototype of a process procedure. It defines the parameters required to complete a procedure. For example, to copy a file you need its source and destination information, which can be defined as parameters for the copy process.

The Template Engine plug-in provides a set of process types using the extension-point org.eclipse.cdt.templateengine.processType. Using these process types you can describe a process in your template. For example, you can describe the copy process by providing the source and destination folder names.

The following is a list of process types provided by the Template Engine:

Once the project template has been written, register it with Eclipse to make it available for use. For more information on this, refer to How to register a template with Eclipse.


See also: