Class ScopedPreferenceStore
- All Implemented Interfaces:
IPersistentPreferenceStore
,IPreferenceStore
A ScopedPreferenceStore does the lookup of a preference based on it's search scopes and sets the value of the preference based on its store scope.
The default scope is always included in the search scopes when searching for preference values.
- Since:
- 3.1
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
A boolean to indicate the property changes should not be propagated.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
ConstructorDescriptionScopedPreferenceStore
(IScopeContext context, String qualifier) Create a new instance of the receiver.ScopedPreferenceStore
(IScopeContext context, String qualifier, String defaultQualifierPath) Create a new instance of the receiver. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a property change listener to this preference store.boolean
Returns whether the named preference is known to this preference store.void
firePropertyChangeEvent
(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.boolean
getBoolean
(String name) Returns the current value of the boolean-valued preference with the given name.boolean
getDefaultBoolean
(String name) Returns the default value for the boolean-valued preference with the given name.double
getDefaultDouble
(String name) Returns the default value for the double-valued preference with the given name.float
getDefaultFloat
(String name) Returns the default value for the float-valued preference with the given name.int
getDefaultInt
(String name) Returns the default value for the integer-valued preference with the given name.long
getDefaultLong
(String name) Returns the default value for the long-valued preference with the given name.getDefaultString
(String name) Returns the default value for the string-valued preference with the given name.double
Returns the current value of the double-valued preference with the given name.float
Returns the current value of the float-valued preference with the given name.int
Returns the current value of the integer-valued preference with the given name.long
Returns the current value of the long-valued preference with the given name.getPreferenceNodes
(boolean includeDefault) Return the preference path to search preferences on.Returns the current value of the string-valued preference with the given name.boolean
Returns whether the current value of the preference with the given name has the default value.boolean
Returns whether the current values in this property store require saving.void
Sets the current value of the preference with the given name to the given string value without sending a property change.void
Removes the given listener from this preference store.void
save()
Saves the non-default-valued preferences known to this preference store to the file from which they were originally loaded.void
setDefault
(String name, boolean value) Sets the default value for the boolean-valued preference with the given name.void
setDefault
(String name, double value) Sets the default value for the double-valued preference with the given name.void
setDefault
(String name, float value) Sets the default value for the float-valued preference with the given name.void
setDefault
(String name, int value) Sets the default value for the integer-valued preference with the given name.void
setDefault
(String name, long value) Sets the default value for the long-valued preference with the given name.void
setDefault
(String name, String defaultObject) Sets the default value for the string-valued preference with the given name.void
setSearchContexts
(IScopeContext[] scopes) Set the search contexts to scopes.void
setToDefault
(String name) Sets the current value of the preference with the given name back to its default value.void
Sets the current value of the boolean-valued preference with the given name.void
Sets the current value of the double-valued preference with the given name.void
Sets the current value of the float-valued preference with the given name.void
Sets the current value of the integer-valued preference with the given name.void
Sets the current value of the long-valued preference with the given name.void
Sets the current value of the string-valued preference with the given name.Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
Field Details
-
silentRunning
protected boolean silentRunningA boolean to indicate the property changes should not be propagated.
-
-
Constructor Details
-
ScopedPreferenceStore
Create a new instance of the receiver. Store the values in context in the node looked up by qualifier. NOTE: Any instance of ScopedPreferenceStore should call- Parameters:
context
- the scope to store toqualifier
- the qualifier used to look up the preference nodedefaultQualifierPath
- the qualifier used when looking up the defaults
-
ScopedPreferenceStore
Create a new instance of the receiver. Store the values in context in the node looked up by qualifier.- Parameters:
context
- the scope to store toqualifier
- the qualifer used to look up the preference node
-
-
Method Details
-
addPropertyChangeListener
Description copied from interface:IPreferenceStore
Adds 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:
addPropertyChangeListener
in 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)
-
getPreferenceNodes
Return the preference path to search preferences on. This is the list of preference nodes based on the scope contexts for this store. If there are no search contexts set, then return this store's context.Whether or not the default context should be included in the resulting list is specified by the
includeDefault
parameter.- Parameters:
includeDefault
-true
if the default context should be included andfalse
otherwise- Returns:
- IEclipsePreferences[]
- Since:
- 3.4 public, was added in 3.1 as private method
-
setSearchContexts
Set the search contexts to scopes. When searching for a value the seach will be done in the order of scope contexts and will not search the storeContext unless it is in this list.If the given list is
null
, then clear this store's search contexts. This means that only this store's scope context and default scope will be used during preference value searching.The defaultContext will be added to the end of this list automatically and MUST NOT be included by the user.
- Parameters:
scopes
- a list of scope contexts to use when searching, ornull
-
contains
Description copied from interface:IPreferenceStore
Returns whether the named preference is known to this preference store.- Specified by:
contains
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
true
if either a current value or a default value is known for the named preference, andfalse
otherwise
-
firePropertyChangeEvent
Description copied from interface:IPreferenceStore
Fires 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
setValue
andsetToDefault
report such events in due course. Implementations should funnel all preference changes through this method.- Specified by:
firePropertyChangeEvent
in 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
Description copied from interface:IPreferenceStore
Returns 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:
getBoolean
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the boolean-valued preference
-
getDefaultBoolean
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultBoolean
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultDouble
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultDouble
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultFloat
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultFloat
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultInt
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultInt
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultLong
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultLong
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDefaultString
Description copied from interface:IPreferenceStore
Returns 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:
getDefaultString
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the default value of the named preference
-
getDouble
Description copied from interface:IPreferenceStore
Returns 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:
getDouble
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the double-valued preference
-
getFloat
Description copied from interface:IPreferenceStore
Returns 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:
getFloat
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the float-valued preference
-
getInt
Description copied from interface:IPreferenceStore
Returns 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:
getInt
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the int-valued preference
-
getLong
Description copied from interface:IPreferenceStore
Returns 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:
getLong
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the long-valued preference
-
getString
Description copied from interface:IPreferenceStore
Returns 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:
getString
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
- the string-valued preference
-
isDefault
Description copied from interface:IPreferenceStore
Returns whether the current value of the preference with the given name has the default value.- Specified by:
isDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference- Returns:
true
if the preference has a known default value and its current value is the same, andfalse
otherwise (including the case where the preference is unknown to this store)
-
needsSaving
public boolean needsSaving()Description copied from interface:IPreferenceStore
Returns whether the current values in this property store require saving.- Specified by:
needsSaving
in interfaceIPreferenceStore
- Returns:
true
if at least one of values of the preferences known to this store has changed and requires saving, andfalse
otherwise.
-
putValue
Description copied from interface:IPreferenceStore
Sets 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:
putValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
removePropertyChangeListener
Description copied from interface:IPreferenceStore
Removes the given listener from this preference store. Has no effect if the listener is not registered.- Specified by:
removePropertyChangeListener
in interfaceIPreferenceStore
- Parameters:
listener
- a property change listener, must not benull
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new default value for the preference
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new default value for the preference
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new default value for the preference
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new default value for the preference
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencedefaultObject
- the new default value for the preference
-
setDefault
Description copied from interface:IPreferenceStore
Sets 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:
setDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new default value for the preference
-
setToDefault
Description copied from interface:IPreferenceStore
Sets 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:
setToDefault
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
setValue
Description copied from interface:IPreferenceStore
Sets 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:
setValue
in interfaceIPreferenceStore
- Parameters:
name
- the name of the preferencevalue
- the new current value of the preference
-
save
Description copied from interface:IPersistentPreferenceStore
Saves the non-default-valued preferences known to this preference store to the file from which they were originally loaded.- Specified by:
save
in interfaceIPersistentPreferenceStore
- Throws:
IOException
- if there is a problem saving this store
-