Eclipse RCP 将值保存到工作台

发布于 2025-01-07 08:04:39 字数 575 浏览 0 评论 0原文

背景

我正在开发 uDig 的插件,这是一个基于 Eclipse RCP 构建的项目。我的插件包含一个表,其中填充了工作台选择中的数据。用户可以对表数据进行分组、排序和过滤。当工作台选择更改组时,排序和筛选信息将重置,并将新选择数据加载到表中。

问题

如何将值保存到工作台以便稍后访问它们?

当工作台选择发生更改时,我希望将组、排序和过滤状态保存到工作台中,以便如果工作台选择变回已保存的选择,我可以恢复状态。

研究

我看过 IViewPart.saveState(IMemento memento) 但感觉这仅在添加和删除视图时才有用。

我也研究过使用首选项,但觉得这是对该资源的错误使用。

IEclipsePreferences node = InstanceScope.INSTANCE.getNode(PluginUI.PLUGIN_ID);
node.put(key, value);

最后,

我对 Eclipse RCP 有点陌生,可能会以错误的方式解决这个问题。如果有更好的方法来保存和加载此信息,请随时分享。

Background

I am working on a plugin for uDig, a project build on Eclipse RCP. My plugin contains a table that gets populated with data from the Workbench selection. The table data can be grouped, sorted and filtered by the user. When the workbench selection changes the group, sort and filter information is reset and the new selection data loaded into the table.

Question

How do I save values to he workbench so I can access them later?

When the workbench selection gets changed I wish to save the group, sort and filter state out to the Workbench so that if the workbench selection ever changes back to the saved selection I can restore the state.

Research

I have looked at IViewPart.saveState(IMemento memento) but get the feeling this is only useful when you are adding and removing a view.

I have also looked at using preferences but feel this is an incorrect usage of this resource.

IEclipsePreferences node = InstanceScope.INSTANCE.getNode(PluginUI.PLUGIN_ID);
node.put(key, value);

Finally

I am some what new to Eclipse RCP and may be attacking this problem the wrong way. If there is a better way to save and load this information please feel free to share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄与心 2025-01-14 08:04:39

从你的描述看来,你对桌子有看法。保存视图状态的教科书方法是通过IMemento。您可以在此演示文稿中查看使用此界面的代码。作为替代方案,您还可以使用 IPreferenceStore

当状态具有全局范围时,您通常使用首选项;当它们特定于视图时,您通常使用备忘录。

From your description, it sounds like you have a view with the table. The text book way to save state for a view, is via IMemento. You can see the code to use this interface in this presentation. As an alternative, you can also use the IPreferenceStore.

You usually use preferences when the state has a global scope and memento when they are specific to a view.

失去的东西太少 2025-01-14 08:04:39

您可以使用对话框设置为了这。

You can use dialog settings for this.

缺⑴份安定 2025-01-14 08:04:39

我假设您正在尝试使用此处所述的选择服务来传达两个视图
http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html

如果是这种情况,您确实不必保存选择,因为选择时的结果是动态计算的(因为这是选择服务的全部目的),

但如果您仍然想保留中间视图您始终可以为其定义自定义 XML 格式的数据将更改保存到磁盘。然后在需要时重新加载它们。

(另一个选项是 Java 内置对象序列化,它可以将视图绑定数据对象保留到磁盘。)

I am assuming you are trying to communicate two views using the selection service as described here
http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html

If that is the case you really dont have to save a selection as the results upon selecting are computed on the fly (as that is the whole purpose of the selection service)

But in case you still want to persist the intermediate view data you can always define your custom XML format for persisting the changes to the disk. And then reload them whenever required.

(Another option is Java inbuilt object serialization which can perist the view bound data objects to disk.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文