Package org.eclipse.text.templates
Class TemplateStoreCore
java.lang.Object
org.eclipse.text.templates.TemplateStoreCore
- Direct Known Subclasses:
TemplateStore
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.7
-
Constructor Summary
ConstructorsConstructorDescriptionTemplateStoreCore(IEclipsePreferences store, String key) Creates a new template store.TemplateStoreCore(ContextTypeRegistry registry, IEclipsePreferences store, String key) Creates a new template store with a context type registry. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(TemplatePersistenceData data) Adds a template encapsulated in its persistent form.voidRemoves a template from the store.findTemplate(String name) Returns the first enabled template that matches the name.findTemplate(String name, String contextTypeId) Returns the first enabled template that matches both name and context type id.Returns the first enabled template that matches the given template id.protected final StringgetKey()Return the key into the Preference Store whose value contains the custom templates encoded as XML.protected ContextTypeRegistryReturns the registry.getTemplateData(boolean includeDeleted) Returns all template data.Returns the template data of the template with ididornullif no such template can be found.Template[]Returns all enabled templates.Template[]getTemplates(String contextTypeId) Returns all enabled templates for the given context type.protected voidHandles anIOExceptionthrown during reloading the preferences due to a preference store update.protected voidAdds a template to the internal store.protected final List<TemplatePersistenceData> Return the stored templatesvoidload()Loads the templates from contributions and preferences.protected voidHook method to load contributed templates.voidDeletes all user-added templates and reverts all contributed templates.voidrestoreDefaults(boolean doSave) Deletes all user-added templates and reverts all contributed templates.voidRestores all contributed templates that have been deleted.voidsave()Saves the templates to the preferences.voidStarts listening for property changes on the preference store.voidStops the auto-updating behavior started by callingstartListeningForPreferenceChanges().
-
Constructor Details
-
TemplateStoreCore
Creates a new template store.- Parameters:
store- the preference store in which to store custom templates underkeykey- the key intostorewhere to store custom templates
-
TemplateStoreCore
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 notnull.- Parameters:
registry- a context type registry, ornullif all templates should be loadedstore- the preference store in which to store custom templates underkeykey- the key intostorewhere to store custom templates
-
-
Method Details
-
load
Loads the templates from contributions and preferences.- Throws:
IOException- if loading fails.
-
startListeningForPreferenceChanges
public void startListeningForPreferenceChanges()Starts listening for property changes on the preference store. If the configured preference key changes, the template store isreloaded. CallstopListeningForPreferenceChanges()to remove any listener and stop the auto-updating behavior.- Since:
- 3.2
-
stopListeningForPreferenceChanges
public void stopListeningForPreferenceChanges()Stops the auto-updating behavior started by callingstartListeningForPreferenceChanges().- Since:
- 3.2
-
handleException
Handles anIOExceptionthrown 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
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
Adds a template to the internal store. The added templates must have a unique id.- Parameters:
data- the template data to add
-
save
Saves the templates to the preferences.- Throws:
IOException- if the templates cannot be written
-
add
Adds a template encapsulated in its persistent form.- Parameters:
data- the template to add
-
delete
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-trueif 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
Returns all enabled templates.- Returns:
- all enabled templates
-
getTemplates
Returns all enabled templates for the given context type.- Parameters:
contextTypeId- the id of the context type of the requested templates, ornullif all templates should be returned- Returns:
- all enabled templates for the given context type
-
findTemplate
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
nullif none is found
-
findTemplate
Returns the first enabled template that matches both name and context type id.- Parameters:
name- the name of the template searched forcontextTypeId- the context type id to clip unwanted templates, ornullif any context type is OK- Returns:
- the first enabled template that matches both name and context type id, or
nullif none is found
-
findTemplateById
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
nullif none is found - Since:
- 3.1
-
getTemplateData
Returns all template data.- Parameters:
includeDeleted- whether to include deleted data- Returns:
- all template data, whether enabled or not
-
getTemplateData
Returns the template data of the template with ididornullif no such template can be found.- Parameters:
id- the id of the template data- Returns:
- the template data of the template with id
idornull - Since:
- 3.1
-
getRegistry
Returns the registry.- Returns:
- Returns the registry
-
getKey
Return the key into the Preference Store whose value contains the custom templates encoded as XML.- Returns:
- the key in the Preference Store
-
internalGetTemplates
Return the stored templates- Returns:
- the stored templates
-