Eclipse Preference Scope
INSTANCE - The instance scope can also be thought of as "workspace". That is, the preferences which are stored in this scope are stored per workspace, or per running instance of Eclipse. This scope corresponds to the default location of preferences in Eclipse 2.1. The instance area is derived from the location returned by org.eclipse.core.runtime.Platform#getInstanceLocation(). Preferences stored in this scope will not be available to other running instances of Eclipse.
CONFIGURATION - The configuration scope is used to store preferences on a per configuration level. Being able store preferences per configuration means that all workspaces share the same preferences. For instance, if you are an Eclipse developer and you have a single Eclipse install but you have multiple workspaces for different projects/branches that you are working on, the preferences stored in the configuration scope will be shared between these workspaces. The configuration area is derived from the location returned by org.eclipse.core.runtime.Platform#getConfigurationLocation().
DEFAULT - The default preference scope was initially created to provide a backwards compatibility story for the plug-in customization code in Eclipse 2.1. Preferences stored in the default scope are not persisted to disk and are a part of the plug-in customization story.
PROJECT - There was a request for per project preferences so the project scope handles this. Preferences which are stored in this scope are shared stored in the project content area and are therefore automatically shared with the repository. This enables items like java compiler settings to be shared between team members working on the same project.
INSTANCE and CONFIGURATION are used in most situations.
Store data in Preference:
INSTANCE
...
Preferences preferences = new InstanceScope().getNode("foo.bar.MyPlugin");
preferences.put("key", "value");
try {
preferences.flush();
} catch (BackingStoreException e) {
e.printStackTrace();
}
...
CONFIGURATION
Preferences preferences = new ConfigurationScope().getNode("foo.bar.MyPlugin");
preferences.put("key", "value");
try {
preferences.flush();
} catch (BackingStoreException e) {
e.printStackTrace();
}
...
Load data in Preference:
preferences.get("key", "");
本文深入解析Eclipse Preference Scope的四种类型:实例、配置、默认和项目级别,详细说明如何存储和加载偏好设置,并提供实例代码。适合Eclipse开发者了解如何高效管理应用的配置。
2174

被折叠的 条评论
为什么被折叠?



