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] Wed, 12 August 2009 22:22
Hiroki Kondo is currently offline Hiroki Kondo
Messages: 35
Registered: July 2009
Member
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[]{
projectScope,
instanceScope,
});

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;
}

@Override
public void setValue(String name, boolean value) {
boolean oldValue = getBoolean(name);
if (oldValue == value) {
return;
}
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: Tue Jul 29 17:07:17 EDT 2014

Powered by FUDForum. Page generated in 0.02174 seconds