Reputation: 809
I have trouble getting preference loaded on to eclipse. I am not able to load the value for the preference without going to the preference page first. I start eclipse, use my plugin, i see that the feature is not enabled. I start eclipse, go to preference page and the use my plugin, all works fine.
I am trying to access the value for enable from preference store using the below code
final IPreferenceStore preferences = new ScopedPreferenceStore(new InstanceScope(), <my plugin id>);
this.enabled = preferences.getBoolean(<templateName>_ENABLE_TEMPLATE"));
this call goes to method
public boolean getBoolean(String name) {
String value = internalGet(name);
return value == null ? BOOLEAN_DEFAULT_DEFAULT : Boolean.valueOf(value)
.booleanValue();
}
internalGet(name) -- returns null..as a result this.enabled
is set to false
.
in my code i check this variable and if it is false i display an error message and don't proceed further.
I want to know how we can make sure that the preferences are enabled/loaded as soon as they are invoked.
Thanks in advance!!
Upvotes: 0
Views: 651
Reputation: 3621
Preferences service is initialized when org.eclipse.core.runtime
plugin is activated, meaning that it is virtually impossible for your code to access it in uninitialized state. The reason for not getting the value of a preference is that the value has not been set.
It is also possible to specify defaults for all your preferences using preferences.ini file (should be placed in the plugin/bundle root).
Upvotes: 1