org.eclipse.palamedes.ui.preferences.stylesheets
Class StylesheetStore

java.lang.Object
  extended by org.eclipse.palamedes.ui.preferences.stylesheets.StylesheetStore

public class StylesheetStore
extends java.lang.Object

A collection of style sheets.


Constructor Summary
StylesheetStore(org.eclipse.jface.preference.IPreferenceStore store, java.lang.String key)
          Creates a new style sheet store.
 
Method Summary
 void add(StylesheetPersistenceData data)
          Adds a template encapsulated in its persistent form.
 void delete(StylesheetPersistenceData data)
          Removes a template from the store.
 Stylesheet findStylesheet(java.lang.String name)
          Returns the first enabled template that matches the name.
 Stylesheet findStylesheetById(java.lang.String id)
          Returns the first enabled style sheet that matches the given style sheet id.
 StylesheetPersistenceData[] getStylesheetData(boolean includeDeleted)
          Returns all style sheet data.
 StylesheetPersistenceData getStylesheetData(java.lang.String id)
          Returns the style sheet data of the style sheet with id id or null if no such style sheet can be found.
 Stylesheet[] getStylesheets()
          Returns all enabled style sheets.
protected  void handleException(java.io.IOException x)
          Handles an IOException thrown during reloading the preferences due to a preference store update.
protected  void internalAdd(StylesheetPersistenceData data)
          Adds a style sheet to the internal store.
 void load()
          Loads the style sheets from contributions and preferences.
protected  void loadContributedStylesheets()
          Hook method to load contributed style sheets.
 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 style sheets 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

StylesheetStore

public StylesheetStore(org.eclipse.jface.preference.IPreferenceStore store,
                       java.lang.String key)
Creates a new style sheet store.

Parameters:
store - the preference store in which to store custom style sheets under key
key - the key into store where to store custom style sheet
Method Detail

add

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

Parameters:
data - the template to add

delete

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

Parameters:
data - the template to remove

findStylesheet

public Stylesheet findStylesheet(java.lang.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 the name or null if none is found

findStylesheetById

public Stylesheet findStylesheetById(java.lang.String id)
Returns the first enabled style sheet that matches the given style sheet id.

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

getStylesheetData

public StylesheetPersistenceData[] getStylesheetData(boolean includeDeleted)
Returns all style sheet data.

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

getStylesheetData

public StylesheetPersistenceData getStylesheetData(java.lang.String id)
Returns the style sheet data of the style sheet with id id or null if no such style sheet can be found.

Parameters:
id - the id of the style sheet data
Returns:
the style sheet data of the style sheet with id id or null

getStylesheets

public Stylesheet[] getStylesheets()
Returns all enabled style sheets.

Returns:
all enabled style sheets

handleException

protected void handleException(java.io.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

internalAdd

protected void internalAdd(StylesheetPersistenceData data)
Adds a style sheet to the internal store. The added style sheets must have a unique id.

Parameters:
data - the style sheet data to add

load

public void load()
          throws java.io.IOException
Loads the style sheets from contributions and preferences.

Throws:
java.io.IOException - if loading fails.

loadContributedStylesheets

protected void loadContributedStylesheets()
                                   throws java.io.IOException
Hook method to load contributed style sheets. Contributed style sheets are superseded by customized versions of user added style sheets stored in the preferences.

The default implementation does nothing.

Throws:
java.io.IOException - if loading fails

restoreDefaults

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


restoreDeleted

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


save

public void save()
          throws java.io.IOException
Saves the style sheets to the preferences.

Throws:
java.io.IOException - if the style sheets cannot be written

startListeningForPreferenceChanges

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


stopListeningForPreferenceChanges

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