【问题标题】:Get preference store of a plugin获取插件的偏好存储
【发布时间】:2017-04-13 08:02:42
【问题描述】:

我有 2 个插件可以说

Plugin A 
Plugin B

插件 A 依赖于插件 B 并且 A 有 Preference Page

在插件 B 中,我也想拥有 A 的偏好存储

当我打电话时

IPreferenceStore store = Activator.getDefault().getPreferenceStore();

从插件 B 获取 A 的存储,我检测到循环,因为 A 依赖于 B 并且 B 也依赖于 A 来获取偏好存储

有什么方法可以在插件 B 中获取 A 的偏好存储?

【问题讨论】:

    标签: java eclipse eclipse-plugin eclipse-rcp


    【解决方案1】:

    你可以使用

    IPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "plugin id");
    

    在不引用插件代码的情况下获取插件的首选项存储。

    【讨论】:

    • 为什么preferenceStore 依赖于eclipse.ui 类?这太废话了!我正在尝试隔离我的插件依赖项,并且我必须包含所有 eclise.ui 才能访问 PLUGIN 的preferenceStore?天哪……
    • @marcolopes 我不是 Eclipse 设计师,所以我无法回答这个问题。在 Eclipse 中实际上有两个级别的首选项,org.eclipse.core.runtime.preferences 中的较低级别,org.eclipse.ui.preferences 中的较高级别。对于某些事情,可以只使用org.eclipse.core.runtime.preferences 级别。
    • 谢谢! org.eclipse.core.runtime.Preferences 已完全弃用,甚至无法正常工作... :\ 奇怪的是我必须扩展 AbstractUIPlugin 才能访问 IPreferenceStore...
    • @marcolopes 我在想像 org.eclipse.core.runtime.preferences.InstanceScope 和 org.eclipse.core.runtime.preferences.IEclipsePreferences 之类的东西
    • 哦,我明白了!我调查了这些类并为没有 UI 依赖项的值实现了一个新的 preferenceStore!非常感谢!
    猜你喜欢
    • 2010-11-22
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    相关资源
    最近更新 更多