1

在我的 Eclipse 3.7 RCP 应用程序中,我得到 PreferenceStore 如下: Activator.getDefault().getPreferenceStore()它返回一个IPreferenceStore. 这里使用了激活器自己的偏好存储。

现在我想使用一个实例,ScopedPreferenceStore它是一个IPreferenceStore
现在必须通过在构造函数中传递一个插件 ID 作为限定符参数来明确设置偏好存储节点ScopedPreferenceStore(IScopeContext context, String qualifier)

例子:
ScopedPreferenceStore(ConfigurationScope.INSTANCE, "com.example.myplugin.id")

问题:
如何获得 Activator 自己的偏好存储限定符?换句话说,我如何创建一个ScopedPreferenceStore将首选项存储在 Activator 自己的首选项存储中的?

4

1 回答 1

2

如果您想在不访问 Activator 本身的情况下为您的捆绑包获取等效的首选项存储,您将使用您列出的相同模式:

preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, "your.bundle.id");

编辑:查找您的捆绑包 ID

当 eclipse 自动生成你的 bundle 激活器时,它会创建一个带有 bundle id 的静态字段。但是,如果您没有激活器,您仍然可以检索您的捆绑包 ID。您可以使用从任何一个类FrameworkUtil中获取对象。Bundle

import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

final Bundle bundle = FrameworkUtil.getBundle(PrintIdHandler.class);
System.out.println(bundle.getSymbolicName());
于 2012-06-20T11:57:47.533 回答