Eclipse Platform
Release 3.0

org.eclipse.jface.text.templates.persistence
Class TemplateStore

java.lang.Object
  extended byorg.eclipse.jface.text.templates.persistence.TemplateStore

public class TemplateStore
extends Object

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
TemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key)
          Creates a new template store with a context type registry.
TemplateStore(IPreferenceStore store, String key)
          Creates a new template store.
 
Method Summary
 void add(TemplatePersistenceData data)
          Adds a template encapsulated in its persistent form.
 void delete(TemplatePersistenceData data)
          Removes a template from the store.
 Template findTemplate(String name)
          Returns the first enabled template that matches the name.
 Template findTemplate(String name, String contextTypeId)
          Returns the first enabled template that matches both name and context type id.
protected  ContextTypeRegistry getRegistry()
          Returns the registry.
 TemplatePersistenceData[] getTemplateData(boolean includeDeleted)
          Returns all template datas.
 Template[] getTemplates()
          Returns all enabled templates.
 Template[] getTemplates(String contextTypeId)
          Returns all enabled templates for the given context type.
protected  void internalAdd(TemplatePersistenceData data)
          Adds a template to the internal store.
 void load()
          Loads the templates from contributions and preferences.
protected  void loadContributedTemplates()
          Hook method to load contributed templates.
 void restoreDefaults()
          Deletes all user-added templates and reverts all contributed templates.
 void restoreDeleted()
          Restores all contributed templates that have been deleted.
 void save()
          Saves the templates to the preferences.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 Detail

load

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

Throws:
IOException - if loading fails.

loadContributedTemplates

protected void loadContributedTemplates()
                                 throws IOException
Hook method to load contributed templates. Contributed templates are superseded by customized versions of user added templates stored in the preferences.

The default implementation does nothing.

Throws:
IOException - if loading fails

internalAdd

protected void internalAdd(TemplatePersistenceData data)
Adds a template to the internal store. The added templates must have a unique id.

Parameters:
data - the template data to add

save

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

Throws:
IOException - if the templates cannot be written

add

public void add(TemplatePersistenceData data)
Adds a template encapsulated in its persistent form.

Parameters:
data - the template to add

delete

public void delete(TemplatePersistenceData data)
Removes a template from the store.

Parameters:
data - the template to remove

restoreDeleted

public void restoreDeleted()
Restores all contributed templates that have been deleted.


restoreDefaults

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


getTemplates

public Template[] getTemplates()
Returns all enabled templates.

Returns:
all enabled templates

getTemplates

public Template[] getTemplates(String contextTypeId)
Returns all enabled templates for the given context type.

Parameters:
contextTypeId - the id of the context type of the requested templates, or null if all templates should be returned
Returns:
all enabled templates for the given context type

findTemplate

public Template findTemplate(String name)
Returns the first enabled template that matches the name.

Parameters:
name - the name of the template searched for
Returns:
the first enabled template that matches both name and context type id, or null if none is found

findTemplate

public Template findTemplate(String name,
                             String contextTypeId)
Returns the first enabled template that matches both name and context type id.

Parameters:
name - the name of the template searched for
contextTypeId - the context type id to clip unwanted templates, or null if any context type is ok
Returns:
the first enabled template that matches both name and context type id, or null if none is found

getTemplateData

public TemplatePersistenceData[] getTemplateData(boolean includeDeleted)
Returns all template datas.

Parameters:
includeDeleted - whether to include deleted datas
Returns:
all template datas, whether enabled or not

getRegistry

protected final ContextTypeRegistry getRegistry()
Returns the registry.

Returns:
Returns the registry

Eclipse Platform
Release 3.0

Guidelines for using Eclipse APIs.

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