Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

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


java.lang.Object
  extended by 
org.eclipse.jface.text.templates.persistence.TemplateStore
Direct Known Subclasses:
ContributionTemplateStore

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.
  Template findTemplateById ( String id)
          Returns the first enabled template that matches the given template id.
protected   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.
  Template[] getTemplates ()
          Returns all enabled templates.
  Template[] getTemplates ( String contextTypeId)
          Returns all enabled templates for the given context type.
protected  void handleException ( IOException x)
          Handles an IOException thrown during reloading the preferences due to a preference store update.
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 restoreDefaults (boolean doSave)
          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.
 void startListeningForPreferenceChanges ()
          Starts listening for property changes on the preference store.
 void stopListeningForPreferenceChanges ()
          Stops the auto-updating behavior started by calling startListeningForPreferenceChanges().
 
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.

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.

Since:
3.2

stopListeningForPreferenceChanges

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

Since:
3.2

handleException

protected void handleException(
IOException x)
Handles an IOException thrown during reloading the preferences due to a preference store update. The default is to write to stderr.

Parameters:
x - the exception
Since:
3.2

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(boolean doSave)
Deletes all user-added templates and reverts all contributed templates.

Parameters:
doSave - true if the store should be saved after restoring
Since:
3.5

restoreDefaults

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

Note: the store will be saved after restoring.


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

findTemplateById

public 
Template findTemplateById(
String id)
Returns the first enabled template that matches the given template id.

Parameters:
id - the id of the template searched for
Returns:
the first enabled template that matches id, or null if none is found
Since:
3.1

getTemplateData

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

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

getTemplateData

public 
TemplatePersistenceData getTemplateData(
String id)
Returns the template data of the template with id id or null if no such template can be found.

Parameters:
id - the id of the template data
Returns:
the template data of the template with id id or null
Since:
3.1

getRegistry

protected final 
ContextTypeRegistry getRegistry()
Returns the registry.

Returns:
Returns the registry

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire