Eclipse Preference Scope

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", "");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值