Home » Eclipse Projects » Eclipse Platform » 3.x Preference Scopes and Nodes Confusion
3.x Preference Scopes and Nodes Confusion [message #284212] |
Tue, 19 April 2005 16:06  |
Eclipse User |
|
|
|
Originally posted by: mark_melvin.amis.com
Hi All,
I have been messing about with scoped preferences in 3.1M6, and I find
them to be very cool, but I have a point I am confused on, and I need
some help.
I am writing a whole whack of preferences to a ProjectScope-based
preference, let's call it "myprefs", in project "MyProject". What this
does is create a file in my project (as expected and desired) called
MyProject/.settings/myprefs.prefs
One of my use cases dictates that I delete all preferences defined in
this particular node, and replace them with a new set. So, what I am
doing is something like the following:
// "project" is a reference to MyProject
IScopeContext context = new ProjectScope(project);
// Get rid of all existing preferences
IEclipsePreferences baseNode = context.getNode("myprefs");
Preferences parent = baseNode.parent();
baseNode.removeNode();
// Flush to make removal permanent
if (parent != null) {
parent.flush();
}
This *seems* to work, as accessing any preferences seems to fail,
however - what I am seeing is that I still have the file
"MyProject/.settings/myprefs.prefs" sitting in my project, full of
preferences. How can I make the preferences framework delete this file?
I basically want a brute force method of clearing all preferences in a
node (including the file in which they are persisted), without
necessarily knowing all of the children in that node. Otherwise, this
file gradually accumulates cruft. What am I doing wrong here?
Mark.
|
|
|
Re: 3.x Preference Scopes and Nodes Confusion [message #284219 is a reply to message #284212] |
Tue, 19 April 2005 16:39   |
Eclipse User |
|
|
|
Originally posted by: mark_melvin.amis.com
Answering my own question - this seems to do what I want... I guess
this is the way to go about it?
IEclipsePreferences baseNode = context.getNode("myprefs");
try {
removePreferenceNode(baseNode);
} catch ...
public static void removePreferenceNode(Preferences node) throws
BackingStoreException {
String[] children = node.childrenNames();
// Remove all keys in this node
node.clear();
// Now remove all children nodes
for (int i = 0; i < children.length; i++) {
node.node(children[i]).removeNode();
}
// Persist to backing store
node.flush();
}
Mark Melvin wrote:
> Hi All,
>
> I have been messing about with scoped preferences in 3.1M6, and I find
> them to be very cool, but I have a point I am confused on, and I need
> some help.
>
> I am writing a whole whack of preferences to a ProjectScope-based
> preference, let's call it "myprefs", in project "MyProject". What this
> does is create a file in my project (as expected and desired) called
>
> MyProject/.settings/myprefs.prefs
>
> One of my use cases dictates that I delete all preferences defined in
> this particular node, and replace them with a new set. So, what I am
> doing is something like the following:
>
> // "project" is a reference to MyProject
> IScopeContext context = new ProjectScope(project);
> // Get rid of all existing preferences
> IEclipsePreferences baseNode = context.getNode("myprefs");
> Preferences parent = baseNode.parent();
> baseNode.removeNode();
> // Flush to make removal permanent
> if (parent != null) {
> parent.flush();
> }
>
> This *seems* to work, as accessing any preferences seems to fail,
> however - what I am seeing is that I still have the file
> "MyProject/.settings/myprefs.prefs" sitting in my project, full of
> preferences. How can I make the preferences framework delete this file?
> I basically want a brute force method of clearing all preferences in a
> node (including the file in which they are persisted), without
> necessarily knowing all of the children in that node. Otherwise, this
> file gradually accumulates cruft. What am I doing wrong here?
>
> Mark.
|
|
|
Re: 3.x Preference Scopes and Nodes Confusion [message #284302 is a reply to message #284219] |
Wed, 20 April 2005 14:08   |
Eclipse User |
|
|
|
Originally posted by: dj_houghton.nospam.ca.ibm.com
Hmm...smells like a bug. Entered bug 92123.
Mark Melvin wrote:
> Answering my own question - this seems to do what I want... I guess
> this is the way to go about it?
>
> IEclipsePreferences baseNode = context.getNode("myprefs");
> try {
> removePreferenceNode(baseNode);
> } catch ...
>
>
> public static void removePreferenceNode(Preferences node) throws
> BackingStoreException {
> String[] children = node.childrenNames();
> // Remove all keys in this node
> node.clear();
> // Now remove all children nodes
> for (int i = 0; i < children.length; i++) {
> node.node(children[i]).removeNode();
> }
> // Persist to backing store
> node.flush();
> }
>
> Mark Melvin wrote:
>
>> Hi All,
>>
>> I have been messing about with scoped preferences in 3.1M6, and I find
>> them to be very cool, but I have a point I am confused on, and I need
>> some help.
>>
>> I am writing a whole whack of preferences to a ProjectScope-based
>> preference, let's call it "myprefs", in project "MyProject". What
>> this does is create a file in my project (as expected and desired) called
>>
>> MyProject/.settings/myprefs.prefs
>>
>> One of my use cases dictates that I delete all preferences defined in
>> this particular node, and replace them with a new set. So, what I am
>> doing is something like the following:
>>
>> // "project" is a reference to MyProject
>> IScopeContext context = new ProjectScope(project);
>> // Get rid of all existing preferences
>> IEclipsePreferences baseNode = context.getNode("myprefs");
>> Preferences parent = baseNode.parent();
>> baseNode.removeNode();
>> // Flush to make removal permanent
>> if (parent != null) {
>> parent.flush();
>> }
>>
>> This *seems* to work, as accessing any preferences seems to fail,
>> however - what I am seeing is that I still have the file
>> "MyProject/.settings/myprefs.prefs" sitting in my project, full of
>> preferences. How can I make the preferences framework delete this
>> file? I basically want a brute force method of clearing all
>> preferences in a node (including the file in which they are
>> persisted), without necessarily knowing all of the children in that
>> node. Otherwise, this file gradually accumulates cruft. What am I
>> doing wrong here?
>>
>> Mark.
|
|
|
Re: 3.x Preference Scopes and Nodes Confusion [message #284341 is a reply to message #284302] |
Thu, 21 April 2005 09:56  |
Eclipse User |
|
|
|
Originally posted by: mark_melvin.amis.com
Ah, I wasn't sure if this was desired behaviour or not. I guess I
should have just opened the bug anyway - so thanks for doing it for me...
...adding myself on CC list.
Thanks,
Mark.
DJ Houghton wrote:
> Hmm...smells like a bug. Entered bug 92123.
>
> Mark Melvin wrote:
>
>> Answering my own question - this seems to do what I want... I guess
>> this is the way to go about it?
>>
>> IEclipsePreferences baseNode = context.getNode("myprefs");
>> try {
>> removePreferenceNode(baseNode);
>> } catch ...
>>
>>
>> public static void removePreferenceNode(Preferences node) throws
>> BackingStoreException {
>> String[] children = node.childrenNames();
>> // Remove all keys in this node
>> node.clear();
>> // Now remove all children nodes
>> for (int i = 0; i < children.length; i++) {
>> node.node(children[i]).removeNode();
>> }
>> // Persist to backing store
>> node.flush();
>> }
>>
>> Mark Melvin wrote:
>>
>>> Hi All,
>>>
>>> I have been messing about with scoped preferences in 3.1M6, and I
>>> find them to be very cool, but I have a point I am confused on, and I
>>> need some help.
>>>
>>> I am writing a whole whack of preferences to a ProjectScope-based
>>> preference, let's call it "myprefs", in project "MyProject". What
>>> this does is create a file in my project (as expected and desired)
>>> called
>>>
>>> MyProject/.settings/myprefs.prefs
>>>
>>> One of my use cases dictates that I delete all preferences defined in
>>> this particular node, and replace them with a new set. So, what I am
>>> doing is something like the following:
>>>
>>> // "project" is a reference to MyProject
>>> IScopeContext context = new ProjectScope(project);
>>> // Get rid of all existing preferences
>>> IEclipsePreferences baseNode = context.getNode("myprefs");
>>> Preferences parent = baseNode.parent();
>>> baseNode.removeNode();
>>> // Flush to make removal permanent
>>> if (parent != null) {
>>> parent.flush();
>>> }
>>>
>>> This *seems* to work, as accessing any preferences seems to fail,
>>> however - what I am seeing is that I still have the file
>>> "MyProject/.settings/myprefs.prefs" sitting in my project, full of
>>> preferences. How can I make the preferences framework delete this
>>> file? I basically want a brute force method of clearing all
>>> preferences in a node (including the file in which they are
>>> persisted), without necessarily knowing all of the children in that
>>> node. Otherwise, this file gradually accumulates cruft. What am I
>>> doing wrong here?
>>>
>>> Mark.
|
|
|
Goto Forum:
Current Time: Wed Jun 04 23:05:16 EDT 2025
Powered by FUDForum. Page generated in 0.02338 seconds
|