com.mindtree.techworks.insight.preferences
Class PreferenceManager

java.lang.Object
  extended by com.mindtree.techworks.insight.preferences.PreferenceManager
All Implemented Interfaces:
PreferenceModelManager

public class PreferenceManager
extends java.lang.Object
implements PreferenceModelManager

This is a singleton class to be used by the entire application for accessing and storing Preferences.

The PreferencesManager is designed not to throw any exceptions, and whenever a particular exception value is missing or cannot be saved, it will simply return null. It is upto the calling method to determine whether it wants to terminate the usecase or continue with the execution of the program or display a warning to the user.

Version:
$Revision: 27 $ $Date: 2007-12-16 04:58:03 -0700 (Sun, 16 Dec 2007) $
Author:
Bindul Bhowmik
See Also:
Preference

Field Summary
 
Fields inherited from interface com.mindtree.techworks.insight.preferences.model.PreferenceModelManager
OPERATION_CHILD_PREF_ADDED, OPERATION_CHILD_PREF_REMOVED, OPERATION_PREF_ATTR_ADDED, OPERATION_PREF_ATTR_REMOVED
 
Method Summary
 void applicationShuttingDown()
          Method to be called when the application is being shut down.
 void attributeValueChanged(java.lang.String completePreferenceId, java.lang.String attributeId, java.lang.String newValue)
          Notifies all interested parties about change in an Attribute's value.
 void childPreferenceChanged(java.lang.String preferenceId, java.lang.String childPreferenceId, int operation)
          This method is used by the Manager to primarily regenerate the PreferenceInfo for the preference.
 void deregisterListener(java.lang.String completePreferenceId, PreferenceChangeListener listener)
          Removes a listener from the list of listeners for a preference, if already registered.
 void deregisterListener(java.lang.String completePreferenceId, java.lang.String attributeId, PreferenceAttributeChangeListener listener)
          Removes a listener from the list of listeners for an attribute, if already registered.
 void endPreferencesSave()
          Informs this PreferenceManager that the save is complete
 java.util.Collection getAllPreferenceNames()
          Returns preference info
 java.util.Collection getAllPreferences()
          Returns all the preferences
static PreferenceManager getInstance()
          Returns the singleton instance of PreferenceManager.
 Preference getPreference(java.lang.String preferenceId)
          Returns a Preference
 void preferenceAttributeChanged(java.lang.String preferenceId, java.lang.String preferenceAttributeId, int operation)
          This method is called on the Preference Model Manager by the Preference, whenever a child preference is added or deleted.
 void registerListener(java.lang.String completePreferenceId, PreferenceChangeListener listener)
          Registeres a listener to be notified of changes in preference values.
 void registerListener(java.lang.String completePreferenceId, java.lang.String attributeId, PreferenceAttributeChangeListener listener)
          Registeres a listener to be notified of changes in attribute values.
 void startPreferencesSave()
          Informs this PreferenceManager of an impending preference(s) save
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static PreferenceManager getInstance()
Returns the singleton instance of PreferenceManager.

Returns:
The singleton instance of PreferenceManager

getPreference

public Preference getPreference(java.lang.String preferenceId)
Returns a Preference

Parameters:
preferenceId - The preferenceId for which the preference is sought
Returns:
Preference The Preference

getAllPreferenceNames

public java.util.Collection getAllPreferenceNames()
Returns preference info

Returns:
List of PreferenceInfo objects.

getAllPreferences

public java.util.Collection getAllPreferences()
Returns all the preferences

Returns:
A Collectionof Preferences

registerListener

public void registerListener(java.lang.String completePreferenceId,
                             java.lang.String attributeId,
                             PreferenceAttributeChangeListener listener)
Registeres a listener to be notified of changes in attribute values.

Parameters:
completePreferenceId - The preference the listener is interested in
attributeId - The attribute in the preference the listener is interested in
listener - The listener to register. Must implement PreferenceAttributeChangeListener

deregisterListener

public void deregisterListener(java.lang.String completePreferenceId,
                               java.lang.String attributeId,
                               PreferenceAttributeChangeListener listener)
Removes a listener from the list of listeners for an attribute, if already registered.

Parameters:
completePreferenceId - The preference the listener is interested in
attributeId - The attribute in the preference the listener is interested in
listener - The listener to register.

registerListener

public void registerListener(java.lang.String completePreferenceId,
                             PreferenceChangeListener listener)
Registeres a listener to be notified of changes in preference values.

Parameters:
completePreferenceId - The preference the listener is interested in
listener - The listener to register. Must implement PreferenceChangeListener

deregisterListener

public void deregisterListener(java.lang.String completePreferenceId,
                               PreferenceChangeListener listener)
Removes a listener from the list of listeners for a preference, if already registered.

Parameters:
completePreferenceId - The preference the listener is interested in
listener - The listener to register.

attributeValueChanged

public void attributeValueChanged(java.lang.String completePreferenceId,
                                  java.lang.String attributeId,
                                  java.lang.String newValue)
Notifies all interested parties about change in an Attribute's value. Also helps in lazy writing.

This method is called by the PreferenceAttribute whose value changes. It is used by the PreferenceManager to notify all interested instances of PreferenceAttributeChangeListener instances registered with the PreferenceManager.

This method is also used by the manager to lazy write the preferences. If a different instance implements PreferenceModelManageris used, then the instance of PreferenceManager should register with that instance for notifications of all attribute value changes.

Specified by:
attributeValueChanged in interface PreferenceModelManager
Parameters:
completePreferenceId - The Preference in which the value changed
attributeId - The Attribute whose value changed
newValue - The new value of the attribute
See Also:
PreferenceModelManager.attributeValueChanged(java.lang.String, java.lang.String, java.lang.String)

childPreferenceChanged

public void childPreferenceChanged(java.lang.String preferenceId,
                                   java.lang.String childPreferenceId,
                                   int operation)
This method is used by the Manager to primarily regenerate the PreferenceInfo for the preference.

Specified by:
childPreferenceChanged in interface PreferenceModelManager
Parameters:
preferenceId - The current Preference id (complete id)
childPreferenceId - The preference id of the child preference
operation - Operation type, denoted by OPERATION_CHILD_PREF_ADDED or OPERATION_CHILD_PREF_REMOVED
See Also:
PreferenceModelManager.childPreferenceChanged(java.lang.String, java.lang.String, int)

applicationShuttingDown

public void applicationShuttingDown()
Method to be called when the application is being shut down. The manager will store all dirty preferences.


preferenceAttributeChanged

public void preferenceAttributeChanged(java.lang.String preferenceId,
                                       java.lang.String preferenceAttributeId,
                                       int operation)
Description copied from interface: PreferenceModelManager
This method is called on the Preference Model Manager by the Preference, whenever a child preference is added or deleted.

Specified by:
preferenceAttributeChanged in interface PreferenceModelManager
Parameters:
preferenceId - The current Preference id (complete id)
preferenceAttributeId - The preference id of the child preference
operation - Operation type, denoted by OPERATION_PREF_ATTR_REMOVED or OPERATION_PREF_ATTR_REMOVED
See Also:
PreferenceModelManager.preferenceAttributeChanged(java.lang.String, java.lang.String, int)

startPreferencesSave

public void startPreferencesSave()
Informs this PreferenceManager of an impending preference(s) save


endPreferencesSave

public void endPreferencesSave()
Informs this PreferenceManager that the save is complete



Copyright © 2003-2008 MindTree Consulting Ltd.. All Rights Reserved.