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

# Class TemplateStore

java.lang.Object
org.eclipse.text.templates.TemplateStoreCore
org.eclipse.jface.text.templates.persistence.TemplateStore

Direct Known Subclasses:
  `ContributionTemplateStore`

public class TemplateStore extends TemplateStoreCore
A collection of templates. Clients may instantiate this class. In order to load templates contributed using the `org.eclipse.ui.editors.templates` extension point, use a `ContributionTemplateStore`.

Since:
  3.0

## Constructor Summary

Constructors
Constructor
Description
`TemplateStore(IPreferenceStore store, String key)`
Creates a new template store.
`TemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key)`
Creates a new template store with a context type registry.

## Method Summary

Modifier and Type
Method
Description
`void`
`add(TemplatePersistenceData data)`
`void`
`delete(TemplatePersistenceData data)`
`protected final ContextTypeRegistry`
`getRegistry()`
Returns the registry.
`TemplatePersistenceData[]`
`getTemplateData(boolean includeDeleted)`
Returns all template data.
`TemplatePersistenceData`
`getTemplateData(String id)`
Returns the template data of the template with id `id` or `null` if no such template can be found.
`protected void`
`internalAdd(TemplatePersistenceData data)`
`void`
`load()`
Loads the templates from contributions and preferences.
`void`
`restoreDefaults(boolean doSave)`
Deletes all user-added templates and reverts all contributed templates.
`void`
`save()`
Saves the templates to the preferences.
`final void`
`startListeningForPreferenceChanges()`
Starts listening for property changes on the preference store.
`final void`
`stopListeningForPreferenceChanges()`
Stops the auto-updating behavior started by calling `startListeningForPreferenceChanges()`.

### Methods inherited from class org.eclipse.text.templates.TemplateStoreCore

`add, delete, findTemplate, findTemplate, findTemplateById, getKey, getTemplates, getTemplates, handleException, internalAdd, internalGetTemplates, loadContributedTemplates, restoreDefaults, restoreDeleted`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### TemplateStore

public TemplateStore(IPreferenceStore store, String key)
Creates a new template store.

Parameters:
  `store` - the preference store in which to store custom templates under `key`
  `key` - the key into `store` where to store custom templates

### TemplateStore

public TemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key)
Creates a new template store with a context type registry. Only templates that specify a context type contained in the registry will be loaded by this store if the registry is not `null`.

Parameters:
  `registry` - a context type registry, or `null` if all templates should be loaded
  `store` - the preference store in which to store custom templates under `key`
  `key` - the key into `store` where to store custom templates

## Method Details

### load

public void load() throws IOException
Loads the templates from contributions and preferences.

Overrides:
  `load` in class `TemplateStoreCore`
Throws:
  `IOException` - if loading fails.

### startListeningForPreferenceChanges

public final void startListeningForPreferenceChanges()
Starts listening for property changes on the preference store. If the configured preference key changes, the template store is `reloaded`. Call `stopListeningForPreferenceChanges()` to remove any listener and stop the auto-updating behavior.

Overrides:
  `startListeningForPreferenceChanges` in class `TemplateStoreCore`
Since:
  3.2

### stopListeningForPreferenceChanges

public final void stopListeningForPreferenceChanges()
Stops the auto-updating behavior started by calling `startListeningForPreferenceChanges()`.

Overrides:
  `stopListeningForPreferenceChanges` in class `TemplateStoreCore`
Since:
  3.2

### save

public void save() throws IOException
Saves the templates to the preferences.

Overrides:
  `save` in class `TemplateStoreCore`
Throws:
  `IOException` - if the templates cannot be written

### restoreDefaults

public void restoreDefaults(boolean doSave)
Deletes all user-added templates and reverts all contributed templates.

Overrides:
  `restoreDefaults` in class `TemplateStoreCore`
Parameters:
  `doSave` - `true` if the store should be saved after restoring
Since:
  3.5

### getRegistry

protected final ContextTypeRegistry getRegistry()
Description copied from class: `TemplateStoreCore`
Returns the registry.

Overrides:
  `getRegistry` in class `TemplateStoreCore`
Returns:
  Returns the registry

### add

public void add(TemplatePersistenceData data)

### delete

public void delete(TemplatePersistenceData data)

### getTemplateData

public TemplatePersistenceData[] getTemplateData(boolean includeDeleted)
Description copied from class: `TemplateStoreCore`
Returns all template data.

Overrides:
  `getTemplateData` in class `TemplateStoreCore`
Parameters:
  `includeDeleted` - whether to include deleted data
Returns:
  all template data, whether enabled or not

### getTemplateData

public TemplatePersistenceData getTemplateData(String id)
Description copied from class: `TemplateStoreCore`
Returns the template data of the template with id `id` or `null` if no such template can be found.

Overrides:
  `getTemplateData` in class `TemplateStoreCore`
Parameters:
  `id` - the id of the template data
Returns:
  the template data of the template with id `id` or `null`

### internalAdd

protected void internalAdd(TemplatePersistenceData data)