org.mailster.gui.prefs.store
Class MailsterPrefStore

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.mailster.gui.prefs.store.MailsterPrefStore
All Implemented Interfaces:
org.eclipse.jface.preference.IPersistentPreferenceStore, org.eclipse.jface.preference.IPreferenceStore

public class MailsterPrefStore
extends org.eclipse.core.commands.common.EventManager
implements org.eclipse.jface.preference.IPersistentPreferenceStore

A concrete preference store implementation based on an internal OrderedProperties object, with support for persisting the non-default preference values to files or streams.

This class was not designed to be subclassed.

See Also:
IPreferenceStore

Field Summary
private  OrderedProperties defaultProperties
          The mapping from preference name to default preference value (represented as strings); null if none.
private  boolean dirty
          Indicates whether a value as been changed by setToDefault or setValue; initially false.
private  java.lang.String filename
          The file name used by the load method to load a property file.
static java.lang.String HEADER
          The header inserted at top of the properties file.
private  OrderedProperties properties
          The mapping from preference name to preference value (represented as strings).
 
Fields inherited from interface org.eclipse.jface.preference.IPreferenceStore
BOOLEAN_DEFAULT_DEFAULT, DOUBLE_DEFAULT_DEFAULT, FALSE, FLOAT_DEFAULT_DEFAULT, INT_DEFAULT_DEFAULT, LONG_DEFAULT_DEFAULT, STRING_DEFAULT_DEFAULT, TRUE
 
Constructor Summary
private MailsterPrefStore()
          Creates an empty preference store.
  MailsterPrefStore(java.lang.String filename)
          Creates an empty preference store that loads from and saves to the a file.
 
Method Summary
 void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
           
 boolean contains(java.lang.String name)
           
 void firePropertyChangeEvent(java.lang.String name, java.lang.Object oldValue, java.lang.Object newValue)
           
private  boolean getBoolean(java.util.Properties p, java.lang.String name)
          Helper function: gets boolean for a given name.
 boolean getBoolean(java.lang.String name)
           
 boolean getDefaultBoolean(java.lang.String name)
           
 double getDefaultDouble(java.lang.String name)
           
 float getDefaultFloat(java.lang.String name)
           
 int getDefaultInt(java.lang.String name)
           
 long getDefaultLong(java.lang.String name)
           
 java.lang.String getDefaultString(java.lang.String name)
           
private  double getDouble(java.util.Properties p, java.lang.String name)
          Helper function: gets double for a given name.
 double getDouble(java.lang.String name)
           
private  float getFloat(java.util.Properties p, java.lang.String name)
          Helper function: gets float for a given name.
 float getFloat(java.lang.String name)
           
private  int getInt(java.util.Properties p, java.lang.String name)
          Helper function: gets int for a given name.
 int getInt(java.lang.String name)
           
private  long getLong(java.util.Properties p, java.lang.String name)
          Helper function: gets long for a given name.
 long getLong(java.lang.String name)
           
private  java.lang.String getString(java.util.Properties p, java.lang.String name)
          Helper function: gets string for a given name.
 java.lang.String getString(java.lang.String name)
           
 boolean isDefault(java.lang.String name)
           
 void list(java.io.PrintStream out)
          Prints the contents of this preference store to the given print stream.
 void list(java.io.PrintWriter out)
          Prints the contents of this preference store to the given print writer.
 void load()
          Loads this preference store from the file established in the constructor PreferenceStore(java.lang.String) (or by setFileName).
 void load(java.io.InputStream in)
          Loads this preference store from the given input stream.
 boolean needsSaving()
           
 java.lang.String[] preferenceNames()
          Returns an enumeration of all preferences known to this store which have current values other than their default value.
 void putValue(java.lang.String name, java.lang.String value)
           
 void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
           
 void save()
          Saves the non-default-valued preferences known to this preference store to the file from which they were originally loaded.
 void save(java.io.OutputStream out, java.lang.String header)
          Saves this preference store to the given output stream.
 void setDefault(java.lang.String name, boolean value)
           
 void setDefault(java.lang.String name, double value)
           
 void setDefault(java.lang.String name, float value)
           
 void setDefault(java.lang.String name, int value)
           
 void setDefault(java.lang.String name, long value)
           
 void setDefault(java.lang.String name, java.lang.String value)
           
 void setFilename(java.lang.String name)
          Sets the name of the file used when loading and storing this preference store.
 void setToDefault(java.lang.String name)
           
private  void setValue(java.util.Properties p, java.lang.String name, boolean value)
          Helper method: sets the value for a given name.
private  void setValue(java.util.Properties p, java.lang.String name, double value)
          Helper method: sets value for a given name.
private  void setValue(java.util.Properties p, java.lang.String name, float value)
          Helper method: sets value for a given name.
private  void setValue(java.util.Properties p, java.lang.String name, int value)
          Helper method: sets value for a given name.
private  void setValue(java.util.Properties p, java.lang.String name, long value)
          Helper method: sets the value for a given name.
private  void setValue(java.util.Properties p, java.lang.String name, java.lang.String value)
          Helper method: sets the value for a given name.
 void setValue(java.lang.String name, boolean value)
           
 void setValue(java.lang.String name, double value)
           
 void setValue(java.lang.String name, float value)
           
 void setValue(java.lang.String name, int value)
           
 void setValue(java.lang.String name, long value)
           
 void setValue(java.lang.String name, java.lang.String value)
           
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER

public static final java.lang.String HEADER
The header inserted at top of the properties file.

See Also:
Constant Field Values

properties

private OrderedProperties properties
The mapping from preference name to preference value (represented as strings).


defaultProperties

private OrderedProperties defaultProperties
The mapping from preference name to default preference value (represented as strings); null if none.


dirty

private boolean dirty
Indicates whether a value as been changed by setToDefault or setValue; initially false.


filename

private java.lang.String filename
The file name used by the load method to load a property file. This filename is used to save the properties file when save is called.

Constructor Detail

MailsterPrefStore

private MailsterPrefStore()
Creates an empty preference store.

Use the methods load(InputStream) and save(InputStream) to load and store this preference store.

See Also:
load(InputStream), save(OutputStream, String)

MailsterPrefStore

public MailsterPrefStore(java.lang.String filename)
Creates an empty preference store that loads from and saves to the a file.

Use the methods load() and save() to load and store this preference store.

Parameters:
filename - the file name
See Also:
load(), save()
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface org.eclipse.jface.preference.IPreferenceStore

contains

public boolean contains(java.lang.String name)
Specified by:
contains in interface org.eclipse.jface.preference.IPreferenceStore

firePropertyChangeEvent

public void firePropertyChangeEvent(java.lang.String name,
                                    java.lang.Object oldValue,
                                    java.lang.Object newValue)
Specified by:
firePropertyChangeEvent in interface org.eclipse.jface.preference.IPreferenceStore

getBoolean

public boolean getBoolean(java.lang.String name)
Specified by:
getBoolean in interface org.eclipse.jface.preference.IPreferenceStore

getBoolean

private boolean getBoolean(java.util.Properties p,
                           java.lang.String name)
Helper function: gets boolean for a given name.

Parameters:
p -
name -
Returns:
boolean

getDefaultBoolean

public boolean getDefaultBoolean(java.lang.String name)
Specified by:
getDefaultBoolean in interface org.eclipse.jface.preference.IPreferenceStore

getDefaultDouble

public double getDefaultDouble(java.lang.String name)
Specified by:
getDefaultDouble in interface org.eclipse.jface.preference.IPreferenceStore

getDefaultFloat

public float getDefaultFloat(java.lang.String name)
Specified by:
getDefaultFloat in interface org.eclipse.jface.preference.IPreferenceStore

getDefaultInt

public int getDefaultInt(java.lang.String name)
Specified by:
getDefaultInt in interface org.eclipse.jface.preference.IPreferenceStore

getDefaultLong

public long getDefaultLong(java.lang.String name)
Specified by:
getDefaultLong in interface org.eclipse.jface.preference.IPreferenceStore

getDefaultString

public java.lang.String getDefaultString(java.lang.String name)
Specified by:
getDefaultString in interface org.eclipse.jface.preference.IPreferenceStore

getDouble

public double getDouble(java.lang.String name)
Specified by:
getDouble in interface org.eclipse.jface.preference.IPreferenceStore

getDouble

private double getDouble(java.util.Properties p,
                         java.lang.String name)
Helper function: gets double for a given name.

Parameters:
p -
name -
Returns:
double

getFloat

public float getFloat(java.lang.String name)
Specified by:
getFloat in interface org.eclipse.jface.preference.IPreferenceStore

getFloat

private float getFloat(java.util.Properties p,
                       java.lang.String name)
Helper function: gets float for a given name.

Parameters:
p -
name -
Returns:
float

getInt

public int getInt(java.lang.String name)
Specified by:
getInt in interface org.eclipse.jface.preference.IPreferenceStore

getInt

private int getInt(java.util.Properties p,
                   java.lang.String name)
Helper function: gets int for a given name.

Parameters:
p -
name -
Returns:
int

getLong

public long getLong(java.lang.String name)
Specified by:
getLong in interface org.eclipse.jface.preference.IPreferenceStore

getLong

private long getLong(java.util.Properties p,
                     java.lang.String name)
Helper function: gets long for a given name.

Parameters:
p - the properties
name - the name of the property
Returns:
the return value as a long

getString

public java.lang.String getString(java.lang.String name)
Specified by:
getString in interface org.eclipse.jface.preference.IPreferenceStore

getString

private java.lang.String getString(java.util.Properties p,
                                   java.lang.String name)
Helper function: gets string for a given name.

Parameters:
p - the properties
name - the property name
Returns:
the return value as a String

isDefault

public boolean isDefault(java.lang.String name)
Specified by:
isDefault in interface org.eclipse.jface.preference.IPreferenceStore

list

public void list(java.io.PrintStream out)
Prints the contents of this preference store to the given print stream.

Parameters:
out - the print stream

list

public void list(java.io.PrintWriter out)
Prints the contents of this preference store to the given print writer.

Parameters:
out - the print writer

load

public void load()
          throws java.io.IOException
Loads this preference store from the file established in the constructor PreferenceStore(java.lang.String) (or by setFileName). Default preference values are not affected.

Throws:
java.io.IOException - if there is a problem loading this store

load

public void load(java.io.InputStream in)
          throws java.io.IOException
Loads this preference store from the given input stream. Default preference values are not affected.

Parameters:
in - the input stream
Throws:
java.io.IOException - if there is a problem loading this store

needsSaving

public boolean needsSaving()
Specified by:
needsSaving in interface org.eclipse.jface.preference.IPreferenceStore

preferenceNames

public java.lang.String[] preferenceNames()
Returns an enumeration of all preferences known to this store which have current values other than their default value.

Returns:
an array of preference names

putValue

public void putValue(java.lang.String name,
                     java.lang.String value)
Specified by:
putValue in interface org.eclipse.jface.preference.IPreferenceStore

removePropertyChangeListener

public void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface org.eclipse.jface.preference.IPreferenceStore

save

public void save()
          throws java.io.IOException
Saves the non-default-valued preferences known to this preference store to the file from which they were originally loaded.

Specified by:
save in interface org.eclipse.jface.preference.IPersistentPreferenceStore
Throws:
java.io.IOException - if there is a problem saving this store

save

public void save(java.io.OutputStream out,
                 java.lang.String header)
          throws java.io.IOException
Saves this preference store to the given output stream. The given string is inserted as header information.

Parameters:
out - the output stream
header - the header
Throws:
java.io.IOException - if there is a problem saving this store

setDefault

public void setDefault(java.lang.String name,
                       double value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setDefault

public void setDefault(java.lang.String name,
                       float value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setDefault

public void setDefault(java.lang.String name,
                       int value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setDefault

public void setDefault(java.lang.String name,
                       long value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setDefault

public void setDefault(java.lang.String name,
                       java.lang.String value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setDefault

public void setDefault(java.lang.String name,
                       boolean value)
Specified by:
setDefault in interface org.eclipse.jface.preference.IPreferenceStore

setFilename

public void setFilename(java.lang.String name)
Sets the name of the file used when loading and storing this preference store.

Afterward, the methods load() and save() can be used to load and store this preference store.

Parameters:
name - the file name
See Also:
load(), save()

setToDefault

public void setToDefault(java.lang.String name)
Specified by:
setToDefault in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     double value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     float value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     int value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     long value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     java.lang.String value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

public void setValue(java.lang.String name,
                     boolean value)
Specified by:
setValue in interface org.eclipse.jface.preference.IPreferenceStore

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      double value)
Helper method: sets value for a given name.

Parameters:
p -
name -
value -

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      float value)
Helper method: sets value for a given name.

Parameters:
p -
name -
value -

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      int value)
Helper method: sets value for a given name.

Parameters:
p -
name -
value -

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      long value)
Helper method: sets the value for a given name.

Parameters:
p -
name -
value -

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      java.lang.String value)
Helper method: sets the value for a given name.

Parameters:
p -
name -
value -

setValue

private void setValue(java.util.Properties p,
                      java.lang.String name,
                      boolean value)
Helper method: sets the value for a given name.

Parameters:
p -
name -
value -