public class ChainedPreferenceStore extends Object implements IPreferenceStore
This preference store is read-only i.e. write access
throws an UnsupportedOperationException
.
BOOLEAN_DEFAULT_DEFAULT, DOUBLE_DEFAULT_DEFAULT, FALSE, FLOAT_DEFAULT_DEFAULT, INT_DEFAULT_DEFAULT, LONG_DEFAULT_DEFAULT, STRING_DEFAULT_DEFAULT, TRUE
Constructor and Description |
---|
ChainedPreferenceStore(IPreferenceStore[] preferenceStores)
Sets the chained preference stores.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(IPropertyChangeListener listener)
Adds a property change listener to this preference store.
|
boolean |
contains(String name)
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.
|
String |
getDefaultString(String name)
Returns the default value for the string-valued preference
with the given name.
|
double |
getDouble(String name)
Returns the current value of the double-valued preference with the
given name.
|
float |
getFloat(String name)
Returns the current value of the float-valued preference with the
given name.
|
int |
getInt(String name)
Returns the current value of the integer-valued preference with the given
name.
|
long |
getLong(String name)
Returns the current value of the long-valued preference with the
given name.
|
String |
getString(String name)
Returns the current value of the string-valued preference with the
given name.
|
boolean |
isDefault(String name)
Returns whether the current value of the preference with the given name
has the default value.
|
boolean |
needsSaving()
Returns whether the current values in this property store
require saving.
|
void |
putValue(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.
|
void |
removePropertyChangeListener(IPropertyChangeListener listener)
Removes the given listener from this preference store.
|
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 |
setToDefault(String name)
Sets the current value of the preference with the given name back
to its default value.
|
void |
setValue(String name,
boolean value)
Sets the current value of the boolean-valued preference with the
given name.
|
void |
setValue(String name,
double value)
Sets the current value of the double-valued preference with the
given name.
|
void |
setValue(String name,
float value)
Sets the current value of the float-valued preference with the
given name.
|
void |
setValue(String name,
int value)
Sets the current value of the integer-valued preference with the
given name.
|
void |
setValue(String name,
long value)
Sets the current value of the long-valued preference with the
given name.
|
void |
setValue(String name,
String value)
Sets the current value of the string-valued preference with the
given name.
|
public ChainedPreferenceStore(IPreferenceStore[] preferenceStores)
preferenceStores
- the chained preference stores to setpublic void addPropertyChangeListener(IPropertyChangeListener listener)
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.
addPropertyChangeListener
in interface IPreferenceStore
listener
- a property change listenerPropertyChangeEvent
,
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)
public void removePropertyChangeListener(IPropertyChangeListener listener)
IPreferenceStore
removePropertyChangeListener
in interface IPreferenceStore
listener
- a property change listener, must not be null
public boolean contains(String name)
IPreferenceStore
contains
in interface IPreferenceStore
name
- the name of the preferencetrue
if either a current value or a default
value is known for the named preference, and false
otherwisepublic void firePropertyChangeEvent(String name, Object oldValue, Object newValue)
IPreferenceStore
This method is provided on this interface to simplify the implementation
of decorators. There is normally no need to call this method since
setValue
and setToDefault
report such
events in due course. Implementations should funnel all preference
changes through this method.
firePropertyChangeEvent
in interface IPreferenceStore
name
- the name of the preference, to be used as the property
in the event objectoldValue
- the old valuenewValue
- the new valuepublic boolean getBoolean(String name)
IPreferenceStore
false
) if there
is no preference with the given name, or if the current value
cannot be treated as a boolean.getBoolean
in interface IPreferenceStore
name
- the name of the preferencepublic boolean getDefaultBoolean(String name)
IPreferenceStore
false
) if there
is no default preference with the given name, or if the default
value cannot be treated as a boolean.getDefaultBoolean
in interface IPreferenceStore
name
- the name of the preferencepublic double getDefaultDouble(String name)
IPreferenceStore
0.0
) if there
is no default preference with the given name, or if the default
value cannot be treated as a double.getDefaultDouble
in interface IPreferenceStore
name
- the name of the preferencepublic float getDefaultFloat(String name)
IPreferenceStore
0.0f
) if there
is no default preference with the given name, or if the default
value cannot be treated as a float.getDefaultFloat
in interface IPreferenceStore
name
- the name of the preferencepublic int getDefaultInt(String name)
IPreferenceStore
0
) if there
is no default preference with the given name, or if the default
value cannot be treated as an integer.getDefaultInt
in interface IPreferenceStore
name
- the name of the preferencepublic long getDefaultLong(String name)
IPreferenceStore
0L
) if there
is no default preference with the given name, or if the default
value cannot be treated as a long.getDefaultLong
in interface IPreferenceStore
name
- the name of the preferencepublic String getDefaultString(String name)
IPreferenceStore
""
)
is no default preference with the given name, or if the default
value cannot be treated as a string.getDefaultString
in interface IPreferenceStore
name
- the name of the preferencepublic double getDouble(String name)
IPreferenceStore
0.0
) if there
is no preference with the given name, or if the current value
cannot be treated as a double.getDouble
in interface IPreferenceStore
name
- the name of the preferencepublic float getFloat(String name)
IPreferenceStore
0.0f
) if there
is no preference with the given name, or if the current value
cannot be treated as a float.getFloat
in interface IPreferenceStore
name
- the name of the preferencepublic int getInt(String name)
IPreferenceStore
0
) if there is no
preference with the given name, or if the current value cannot be treated
as an integer.getInt
in interface IPreferenceStore
name
- the name of the preferencepublic long getLong(String name)
IPreferenceStore
0L
) if there
is no preference with the given name, or if the current value
cannot be treated as a long.getLong
in interface IPreferenceStore
name
- the name of the preferencepublic String getString(String name)
IPreferenceStore
""
)
if there is no preference with the given name, or if the current value
cannot be treated as a string.getString
in interface IPreferenceStore
name
- the name of the preferencepublic boolean isDefault(String name)
IPreferenceStore
isDefault
in interface IPreferenceStore
name
- the name of the preferencetrue
if the preference has a known default value
and its current value is the same, and false
otherwise
(including the case where the preference is unknown to this store)public boolean needsSaving()
IPreferenceStore
needsSaving
in interface IPreferenceStore
true
if at least one of values of
the preferences known to this store has changed and
requires saving, and false
otherwise.public void putValue(String name, String value)
IPreferenceStore
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.
putValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setDefault(String name, double value)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new default value for the preferencepublic void setDefault(String name, float value)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new default value for the preferencepublic void setDefault(String name, int value)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new default value for the preferencepublic void setDefault(String name, long value)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new default value for the preferencepublic void setDefault(String name, String defaultObject)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencedefaultObject
- the new default value for the preferencepublic void setDefault(String name, boolean value)
IPreferenceStore
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.
setDefault
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new default value for the preferencepublic void setToDefault(String name)
IPreferenceStore
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.
setToDefault
in interface IPreferenceStore
name
- the name of the preferencepublic void setValue(String name, double value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setValue(String name, float value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setValue(String name, int value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setValue(String name, long value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setValue(String name, String value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preferencepublic void setValue(String name, boolean value)
IPreferenceStore
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
.
setValue
in interface IPreferenceStore
name
- the name of the preferencevalue
- the new current value of the preference
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.