Interface IPreferencesService
The default-default preference search look-up order as defined by the platform is: project, instance, configuration, default.
This interface is not intended to be implemented by clients.
- Since:
- 3.0
- Restriction:
- This interface is not intended to be implemented by clients.
- Restriction:
- This interface is not intended to be extended by clients.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyPreferences
(IEclipsePreferences node, IPreferenceFilter[] filters) Apply the preference tree rooted at the given node, to the system's preference tree.applyPreferences
(IExportedPreferences preferences) Take the given preference tree and apply it to the Eclipse global preference hierarchy.exportPreferences
(IEclipsePreferences node, OutputStream output, String[] excludesList) Exports all preferences for the given preference node and all its children to the specified output stream.void
exportPreferences
(IEclipsePreferences node, IPreferenceFilter[] filters, OutputStream output) Export the preference tree rooted at the given node, to the specified output stream.get
(String key, String defaultValue, Preferences[] nodes) Lookup the given key in the specified preference nodes in the given order.boolean
getBoolean
(String qualifier, String key, boolean defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.byte[]
getByteArray
(String qualifier, String key, byte[] defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.String[]
getDefaultLookupOrder
(String qualifier, String key) Return an array with the default lookup order for the preference keyed by the given qualifier and simple name.double
getDouble
(String qualifier, String key, double defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.float
getFloat
(String qualifier, String key, float defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.int
getInt
(String qualifier, String key, int defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.long
getLong
(String qualifier, String key, long defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.String[]
getLookupOrder
(String qualifier, String key) Return an array with the lookup order for the preference keyed by the given qualifier and simple name.Return the root node of the Eclipse preference hierarchy.getString
(String qualifier, String key, String defaultValue, IScopeContext[] contexts) Return the value stored in the preference store for the given key.importPreferences
(InputStream input) Loads preferences from the given file and stores them in the preferences store.matches
(IEclipsePreferences node, IPreferenceFilter[] filters) Return a list of filters which match the given tree and is a subset of the given filter list.readPreferences
(InputStream input) Read from the given input stream and create a node hierarchy representing the preferences and their values.void
setDefaultLookupOrder
(String qualifier, String key, String[] order) Set the default scope lookup order for the preference keyed by the given qualifier and simple name.
-
Method Details
-
get
Lookup the given key in the specified preference nodes in the given order. Return the value from the first node the key is found in. If the key is not defined in any of the given nodes, then return the specified default value.Immediately returns the default value if the node list is
null
. If any of the individual entries in the node list arenull
then skip over them and move on to the next node in the list.- Parameters:
key
- the preference keydefaultValue
- the default valuenodes
- the list of nodes to search, ornull
- Returns:
- the stored preference value or the specified default value
- See Also:
-
getBoolean
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getByteArray
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getDouble
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getFloat
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getInt
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getLong
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getString
Return the value stored in the preference store for the given key. If the key is not defined then return the specified default value. Use the canonical scope lookup order for finding the preference value.The semantics of this method are to calculate the appropriate
Preferences
nodes in the preference hierarchy to use and then call theget(String, String, Preferences[])
method. The order of the nodes is calculated by consulting the default scope lookup order as set bysetDefaultLookupOrder(String, String, String[])
.The specified key may either refer to a simple key or be the concatenation of the path of a child node and key. If the key contains a slash ("/") character, then a double-slash must be used to denote the end of they child path and the beginning of the key. Otherwise it is assumed that the key is the last segment of the path. The following are some examples of keys and their meanings:
- "a" - look for a value for the property "a"
- "//a" - look for a value for the property "a"
- "///a" - look for a value for the property "/a"
- "//a//b" - look for a value for the property "a//b"
- "a/b/c" - look in the child node "a/b" for property "c"
- "/a/b/c" - look in the child node "a/b" for property "c"
- "/a/b//c" - look in the child node "a/b" for the property "c"
- "a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c/d" - look in the child node "a/b" for the property "c/d"
- "/a/b//c//d" - look in the child node "a/b" for the property "c//d"
The scope look-up order is determined by the preference service default lookup order, not by the order of the scope contexts that are being passed in. The context objects are only consulted to help determine which nodes to look in, not the order of the nodes.
Callers may specify an array of scope context objects to aid in the determination of the correct nodes. For each entry in the lookup order, the array of contexts is consulted and if one matching the scope exists, then it is used to calculate the node. Otherwise a default calculation algorithm is used.
An example of a qualifier for an Eclipse 2.1 preference is the plug-in identifier. (e.g. "org.eclipse.core.resources" for "description.autobuild")
- Parameters:
qualifier
- a namespace qualifier for the preferencekey
- the name of the preference (optionally including its path)defaultValue
- the value to use if the preference is not definedcontexts
- optional context objects to help scopes determine which nodes to search, ornull
- Returns:
- the value of the preference or the given default value
- See Also:
-
getRootNode
IEclipsePreferences getRootNode()Return the root node of the Eclipse preference hierarchy.- Returns:
- the root of the hierarchy
-
exportPreferences
IStatus exportPreferences(IEclipsePreferences node, OutputStream output, String[] excludesList) throws CoreException Exports all preferences for the given preference node and all its children to the specified output stream. It is the responsibility of the client to close the given output stream.If the given export list is
null
then all preferences for all sub-nodes of the given node are exported to the given stream. Otherwise the export list is consulted before exporting each preference value. If there is a string match then the preference is not exported. The exclusion can also occur at a per-node level. Wild cards are not accepted in the excludes list as a basic String compare is done. The basic algorithm is similar to the following:String fullPath = node.absolutePath() + '/' + key; if (!fullPath.startsWith(excludesList[i])) // export preference
The values stored in the resulting stream are suitable for later being read by the by
importPreferences(InputStream)
orreadPreferences(InputStream)
methods.- Parameters:
node
- the node to treat as the root of the exportoutput
- the stream to write toexcludesList
- a list of path prefixes to exclude from the export, ornull
- Returns:
- a status object describing success or detailing failure reasons
- Throws:
CoreException
- if there was a problem exporting the preferencesIllegalArgumentException
- if the node or stream isnull
- See Also:
-
importPreferences
Loads preferences from the given file and stores them in the preferences store. Existing values are over-ridden by those from the stream. The stream must not benull
and is closed upon return from this method.This file must have been written by the
exportPreferences(IEclipsePreferences, OutputStream, String[])
method.This method is equivalent to calling
applyPreferences(readPreferences(input));
.- Parameters:
input
- the stream to load the preferences from- Returns:
- a status object describing success or detailing failure reasons
- Throws:
CoreException
- if there are problems importing the preferencesIllegalArgumentException
- if the stream isnull
- See Also:
-
applyPreferences
Take the given preference tree and apply it to the Eclipse global preference hierarchy. If a node is an export root, then treat the operation for that node as an overwrite rather than a merge. That is, remove the node from the global tree before adding any preferences contained in it or its children.The given preferences object must not be
null
.Before the tree is applied to the global preference tree, the registered
PreferenceModifyListener
objects are called and given the opportunity to modify the tree.- Parameters:
preferences
- the preferences to apply globally- Returns:
- status object indicating success or failure
- Throws:
IllegalArgumentException
- if the preferences arenull
CoreException
- if there are problems applying the preferences- See Also:
-
readPreferences
Read from the given input stream and create a node hierarchy representing the preferences and their values. The given input stream must not benull
. The result of this function is suitable for passing as an argument toapplyPreferences(IExportedPreferences)
.It is assumed the contents of the input stream have been written by
exportPreferences(IEclipsePreferences, OutputStream, String[])
.- Parameters:
input
- the input stream to read from- Returns:
- the node hierarchy representing the stream contents
- Throws:
IllegalArgumentException
- if the given stream is nullCoreException
- if there are problems reading the preferences- See Also:
-
getDefaultLookupOrder
Return an array with the default lookup order for the preference keyed by the given qualifier and simple name. Returnnull
if no default has been set.The lookup order returned is based on an exact match to the specified qualifier and simple name. For instance, if the given key is non-
null
and no default lookup order is found, the default lookup order for the qualifier (and anull
key) is NOT returned. Clients should callgetLookupOrder(String, String)
if they desire this behavior.- Parameters:
qualifier
- the namespace qualifier for the preferencekey
- the preference name ornull
- Returns:
- the scope order or
null
- See Also:
-
getLookupOrder
Return an array with the lookup order for the preference keyed by the given qualifier and simple name.First do an exact match lookup with the given qualifier and simple name. If a match is found then return it. Otherwise if the key is non-
null
then do a lookup based on only the qualifier and return the set value. Return the default-default order as defined by the platform if no order has been set.- Parameters:
qualifier
- the namespace qualifier for the preferencekey
- the preference name ornull
- Returns:
- the scope order
- Throws:
IllegalArgumentException
- if the qualifier isnull
- See Also:
-
setDefaultLookupOrder
Set the default scope lookup order for the preference keyed by the given qualifier and simple name. If the given order isnull
then the set ordering (if it exists) is removed.If the given simple name is
null
then set the given lookup order to be used for all keys with the given qualifier.Note that the default lookup order is not persisted across platform invocations.
- Parameters:
qualifier
- the namespace qualifier for the preferencekey
- the preference name ornull
order
- the lookup order ornull
- Throws:
IllegalArgumentException
-- if the qualifier is
null
- if an entry in the order array is
null
(the array itself is allowed to benull
- if the qualifier is
- See Also:
-
exportPreferences
void exportPreferences(IEclipsePreferences node, IPreferenceFilter[] filters, OutputStream output) throws CoreException Export the preference tree rooted at the given node, to the specified output stream. Apply the given list of preference filters, only exporting preference node and keys which are applicable to at least one filter in the list.The given node and output stream must not be
null
. If the list of filters isnull
or empty then do nothing.It is the responsibility of the client to close the given output stream.
- Parameters:
node
- the tree to exportfilters
- the list of filters to exportoutput
- the stream to export to- Throws:
CoreException
- if there was a problem exporting the preferences- Since:
- 3.1
- See Also:
-
matches
IPreferenceFilter[] matches(IEclipsePreferences node, IPreferenceFilter[] filters) throws CoreException Return a list of filters which match the given tree and is a subset of the given filter list. If the specified list of filters isnull
, empty, or there are no matches, then return an empty list.- Parameters:
node
- the tree to match againstfilters
- the list of filters to match against- Returns:
- the array of matching transfers
- Throws:
CoreException
- if there are problems during matching- Since:
- 3.1
- See Also:
-
applyPreferences
Apply the preference tree rooted at the given node, to the system's preference tree. The list of preference filters will act as a filter and only preferences in the tree which apply to at least one filter in the list, will be applied.If the list of filters is
null
or empty then do nothing.Before the tree is applied to the global preference tree, the registered
PreferenceModifyListener
objects are called and given the opportunity to modify the tree.- Parameters:
node
- the tree to consider applyingfilters
- the filters to use- Throws:
CoreException
- if there are problems applying the preferences- Since:
- 3.1
- See Also:
-