Class ChainedPreferenceStore
- java.lang.Object
-
- org.eclipse.ui.texteditor.ChainedPreferenceStore
-
- All Implemented Interfaces:
IPreferenceStore
public class ChainedPreferenceStore extends Object implements IPreferenceStore
Preference store that composes multiple preference stores in a chain and serves a preference value from the first preference store in the chain that contains the preference.This preference store is read-only i.e. write access throws an
UnsupportedOperationException.- Since:
- 3.0
-
-
Field Summary
-
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
Constructors Constructor Description ChainedPreferenceStore(IPreferenceStore[] preferenceStores)Sets the chained preference stores.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(IPropertyChangeListener listener)Adds a property change listener to this preference store.booleancontains(String name)Returns whether the named preference is known to this preference store.voidfirePropertyChangeEvent(String name, Object oldValue, Object newValue)Fires a property change event corresponding to a change to the current value of the preference with the given name.booleangetBoolean(String name)Returns the current value of the boolean-valued preference with the given name.booleangetDefaultBoolean(String name)Returns the default value for the boolean-valued preference with the given name.doublegetDefaultDouble(String name)Returns the default value for the double-valued preference with the given name.floatgetDefaultFloat(String name)Returns the default value for the float-valued preference with the given name.intgetDefaultInt(String name)Returns the default value for the integer-valued preference with the given name.longgetDefaultLong(String name)Returns the default value for the long-valued preference with the given name.StringgetDefaultString(String name)Returns the default value for the string-valued preference with the given name.doublegetDouble(String name)Returns the current value of the double-valued preference with the given name.floatgetFloat(String name)Returns the current value of the float-valued preference with the given name.intgetInt(String name)Returns the current value of the integer-valued preference with the given name.longgetLong(String name)Returns the current value of the long-valued preference with the given name.StringgetString(String name)Returns the current value of the string-valued preference with the given name.booleanisDefault(String name)Returns whether the current value of the preference with the given name has the default value.booleanneedsSaving()Returns whether the current values in this property store require saving.voidputValue(String name, String value)Sets the current value of the preference with the given name to the given string value without sending a property change.voidremovePropertyChangeListener(IPropertyChangeListener listener)Removes the given listener from this preference store.voidsetDefault(String name, boolean value)Sets the default value for the boolean-valued preference with the given name.voidsetDefault(String name, double value)Sets the default value for the double-valued preference with the given name.voidsetDefault(String name, float value)Sets the default value for the float-valued preference with the given name.voidsetDefault(String name, int value)Sets the default value for the integer-valued preference with the given name.voidsetDefault(String name, long value)Sets the default value for the long-valued preference with the given name.voidsetDefault(String name, String defaultObject)Sets the default value for the string-valued preference with the given name.voidsetToDefault(String name)Sets the current value of the preference with the given name back to its default value.voidsetValue(String name, boolean value)Sets the current value of the boolean-valued preference with the given name.voidsetValue(String name, double value)Sets the current value of the double-valued preference with the given name.voidsetValue(String name, float value)Sets the current value of the float-valued preference with the given name.voidsetValue(String name, int value)Sets the current value of the integer-valued preference with the given name.voidsetValue(String name, long value)Sets the current value of the long-valued preference with the given name.voidsetValue(String name, String value)Sets the current value of the string-valued preference with the given name.
-
-
-
Constructor Detail
-
ChainedPreferenceStore
public ChainedPreferenceStore(IPreferenceStore[] preferenceStores)
Sets the chained preference stores.- Parameters:
preferenceStores- the chained preference stores to set
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(IPropertyChangeListener listener)
Description copied from interface:IPreferenceStoreAdds a property change listener to this preference store.
Note The types of the oldValue and newValue of the generated PropertyChangeEvent are determined by whether or not the typed API in IPreferenceStore was called. If values are changed via setValue(name,type) the values in the PropertyChangedEvent will be of that type. If they are set using a non typed API (i.e. #setToDefault or using the OSGI Preferences) the values will be unconverted Strings.
A listener will be called in the same Thread that it is invoked in. Any Thread dependant listeners (such as those who update an SWT widget) will need to update in the correct Thread. In the case of an SWT update you can update using Display#syncExec(Runnable) or Display#asyncExec(Runnable).
Likewise any application that updates an IPreferenceStore from a Thread other than the UI Thread should be aware of any listeners that require an update in the UI Thread.
- Specified by:
addPropertyChangeListenerin interfaceIPreferenceStore- Parameters:
listener- a property change listener- See Also:
PropertyChangeEvent,IPreferenceStore.setToDefault(String),IPreferenceStore.setValue(String, boolean),IPreferenceStore.setValue(String, double),IPreferenceStore.setValue(String, float),IPreferenceStore.setValue(String, int),IPreferenceStore.setValue(String, long),IPreferenceStore.setValue(String, String)
-
removePropertyChangeListener
public void removePropertyChangeListener(IPropertyChangeListener listener)
Description copied from interface:IPreferenceStoreRemoves the given listener from this preference store. Has no effect if the listener is not registered.- Specified by:
removePropertyChangeListenerin interfaceIPreferenceStore- Parameters:
listener- a property change listener, must not benull
-
contains
public boolean contains(String name)
Description copied from interface:IPreferenceStoreReturns whether the named preference is known to this preference store.- Specified by:
containsin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
trueif either a current value or a default value is known for the named preference, andfalseotherwise
-
firePropertyChangeEvent
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue)
Description copied from interface:IPreferenceStoreFires a property change event corresponding to a change to the current value of the preference with the given name.This method is provided on this interface to simplify the implementation of decorators. There is normally no need to call this method since
setValueandsetToDefaultreport such events in due course. Implementations should funnel all preference changes through this method.- Specified by:
firePropertyChangeEventin interfaceIPreferenceStore- Parameters:
name- the name of the preference, to be used as the property in the event objectoldValue- the old valuenewValue- the new value
-
getBoolean
public boolean getBoolean(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the boolean-valued preference with the given name. Returns the default-default value (false) if there is no preference with the given name, or if the current value cannot be treated as a boolean.- Specified by:
getBooleanin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the boolean-valued preference
-
getDefaultBoolean
public boolean getDefaultBoolean(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the boolean-valued preference with the given name. Returns the default-default value (false) if there is no default preference with the given name, or if the default value cannot be treated as a boolean.- Specified by:
getDefaultBooleanin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultDouble
public double getDefaultDouble(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the double-valued preference with the given name. Returns the default-default value (0.0) if there is no default preference with the given name, or if the default value cannot be treated as a double.- Specified by:
getDefaultDoublein interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultFloat
public float getDefaultFloat(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the float-valued preference with the given name. Returns the default-default value (0.0f) if there is no default preference with the given name, or if the default value cannot be treated as a float.- Specified by:
getDefaultFloatin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultInt
public int getDefaultInt(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the integer-valued preference with the given name. Returns the default-default value (0) if there is no default preference with the given name, or if the default value cannot be treated as an integer.- Specified by:
getDefaultIntin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultLong
public long getDefaultLong(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the long-valued preference with the given name. Returns the default-default value (0L) if there is no default preference with the given name, or if the default value cannot be treated as a long.- Specified by:
getDefaultLongin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultString
public String getDefaultString(String name)
Description copied from interface:IPreferenceStoreReturns the default value for the string-valued preference with the given name. Returns the default-default value (the empty string"") is no default preference with the given name, or if the default value cannot be treated as a string.- Specified by:
getDefaultStringin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the default value of the named preference
-
getDouble
public double getDouble(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the double-valued preference with the given name. Returns the default-default value (0.0) if there is no preference with the given name, or if the current value cannot be treated as a double.- Specified by:
getDoublein interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the double-valued preference
-
getFloat
public float getFloat(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the float-valued preference with the given name. Returns the default-default value (0.0f) if there is no preference with the given name, or if the current value cannot be treated as a float.- Specified by:
getFloatin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the float-valued preference
-
getInt
public int getInt(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the integer-valued preference with the given name. Returns the default-default value (0) if there is no preference with the given name, or if the current value cannot be treated as an integer.- Specified by:
getIntin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the int-valued preference
-
getLong
public long getLong(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the long-valued preference with the given name. Returns the default-default value (0L) if there is no preference with the given name, or if the current value cannot be treated as a long.- Specified by:
getLongin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the long-valued preference
-
getString
public String getString(String name)
Description copied from interface:IPreferenceStoreReturns the current value of the string-valued preference with the given name. Returns the default-default value (the empty string"") if there is no preference with the given name, or if the current value cannot be treated as a string.- Specified by:
getStringin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
- the string-valued preference
-
isDefault
public boolean isDefault(String name)
Description copied from interface:IPreferenceStoreReturns whether the current value of the preference with the given name has the default value.- Specified by:
isDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preference- Returns:
trueif the preference has a known default value and its current value is the same, andfalseotherwise (including the case where the preference is unknown to this store)
-
needsSaving
public boolean needsSaving()
Description copied from interface:IPreferenceStoreReturns whether the current values in this property store require saving.- Specified by:
needsSavingin interfaceIPreferenceStore- Returns:
trueif at least one of values of the preferences known to this store has changed and requires saving, andfalseotherwise.
-
putValue
public void putValue(String name, String value)
Description copied from interface:IPreferenceStoreSets the current value of the preference with the given name to the given string value without sending a property change.This method does not fire a property change event and should only be used for setting internal preferences that are not meant to be processed by listeners. Normal clients should instead call #setValue.
- Specified by:
putValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setDefault
public void setDefault(String name, double value)
Description copied from interface:IPreferenceStoreSets the default value for the double-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new default value for the preference
-
setDefault
public void setDefault(String name, float value)
Description copied from interface:IPreferenceStoreSets the default value for the float-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new default value for the preference
-
setDefault
public void setDefault(String name, int value)
Description copied from interface:IPreferenceStoreSets the default value for the integer-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new default value for the preference
-
setDefault
public void setDefault(String name, long value)
Description copied from interface:IPreferenceStoreSets the default value for the long-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new default value for the preference
-
setDefault
public void setDefault(String name, String defaultObject)
Description copied from interface:IPreferenceStoreSets the default value for the string-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencedefaultObject- the new default value for the preference
-
setDefault
public void setDefault(String name, boolean value)
Description copied from interface:IPreferenceStoreSets the default value for the boolean-valued preference with the given name.Note that the current value of the preference is affected if the preference's current value was its old default value, in which case it changes to the new default value. If the preference's current is different from its old default value, its current value is unaffected. No property change events are reported by changing default values.
- Specified by:
setDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new default value for the preference
-
setToDefault
public void setToDefault(String name)
Description copied from interface:IPreferenceStoreSets the current value of the preference with the given name back to its default value.Note that the preferred way of re-initializing a preference to the appropriate default value is to call
setToDefault. This is implemented by removing the named value from the store, thereby exposing the default value.- Specified by:
setToDefaultin interfaceIPreferenceStore- Parameters:
name- the name of the preference
-
setValue
public void setValue(String name, double value)
Description copied from interface:IPreferenceStoreSets the current value of the double-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setValue
public void setValue(String name, float value)
Description copied from interface:IPreferenceStoreSets the current value of the float-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setValue
public void setValue(String name, int value)
Description copied from interface:IPreferenceStoreSets the current value of the integer-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setValue
public void setValue(String name, long value)
Description copied from interface:IPreferenceStoreSets the current value of the long-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setValue
public void setValue(String name, String value)
Description copied from interface:IPreferenceStoreSets the current value of the string-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
setValue
public void setValue(String name, boolean value)
Description copied from interface:IPreferenceStoreSets the current value of the boolean-valued preference with the given name.A property change event is reported if the current value of the preference actually changes from its previous value. In the event object, the property name is the name of the preference, and the old and new values are wrapped as objects.
Note that the preferred way of re-initializing a preference to its default value is to call
setToDefault.- Specified by:
setValuein interfaceIPreferenceStore- Parameters:
name- the name of the preferencevalue- the new current value of the preference
-
-