comparison dwtx/jface/text/templates/package.html @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
2 <html>
3 <head>
4 <meta content="text/html; charset=iso-8859-1"
5 http-equiv="Content-Type">
6 <meta content="IBM" name="Author">
7 <title>Templates</title>
8 <meta content="Template Infrastructure package description"
9 name="description">
10 </head>
11 <body>
12 Application programming interfaces for interaction
13 with the Eclipse text editor template support.
14 <h2>Templates</h2>
15 <h3>Packages</h3>
16 <ul>
17 <li><tt><big><strong>org.eclipse.jface.text.templates</strong></big></tt></li>
18 <li><tt><big><strong>org.eclipse.ui.workbench.texteditor.templates</strong></big></tt></li>
19 <li><tt><big><strong>org.eclipse.ui.editors.templates</strong></big></tt></li>
20 </ul>
21 <h3>Introduction</h3>
22 Templates are shortcuts for frequently used fragments of text such as
23 code patterns or complex text entities. They may contain variables
24 which are only resolved at the time when the template is inserted
25 within a context. Together with linked mode, inserting a template can
26 create a on-the-fly edit mask within a text viewer.<br>
27 <br>
28 Templates are specified as text, variables are defined using the <tt>${variable}</tt>
29 notation known from
30 Ant, for example. The following snippet shows an example template for
31 an instance check in Java:<br>
32 <pre>if (${name} instanceof ${type}) {
33 &nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};
34 &nbsp;&nbsp;&nbsp; ${cursor}
35 }
36 </pre>
37 In this template, the variables (<tt>name,type, ...</tt>) are resolved
38 when inserted into java source and changing one variable instance will
39 also change the other. When leaving linked mode, the caret is placed at
40 the <tt>cursor</tt> variable.<br>
41 <br>
42 Template functionality can be added to a custom text editor by offering
43 <tt>TemplateProposal</tt>s as content assist choices, which is
44 simplified by using a subclass of <tt>TemplateCompletionProcessor</tt>. User template management can be
45 offered by including a <tt>TemplatePreferencePage</tt> which uses a <tt>TemplateStore</tt> and <tt>ContextTypeRegistry</tt> as the
46 underlying model to store templates. The <tt>org.eclipse.ui.editors.templates</tt>
47 extension point can be used to allow other plug-ins to contribute
48 templates to an editor. This is accomplished by using the <tt>ContributionTemplateStore</tt> and <tt>ContributionContextTypeRegistry</tt>
49 subclasses of the above types.<br>
50 <br>
51 Template variables are resolved by a <tt>TemplateVariableResolver.</tt> <tt>GlobalTemplateVariables</tt> offers
52 some default variables such as date, user, and selection, but advanced
53 features such as resolving to language constructs can be performed in
54 subclasses.<br>
55 <h4>Classes</h4>
56 <ul>
57 <li><tt>Template</tt> a template consists of name, context
58 type identifier, and a pattern.</li>
59 <li><tt>TemplateTranslator</tt> and <tt>TemplateBuffer</tt> are used to
60 parse the template grammar and don't need to be used usually.</li>
61 <li>A <tt>TemplateProposal </tt>can be
62 offered in content assist, possibly created by a subclass of <tt>TemplateCompletionProcessor.</tt></li>
63 <li><tt>TemplateStore</tt> and <tt>ContextTypeRegistry</tt> manage a
64 set of templates within a plug-in and offer ways to store them in the
65 preferences or externally in XML streams via a <tt>TemplateReaderWriter</tt>.<br></li>
66 <li><tt>ContributionTemplateStore</tt> and <tt>ContributionContextTypeRegistry</tt>
67 add awareness for the <tt>org.eclipse.ui.editors.templates</tt>
68 extension point.</li>
69 <li><tt>TemplatePreferencePage</tt> allows
70 the user to access the templates within a <tt>TemplateStore.</tt></li>
71 </ul>
72 <ul>
73 </ul>
74 <h4>Example</h4>
75 See the Template Editor Example in the <strong>org.eclipse.ui.examples.javaeditor</strong> project.<br>
76 </body>
77 </html>