Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to override Boolean settings using ScopedPreferenceStore?
How to override Boolean settings using ScopedPreferenceStore? [message #479906] Thu, 13 August 2009 02:22
Hiroki Kondo is currently offline Hiroki KondoFriend
Messages: 47
Registered: July 2009
Hi all,

I'm using ScopedPreferenceStore to override the settings.
My application has 2 scopes,Project and Instance.(Of cause it has default
scope.) like this:
InstanceScope instanceScope = new InstanceScope();
ProjectScope projectScope = new ProjectScope(getProject());
ScopedPreferenceStore scopedPreferenceStore = new ScopedPreferenceStore
(projectScope, PLUGIN_ID);
scopedPreferenceStore.setSearchContexts(new IScopeContext[]{

I want to store 'false' value at this ScopedPreferenceStore.
But I can't.ScopedPreferenceStore returns 'true' when InstanceScope set 'true'.
Because 'false' is default value.
So ScopedPreferenceStore always store 'null' to project setting.
However,ScopedPreferenceStore#internalGet(Boolean_key) handles 'null' value is
continue search at lower layer(yes, this case is ScopedPreferenceStore searching
InstanceScope.So it returns 'true')

Is it a spec? I always implement subclass for override like this?
class EnabledOverrideScopedPreferenceStore extends
ScopedPreferenceStore {
private IScopeContext storeContext;
private String nodeQualifier;

private EnabledOverrideScopedPreferenceStore(
IScopeContext context,
String qualifier) {
super(context, qualifier);
this.storeContext = context;
this.nodeQualifier = qualifier;

public void setValue(String name, boolean value) {
boolean oldValue = getBoolean(name);
if (oldValue == value) {
try {
silentRunning = true;// Turn off updates from the store
overridePreference(name, value);
firePropertyChangeEvent(name, oldValue ? Boolean.TRUE
: Boolean.FALSE, value ? Boolean.TRUE : Boolean.FALSE);
} finally {
silentRunning = false;// Restart listening to preferences

private void overridePreference(String name, boolean value) {
storeContext.getNode(nodeQualifier).putBoolean(name, value);

Previous Topic:Converting an Action path into command path
Next Topic:Create Java Project using Ant build file
Goto Forum:

Current Time: Mon Jun 25 04:42:41 GMT 2018

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

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

Back to the top