Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "FAQ How do I load and save plug-in preferences?"
(→Current Practice) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Current Practice == | == Current Practice == | ||
− | |||
− | + | As of 3.1 the technique to modify preference values goes something like this: | |
private void savePluginSettings() { | private void savePluginSettings() { | ||
// saves plugin preferences at the workspace level | // saves plugin preferences at the workspace level | ||
− | Preferences prefs = | + | Preferences prefs = |
+ | InstanceScope.INSTANCE.getNode(MY_PLUGIN_ID); // does all the above behind the scenes | ||
prefs.put(KEY1, this.someStr); | prefs.put(KEY1, this.someStr); | ||
Line 46: | Line 21: | ||
private void loadPluginSettings() { | private void loadPluginSettings() { | ||
− | Preferences prefs = | + | Preferences prefs = new InstanceScope().getNode(MY_PLUGIN_ID); |
// you might want to call prefs.sync() if you're worried about others changing your settings | // you might want to call prefs.sync() if you're worried about others changing your settings | ||
this.someStr = prefs.get(KEY1); | this.someStr = prefs.get(KEY1); | ||
this.someBool= prefs.getBoolean(KEY2); | this.someBool= prefs.getBoolean(KEY2); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== See Also: == | == See Also: == | ||
*[[FAQ How do I use the preference service?]] | *[[FAQ How do I use the preference service?]] | ||
− | + | *[[FAQ What is a preference scope?]] | |
{{Template:FAQ_Tagline}} | {{Template:FAQ_Tagline}} |
Latest revision as of 05:53, 12 November 2014
Current Practice
As of 3.1 the technique to modify preference values goes something like this:
private void savePluginSettings() { // saves plugin preferences at the workspace level Preferences prefs = InstanceScope.INSTANCE.getNode(MY_PLUGIN_ID); // does all the above behind the scenes prefs.put(KEY1, this.someStr); prefs.put(KEY2, this.someBool); try { // prefs are automatically flushed during a plugin's "super.stop()". prefs.flush(); } catch(BackingStoreException e) { //TODO write a real exception handler. e.printStackTrace(); } } private void loadPluginSettings() { Preferences prefs = new InstanceScope().getNode(MY_PLUGIN_ID); // you might want to call prefs.sync() if you're worried about others changing your settings this.someStr = prefs.get(KEY1); this.someBool= prefs.getBoolean(KEY2); }
See Also:
This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.