Eclipse 建模框架:将替代视图链接到模型

发布于 2024-11-17 06:25:29 字数 204 浏览 4 评论 0原文

我有一个 ECore 模型,可以用来自动生成模型源和 JFace 编辑包。我正在尝试为该模型的内容开发一个替代视图,基本上是一个基于 JFreeChart 的图形视图。我已经成功创建了一个基于 JFreeChart 的视图插件。现在我需要将视图与模型链接起来。我怎样才能做到这一点?我想使用 TreeBased 编辑器编辑模型,并在图形视图中查看此类编辑的效果。这可能吗?

谢谢

I have an ECore model I exploit to automatically generate the model source and JFace edit package. I am trying to develop an alternative view for contents of that model, basically a graph view based on JFreeChart. I have managed to create a JFreeChart based view plugin. Now I need to link the view with the model. How can I do that? I would like to edit the model with the TreeBased editor and see the effects of such editing in the graph view. Is that possible?

thank you

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

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

发布评论

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

评论(3

小草泠泠 2024-11-24 06:25:29

如果您打开 Graphbased-View,则询问当前打开的编辑器的 IFile。获取文件后,您可以加载模型(请参阅生成的编辑器如何从底层资源加载模型)附加 IResourceChangeListener 以在 EMF 模型的底层 IFile 发生更改时获取通知。
收到通知后,您可以从文件中重新加载模型并在视图中显示模型。

此外,如果用户将另一个 emf 编辑器带到顶部或关闭编辑器(您还必须卸载(关闭时)或刷新(另一个带有您的 emf 模型的编辑器被带到顶部),您必须注册一个 PartListener 以获取通知顶部)。

If you open your Graphbased-View ask for the IFile of the current opened editor. After you got the file, you can load the model (see the generated Editor how to load the Model from the underlying resource) attach a IResourceChangeListener to get a notification, if the underlying IFile of your EMF Model changed.
After a notification you can reload the model from your file and show the model in your view.

In addition you have to register a PartListener to get a notification if the user brings another emf-editor to top or he closes the editor (you also have to unload (on close) or refresh (another editor with your emf-model was brought to top).

吾性傲以野 2024-11-24 06:25:29

是的,确实如此,因为生成的 EMF 代码提供了一个通知层:使用 EObject.eAdapters 添加新适配器,如果模型发生更改,则会收到通知。

    object.eAdapters().add(new Adapter() {

        public void setTarget(Notifier newTarget) {
            // TODO Auto-generated method stub

        }

        public void notifyChanged(Notification notification) {
            // TODO Auto-generated method stub

        }

        public boolean isAdapterForType(Object type) {
            // TODO Auto-generated method stub
            return false;
        }

        public Notifier getTarget() {
            // TODO Auto-generated method stub
            return null;
        }
    });

Yes, it is, as the generated EMF code provides a notification layer: use EObject.eAdapters to add a new adapter, that is notified if the model is changed.

    object.eAdapters().add(new Adapter() {

        public void setTarget(Notifier newTarget) {
            // TODO Auto-generated method stub

        }

        public void notifyChanged(Notification notification) {
            // TODO Auto-generated method stub

        }

        public boolean isAdapterForType(Object type) {
            // TODO Auto-generated method stub
            return false;
        }

        public Notifier getTarget() {
            // TODO Auto-generated method stub
            return null;
        }
    });
时间你老了 2024-11-24 06:25:29

好的,我已经按照 Zoltán 的建议成功做到了这一点。不管怎样,我承认我更喜欢一个更结构化的答案,这就是为什么我用解决方案的简短摘要来回答我自己的问题。

基本上这个想法是视图插件实现 ViewPart 接口。因此,它实际上可以调用以下方法

getSite().getWorkbenchWindow().getSelectionService()

来获取工作台选择服务。因此,您可以调用 SelectionService 方法

addSelectionListener(ISelectionListener listener)

,将您自己的 ISelectionListener 作为参数传递,该 ISelectionListener 可以是您正在实现的同一 ViewPart。您只需实现 ISelectionListener 接口,从而提供 SelectionChanged 方法的实现

public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection)

Ok I have managed to do that following the Zoltán suggestions. Anyway I admit I would have preferred a more structured answer, and that is why I am answering my own question with a brief summary of the solution.

basically the idea is that a view plugin implements the ViewPart interface. Because of this it can actually invoke the following methods

getSite().getWorkbenchWindow().getSelectionService()

in order to get the workbench selection service. You can therefore invoke the SelectionService method

addSelectionListener(ISelectionListener listener)

passing as parameter your own ISelectionListener which can be the same ViewPart you are implementing. You just have to implement the ISelectionListener interface and thus provide an implementation of the selectionChanged method

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