Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Eclipse Platform Release 3.0
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

## Package org.eclipse.jface.text.templates.persistence

Application programming interfaces for interaction with the Eclipse Java User Interface text support.

See:
Description

Class Summary
TemplatePersistenceData | TemplatePersistenceData stores information about a template.
TemplateReaderWriter | Serializes templates as character or byte stream and reads the same format back.
TemplateStore | A collection of templates.

## Package org.eclipse.jface.text.templates.persistence Description

Application programming interfaces for interaction with the Eclipse Java User Interface text support.

## Templates

### Packages

- `org.eclipse.jface.text.templates`
- `org.eclipse.ui.workbench.texteditor.templates`
- `org.eclipse.ui.editors.templates`

### Introduction

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.
Templates are specified as text, variables are defined using the `${variable}` notation known from Ant, for example. The following snippet shows an example template for an instance check in Java:

    if (${name} instanceof ${type}) {
        ${type} ${new_name} = (${type})${name};
        ${cursor}
    }

In this template, the variables (`name,type, ...`) 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 `cursor` variable.
Template functionality can be added to a custom text editor by offering `TemplateProposal`s as content assist choices, which is simplified by using a subclass of `TemplateCompletionProcessor`. User template management can be offered by including a `TemplatePreferencePage` which uses a `TemplateStore` and `ContextTypeRegistry` as the underlying model to store templates. The `org.eclipse.ui.editors.templates` extension point can be used to allow other plug-ins to contribute templates to an editor. This is accomplished by using the `ContributionTemplateStore` and `ContributionContextTypeRegistry` subclasses of the above types.
Template variables are resolved by a `TemplateVariableResolver.` `GlobalTemplateVariables` offers some default variables such as date, user, and selection, but advanced features such as resolving to language constructs can be performed in subclasses.

#### Classes

- `Template` a template consists of name, context type identifier, and a pattern.
- `TemplateTranslator` and `TemplateBuffer` are used to parse the template grammar and don't need to be used usually.
- A `TemplateProposal` can be offered in content assist, possibly created by a subclass of `TemplateCompletionProcessor.`
- `TemplateStore` and `ContextTypeRegistry` 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 `TemplateReaderWriter`.
- `ContributionTemplateStore` and `ContributionContextTypeRegistry` add awareness for the `org.eclipse.ui.editors.templates` extension point.
- `TemplatePreferencePage` allows the user to access the templates within a `TemplateStore.`

#### Example

See the Template Editor Example in the org.eclipse.ui.examples.javaeditor project.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Eclipse Platform Release 3.0
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.