Eclipse RCP:我应该在哪里保留我的模型对象以及它们如何与视图对话?

时间:2023-01-13 23:01:54

In Eclipse RCP way of doing things, where should I keep my model objects? And when they are loaded or changed, how should they talk to the views?

在Eclipse RCP的做事方式中,我应该在哪里保留我的模型对象?当他们被加载或更改时,他们应该如何与观点交谈?

I am attempting to port my existing application to Eclipse RCP. It could be viewed as an IDE-like application: I open a file, which contains links to source files. The source files are displayed in the tree view. I can edit the source, and build the sources into some output...

我试图将我现有的应用程序移植到Eclipse RCP。它可以被视为类似IDE的应用程序:我打开一个文件,其中包含指向源文件的链接。源文件显示在树视图中。我可以编辑源代码,并将源代码构建到某个输出中......

For example, when I handle the Open command, where would I create the model object so my views can see them? I'd rather avoid the use of singleton manager class, but that maybe the simplest way.

例如,当我处理Open命令时,我将在哪里创建模型对象,以便我的视图可以看到它们?我宁愿避免使用单例管理器类,但这可能是最简单的方法。

Interesting code I found browsing JDT's source code are JavaCore, JavaModel, JavaModelManager. and JavaProject.

我发现浏览JDT源代码的有趣代码是JavaCore,JavaModel,JavaModelManager。和JavaProject。


IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();

public static IJavaProject create(IProject project) {
    if (project == null) {
        return null;
    }
    JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel();
    return javaModel.getJavaProject(project);
}

Related:

2 个解决方案

#1


5  

I believe this is best achieved through Listeners.

我相信这最好通过听众来实现。

Your data (model) is in private package, and only Interfaces of those data are exposed in a public package.

您的数据(模型)位于私有包中,并且只有这些数据的接口才会公开在公共包中。

Eclipse RCP:我应该在哪里保留我的模型对象以及它们如何与视图对话?

You will find in this wiki section the principle, but also concrete examples here.

你会在这个维基部分找到原理,但也有具体的例子。


Regarding the model, an osgi-like approch would be to use a host plugin as the accessible object. i.e:

关于模型,类似osgi的approch将使用主机插件作为可访问对象。即:

MyPlugin.getDefault().getModel()

This will allow you to setup/dispose the model along with the plugin lifecycle.

这将允许您设置/处置模型以及插件生命周期。

If the model is in one plugin, it can define extension points for listeners. A view can extend these extension points which are then automatically registered in the loading of the Model plugin. The views can query the model for the required information as soon as they get the first message from the model.

如果模型在一个插件中,它可以为侦听器定义扩展点。视图可以扩展这些扩展点,然后在加载Model插件时自动注册。一旦从模型中获取第一条消息,视图就可以在模型中查询所需信息。

A good example of data binding can be found in this article.

本文中提供了一个很好的数据绑定示例。

#2


2  

We tend to use IEditorParts to store keep a copy of the model (derived from the IEditorInput).

我们倾向于使用IEditorParts来存储保留模型的副本(从IEditorInput派生)。

If a view needs to know about the model, then use the ISelection framework and focus to move the model around from the editor to the view.

如果视图需要了解模型,则使用ISelection框架并将焦点从编辑器移动到视图。

#1


5  

I believe this is best achieved through Listeners.

我相信这最好通过听众来实现。

Your data (model) is in private package, and only Interfaces of those data are exposed in a public package.

您的数据(模型)位于私有包中,并且只有这些数据的接口才会公开在公共包中。

Eclipse RCP:我应该在哪里保留我的模型对象以及它们如何与视图对话?

You will find in this wiki section the principle, but also concrete examples here.

你会在这个维基部分找到原理,但也有具体的例子。


Regarding the model, an osgi-like approch would be to use a host plugin as the accessible object. i.e:

关于模型,类似osgi的approch将使用主机插件作为可访问对象。即:

MyPlugin.getDefault().getModel()

This will allow you to setup/dispose the model along with the plugin lifecycle.

这将允许您设置/处置模型以及插件生命周期。

If the model is in one plugin, it can define extension points for listeners. A view can extend these extension points which are then automatically registered in the loading of the Model plugin. The views can query the model for the required information as soon as they get the first message from the model.

如果模型在一个插件中,它可以为侦听器定义扩展点。视图可以扩展这些扩展点,然后在加载Model插件时自动注册。一旦从模型中获取第一条消息,视图就可以在模型中查询所需信息。

A good example of data binding can be found in this article.

本文中提供了一个很好的数据绑定示例。

#2


2  

We tend to use IEditorParts to store keep a copy of the model (derived from the IEditorInput).

我们倾向于使用IEditorParts来存储保留模型的副本(从IEditorInput派生)。

If a view needs to know about the model, then use the ISelection framework and focus to move the model around from the editor to the view.

如果视图需要了解模型,则使用ISelection框架并将焦点从编辑器移动到视图。