Eclipse:OSGI首选项与PreferenceStore [英] Eclipse: OSGI Preferences vs. PreferenceStore

查看:201
本文介绍了Eclipse:OSGI首选项与PreferenceStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse插件(或实际上是一个基于Eclipse的应用程序的插件),需要用户输入一些配置。

I'm working on an Eclipse plugin (or in fact, a plugin for an Eclipse-based application) which needs some configuration to be entered by the user.

从查看文档,似乎有两个首选API - 一个在 org.eclipse.core.runtime.preferences / a>,扩展/实现 OSGI prefererence API ,另一个,JFace具体,在 org.eclipse.jface.preference 。那么我们有

From looking at the documentation, there seem to be two preference APIs - one in org.eclipse.core.runtime.preferences, extending/implementing the OSGI prefererence API, another one, JFace specific, in org.eclipse.jface.preference. Then we have org.eclipse.ui.preferences, too.

OSGI API具有层次结构树 - 偏好节点(首选项 IEclipsePreferences )可以具有多个子节点,它们本身可以包含单个的名称 - 值对以及更多的子节点。这似乎是适合我的用例 - 我有一个动态数量的偏好组,每个都有大约三个字符串属性(名称,描述,命令),它很好地映射到这些节点。

The OSGI API has a hierarchic Node tree - a preference node (Preferences or IEclipsePreferences) can have multiple subnodes, which themselves can contain both individual name-value-pairs as well as more subnodes. This seems to be right for my use case - I have a dynamic number of "preference groups", each with about three string properties (name, description, command), which would nicely map to these nodes.

JFace API没有这样的层次结构,每个插件只有一个平面的 IPreferenceStore 。但是它提供了首选编辑器页面,然后可以通过实现 IWorkbenchPreferencePage 使用org.eclipse.ui.preferencePages扩展点。 (我仍然需要自己实现部分偏好页面,但是这个API为此提供了一个很好的基础,似乎。)

The JFace API has no such hierarchy, only a flat IPreferenceStore for each plugin. But it provides preference editor pages, which then can be included in the usual preferences dialog (Window / Preferences) by implementing IWorkbenchPreferencePage and using the "org.eclipse.ui.preferencePages" extension point. (I still have to implement part of the preference page myself, but this API provides a good base for this, it seems.)

似乎 org.eclipse.ui.preferences API通过提供基于IEclipsePreferences的IPreferenceStore实现来桥接这两个API,但是我仍然不能看看如何使用这个。

It seems that the org.eclipse.ui.preferences API somehow bridges both these APIs by providing an IPreferenceStore implementation based on the IEclipsePreferences, but I still can't see how to use this.

所以这里我的问题:如何使用分层OSGI 首选项在首选项对话框中?我只需要一个级别,但我需要用户能够动态添加新的节点(每个约有三个首选项)。 (这些节点不一定要有新的首选页面。)

So here my question: How can I use the hierarchical OSGI Preferences in the preferences-dialog? I only need one level, but I need the user to be able to dynamically add new nodes (with about three preferences each). (These nodes do not have to have new preference-pages, though.)

推荐答案

似乎在首选页面级别,它想要使用偏好商店。大多数插件从 org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore()提供的默认值中获取他们的偏好存储。这样可以轻松地转换为具有InstanceScope的ScopedPreferenceStore,并具有与其bundle.id匹配的节点。

It seems that at the preference page level, it wants to work with a preference store. Most plugins get their preference store from the default provided by org.eclipse.ui.plugin.AbstractUIPlugin.getPreferenceStore(). That translates loosely to a ScopedPreferenceStore with an InstanceScope with a node that matches their bundle.id.

相当于获取匹配的IEclipsePreferences对象将是 InstanceScope.INSTANCE.getNode( bundle.id)。这将允许您在其下方添加更多节点,但是它们将无法从您的IPreferenceStore访问。但是,您的偏好页面可以将其首选项设置为插件的主要存储,并且仍然使用IEclipsePreferences或辅助IPreferenceStore来访问额外的首选项(您只需要自己编码,类似于 org.eclipse .ui.internal.dialogs.EditorsPreferencePage )。

The equivalent to get the matching IEclipsePreferences object would be InstanceScope.INSTANCE.getNode("bundle.id"). That would allow you to add further nodes underneath, but they wouldn't be accessible from your IPreferenceStore. However, your preference page could set its preference store to the main one for your plugin, and still use IEclipsePreferences or a secondary IPreferenceStore to access extra preferences (you just have to code it yourself, similar to org.eclipse.ui.internal.dialogs.EditorsPreferencePage).

这篇关于Eclipse:OSGI首选项与PreferenceStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆