templates.library
Class TemplateLibrary

java.lang.Object
  extended by templates.library.TemplateLibrary

public class TemplateLibrary
extends java.lang.Object

Library of Templates.

Author:
Lenko Grigorov

Constructor Summary
TemplateLibrary(java.io.File dir)
          Create a new template library using the files in the given directory.
 
Method Summary
 void addListener(TemplateLibraryListener listener)
          Subscribe the given listener to receive notifications from this template library.
 void addTemplate(TemplateDescriptor td, ides.api.model.fsa.FSAModel model)
          Add a new template to the library, with the given properties and underlying model.
protected  void fireCollectionChanged()
          Announce a change in the content of the template library to all subscribed listeners.
 Template getTemplate(java.lang.String name)
          Retrieve the template with the given "ID".
 TemplateLibraryListener[] getTemplateLibraryListeners()
          Returns all current subscribers to this template library.
 java.util.Collection<Template> getTemplates()
          Retrieve the set of templates in the library.
protected  ides.api.model.fsa.FSAModel loadTemplateModel(java.io.File file)
          Load the model of a template from the given file.
 void reloadTemplate(java.lang.String name)
          Reload the given template from the file where the template is saved.
 void removeListener(TemplateLibraryListener listener)
          Cancel the subscription the given listener to receive notifications from this template library.
 void removeTemplate(java.lang.String name)
          Remove a template from the library and remove the file with the template from the directory of templates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateLibrary

public TemplateLibrary(java.io.File dir)
Create a new template library using the files in the given directory. Problems encountered when loading the templates are reported in the NoticeManager.

Parameters:
dir - the directory which contains the files where the models of the templates in the library are saved
Method Detail

getTemplates

public java.util.Collection<Template> getTemplates()
Retrieve the set of templates in the library.

Returns:
the set of templates in the library

getTemplate

public Template getTemplate(java.lang.String name)
Retrieve the template with the given "ID".

Parameters:
name - the "ID" of the template
Returns:
the template with the given "ID" if the library contains it; null otherwise
See Also:
Template.getName()

addTemplate

public void addTemplate(TemplateDescriptor td,
                        ides.api.model.fsa.FSAModel model)
                 throws java.io.IOException
Add a new template to the library, with the given properties and underlying model. The template is saved into a file in the directory of templates.

Parameters:
td - the properties of the new template
model - the underlying model for the new template
Throws:
java.io.IOException - when there is an IO problem while saving the new template into a file

removeTemplate

public void removeTemplate(java.lang.String name)
                    throws java.io.IOException
Remove a template from the library and remove the file with the template from the directory of templates.

Parameters:
name - the "ID" of the template to be removed
Throws:
java.io.IOException - when there is an IO problem while removing the file of the template

reloadTemplate

public void reloadTemplate(java.lang.String name)
                    throws java.io.IOException
Reload the given template from the file where the template is saved.

Parameters:
name - the "ID" of the template to be reloaded
Throws:
java.io.IOException - when there is an IO problem while loading the template from the file

loadTemplateModel

protected ides.api.model.fsa.FSAModel loadTemplateModel(java.io.File file)
                                                 throws ides.api.plugin.io.FileLoadException
Load the model of a template from the given file.

Parameters:
file - the file containing the template model
Returns:
the underlying model of the template, annotated with the description of the template
Throws:
ides.api.plugin.io.FileLoadException - when the loading of the template model failed; the exception may contain the partially-loaded model
See Also:
TemplateDescriptor

fireCollectionChanged

protected void fireCollectionChanged()
Announce a change in the content of the template library to all subscribed listeners.


addListener

public void addListener(TemplateLibraryListener listener)
Subscribe the given listener to receive notifications from this template library.

Parameters:
listener - the listener to be subscribed

removeListener

public void removeListener(TemplateLibraryListener listener)
Cancel the subscription the given listener to receive notifications from this template library.

Parameters:
listener - the listener whose subscription is to be cancelled

getTemplateLibraryListeners

public TemplateLibraryListener[] getTemplateLibraryListeners()
Returns all current subscribers to this template library.

Returns:
all current subscribers to this template library