Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method
Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method [message #308132] Wed, 13 September 2006 22:50 Go to next message
Eclipse UserFriend
Originally posted by: bnegrao.gmail.com

Hi guys, when I'm using the Preferences in Eclipse i found an odd
behaviour.

If I try to set a preference in the ConfigurationScope() to a value that
is the default value set in the DefaultScope() of that preference, the
method setValue(String, String) of the ScopedPreferenceStore class will
silently remove the preference key from the ConfigurationScope() store!
What obligates me to retrieve the value from the DefaultScope() preference.

Does someone out there understand why this is being accomplished this way?

Bellow is the source of the mentioned method:

/*
* (non-Javadoc)
*
* @see
org.eclipse.jface.preference.IPreferenceStore#setValue(java. lang.String,
* java.lang.String)
*/
public void setValue(String name, String value) {
// Do not turn on silent running here as Strings are propagated
if (getDefaultString(name).equals(value)) {
getStorePreferences().remove(name); <==HERE! REMOVING MY PREF!
} else {
getStorePreferences().put(name, value);
}
dirty = true;
}

Thank you,
bruno.
Re: Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method [message #308142 is a reply to message #308132] Thu, 14 September 2006 08:44 Go to previous messageGo to next message
Eclipse UserFriend
Bruno Negrao wrote:
> Hi guys, when I'm using the Preferences in Eclipse i found an odd
> behaviour.
>
> If I try to set a preference in the ConfigurationScope() to a value that
> is the default value set in the DefaultScope() of that preference, the
> method setValue(String, String) of the ScopedPreferenceStore class will
> silently remove the preference key from the ConfigurationScope() store!
> What obligates me to retrieve the value from the DefaultScope() preference.
>
> Does someone out there understand why this is being accomplished this way?

Except doesn't the ConfigurationScope getValue() check itself and then
delegate to the default store if it can't find anything?

Later,
PW
Re: Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method [message #308167 is a reply to message #308132] Thu, 14 September 2006 19:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bnegrao.gmail.com

> public void setValue(String name, String value) {
> // Do not turn on silent running here as Strings are propagated
> if (getDefaultString(name).equals(value)) {
> getStorePreferences().remove(name); <==HERE! REMOVING MY PREF!
> } else {
> getStorePreferences().put(name, value);
> }
> dirty = true;
> }
This is awkward. The "getStorePreferences().remove(name)" above fires a
preference change event (see the source of the remove() method) stating
that the new value for that preference is "null"!!. This cheats all my
preference change listeners, saying that the new value for that preference
is null, when actually the user set the value back to its default.
ggrrrrr!!!!

public void remove(String key) {
String oldValue = properties.get(key);
if (oldValue == null)
return;
properties = properties.removeKey(key);
makeDirty();
firePreferenceEvent(key, oldValue, null);
}
Re: Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method [message #308186 is a reply to message #308167] Fri, 15 September 2006 08:34 Go to previous messageGo to next message
Eclipse UserFriend
If you know you are setting it to the default value (i.e. on a reset),
call setToDefault(*).

But you might want to open a bug about this at
https://bugs.eclipse.org/bugs/ against Platform UI.

Calling setValue(a, b) should never fire an event where the "new" value
is null.

Later,
PW
Re: Crazy behaviour in ScopedPreferenceStore.setValue(string, string) method [message #308205 is a reply to message #308186] Fri, 15 September 2006 19:28 Go to previous message
Eclipse UserFriend
Originally posted by: bnegrao.gmail.com

Thanks Paul.

the bug is on https://bugs.eclipse.org/bugs/show_bug.cgi?id=157539
Previous Topic:PDE generateFeature Ant task
Next Topic:How would invoke my action when a resource in the workspace is double-clicked on?
Goto Forum:
  


Current Time: Sat Jul 19 02:18:50 EDT 2025

Powered by FUDForum. Page generated in 0.10418 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top