<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
  <meta content="text/html; charset=iso-8859-1"
 http-equiv="Content-Type">
  <meta content="IBM" name="Author">
  <title>Templates</title>
  <meta content="Template Infrastructure package description"
 name="description">
</head>
<body>
Application programming interfaces for interaction
with the Eclipse Java User Interface text support.
<h2>Templates</h2>
<h3>Packages</h3>
<ul>
  <li><tt><big><strong>org.eclipse.jface.text.templates</strong></big></tt></li>
  <li><tt><big><strong>org.eclipse.ui.workbench.texteditor.templates</strong></big></tt></li>
  <li><tt><big><strong>org.eclipse.ui.editors.templates</strong></big></tt></li>
</ul>
<h3>Introduction</h3>
Templates are shortcuts for frequently used fragments of text such as
code patterns or complex text entities. They may contain variables
which are only resolved at the time when the template is inserted
within a context. Together with linked mode, inserting a template can
create a on-the-fly edit mask within a text viewer.<br>
<br>
Templates are specified as text, variables are defined using the <tt>${variable}</tt>
notation known from
Ant, for example. The following snippet shows an example template for
an instance check in Java:<br>
<pre>if (${name} instanceof ${type}) {
&nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};
&nbsp;&nbsp;&nbsp; ${cursor}
}
</pre>
In this template, the variables (<tt>name,type, ...</tt>) are resolved
when inserted into java source and changing one variable instance will
also change the other. When leaving linked mode, the caret is placed at
the <tt>cursor</tt> variable.<br>
<br>
Template functionality can be added to a custom text editor by offering
<tt>TemplateProposal</tt>s as content assist choices, which is
simplified by using a subclass of <tt>TemplateCompletionProcessor</tt>. User template management can be
offered by including a <tt>TemplatePreferencePage</tt> which uses a <tt>TemplateStore</tt> and <tt>ContextTypeRegistry</tt> as the
underlying model to store templates. The <tt>org.eclipse.ui.editors.templates</tt>
extension point can be used to allow other plug-ins to contribute
templates to an editor. This is accomplished by using the <tt>ContributionTemplateStore</tt> and <tt>ContributionContextTypeRegistry</tt>
subclasses of the above types.<br>
<br>
Template variables are resolved by a <tt>TemplateVariableResolver.</tt> <tt>GlobalTemplateVariables</tt> offers
some default variables such as date, user, and selection, but advanced
features such as resolving to language constructs can be performed in
subclasses.<br>
<h4>Classes</h4>
<ul>
  <li><tt>Template</tt> a template consists of name, context
type identifier, and a pattern.</li>
  <li><tt>TemplateTranslator</tt> and <tt>TemplateBuffer</tt> are used to
parse the template grammar and don't need to be used usually.</li>
  <li>A <tt>TemplateProposal </tt>can be
offered in content assist, possibly created by a subclass of <tt>TemplateCompletionProcessor.</tt></li>
  <li><tt>TemplateStore</tt> and <tt>ContextTypeRegistry</tt> manage a
set of templates within a plug-in and offer ways to store them in the
preferences or externally in XML streams via a <tt>TemplateReaderWriter</tt>.<br></li>
  <li><tt>ContributionTemplateStore</tt> and <tt>ContributionContextTypeRegistry</tt>
add awareness for the  <tt>org.eclipse.ui.editors.templates</tt>
extension point.</li>
  <li><tt>TemplatePreferencePage</tt> allows
the user to access the templates within a <tt>TemplateStore.</tt></li>
</ul>
<ul>
</ul>
<h4>Example</h4>
See the Template Editor Example in the <strong>org.eclipse.ui.examples.javaeditor</strong> project.<br>
</body>
</html>
