Eclipse 插件/查看问题

发布于 2024-07-25 14:06:40 字数 288 浏览 7 评论 0原文

我有一个包含类 A 的插件,它通过以下代码行打开类 B 中定义的视图:

(VideoLogView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("Videolog.VideoLogView");

我需要在视图(类 B 对象)的 createPartControl() 方法中执行的操作是访问类中的方法一个物体。

如何做到这一点?

谢谢。

I have a plugin which contains class A that brings up a view defined in class B via the following line of code:

(VideoLogView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("Videolog.VideoLogView");

What I need to do in the createPartControl() method of the view (class B object) is access a method in the class A object.

How can this be done?

Thanks.

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

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

发布评论

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

评论(1

站稳脚跟 2024-08-01 14:06:40

看起来您面临着“如何将参数传递给我的观点”的经典问题?
此线程最好地说明了这一点:

我在 RCP 项目开始时也面临着同样的问题。 我对无法将参数传递给视图作为查看模型这一事实感到很奇怪。

为什么? 因为(强调我的):

您处于一个开放的可插拔平台上。
为现有的发展做出贡献,其他人也应该能够为您的发展做出贡献。

因此,您不会将参数“传递”给视图,这会将整个事物锁定为非开放设计。
相反,您的视图将询问平台(或听取平台的意见)来确定要管理哪些信息。
其他视图(来自尚不存在的其他插件)可能也想管理同一事件的相同信息。

然后您应该做的是向工作台询问当前的选择。 我猜您的视图是通过双击操作或简单选择打开的,因此当前将选择您要在视图中管理的对象。
这是您从视图中检索工作台选择的方法:

ISelection s = this.getSite().getWorkbenchWindow().getSelectionService().getSelection();

其中“this”是一个 ViewPart。

然后,您必须将初始视图(从给定事件(例如 DoubleClick)启动视图创建的视图)作为选择提供程序。 JFace 查看器是一个选择提供程序,因此如果您使用 jface,则可以使用它,或者当您使用自定义 时,您可以实现 ISelectionProvider 接口SWT 控件(这就是我的情况)。


文章“Eclipse Workbench:使用选择服务”也可以给出你一些指点。

替代文本

Look like you are facing the classic issue of "how do I pass arguments to my view" ?
This thread illustrates it best:

I was facing the same problem at the beggining of my RCP project. I was getting weird about the fact that there was no way to pass an argument to a view as the viewed model.

Why? Because (emphasis mine):

You are on an opened, pluggable platform.
You contribute to existing developments, others should be able to contribute to yours.

Therefore you will not "pass" arguments to a view, this would lock the whole thing into a non-opened design.
Instead, your view will ask the platform (or will listen to the platform) to determine which information to manage.
Other views (from other plugins that don't yet exist) might also want to manage the same information on the same event.

What you should do then is to ask the workbench for the current selection. I guess your view is opening on a double click action or simple selection so the object you want to manage in your view will be currently selected.
This is how you could retrieve the workbench selection from your view :

ISelection s = this.getSite().getWorkbenchWindow().getSelectionService().getSelection();

where "this" is a ViewPart.

Then you have to make your initial view (the one initiating the view creation from a given event like DoubleClick) a selection provider. A JFace viewer is a selection provider, so you can use it if you're using jface, or you can implement the ISelectionProvider interface when you're using custom SWT controls (that was my case).


The article "Eclipse Workbench: Using the Selection Service" can also give you some pointers.

alt text

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