Eclipse Preference scope

Preference是Eclipse平台内置支持的几种持久化(记忆先前的状态)的机制中的一种(其它的还有DialogSettings,IMemento)。本篇主要针对Preference的Scope(范围)进行总结。

Preference持久化文件的后缀为".prefs"。

The Eclipse runtime defines three so-called scopes. The scope defines how the preference data is stored and how it is changeable.

Table 1. Eclipse Preference scope(Table1来自Lars Vogel的博客)

ScopeDescription
Instance scopeIf the user runs the same program twice, the settings between the two programs may be different.
Configuration scopeIf the user runs the same program twice then the settings between the two programs are the same.
Default scopeDefault values which can not be changed. Supplied via configuration files in plug-ins and product definitions.  
下面通过一些比较浅显的注释以及源码分析来分别了解一下各个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 byorg.eclipse.core.runtime.Platform#getInstanceLocation(). Preferences stored in this scope will not be available to other running instances of Eclipse。
instance scope按照工作空间或平台的运行实例存储的,每个运行实例所存储的值可能是不一样的,不同实例之间只使用自己的值,无法与其它实例共享。
存储位置位于运行实例的如下位置:{workspace_path}\.metadata\.plugins\org.eclipse.core.runtime\.settings\{qualifier}.prefs
这点,我们可以通过阅读下面几个类去分析一下,限于时间,在此不分析源码了。所涉及类如下:org.eclipse.core.internal.preferences.InstancePreferences
org.eclipse.core.internal.runtime.DataArea
org.eclipse.core.internal.preferences.EclipsePreferences

configuration scope -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 byorg.eclipse.core.runtime.Platform#getConfigurationLocation()
configuration scope 各个工作空间将共享它们。例如,如果用户具有平台的单个安装,但是运行几个不同的工作空间,则配置级别范围的首选项将在工作空间之间共享。
存储位置位于程序安装目录的如下位置:{configuration}\.settings\{qualifier}.prefs

Default scope表示首选项的缺省值。它们不是由平台更改或存储的。但是,这些值来源于随插件的产品或主要功能部件一起存储的文件。

另外,常用的Scope还有一个是project Scope,针对特定工程的设置,存储位置位于
{project_path}\.settings\{qualifier}.prefs

这几个Scope在eclipse中均有相应的类对应,分别为:InstanceScope,ConfigurationScope,DefaultScope,ProjectScope。
在后续的博文中,将提及这些Scope的应用。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值