如何使用侦听器扩展基于EMF的模型以在GEF编辑器中使用? [英] How to extend an EMF-based model with listeners for use in a GEF editor?

查看:93
本文介绍了如何使用侦听器扩展基于EMF的模型以在GEF编辑器中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GEF 编辑器和基于 EMF 的模型创建Eclipse RCP.

I am creating an Eclipse RCP with a GEF editor and an EMF-based model.

GEF书中提到的关于模型的一件事是

One thing that is mentioned about the model in the GEF Book is

模型应通过监听器广播所有状态更改,以便 在模型不具有任何直接知识的情况下,可以更新视图 控制器或视图.

The model should broadcast all state changes via listeners so that the view can be updated without the model having any direct knowledge of the controller or view.

在本书的示例中,每个模型元素类(例如PersonMarriage等)(示例是家谱编辑器)都具有添加和删除相应监听器的方法,例如,用于Person是:

In the book's example, each model element class, e.g., Person, Marriage, etc. (the example is a genealogy editor), has methods to add and remove the respective listener, e.g., for Person the are:

public void addPersonListener(PersonListener l) {
    listeners.add(l);
}

public void removePersonListener(PersonListener l) {
    listeners.remove(l);
}

不幸的是,我使用的模型没有这些add/removeListener方法.现在,我需要一种扩展模型并实现方法的方法.我不知道从哪里真正开始,因为我对EMF知之甚少.

Unfortunately, the model I use doesn't have these add/removeListener methods. Now I need a way to extend the model and implement the methods. I have no idea where to start really, as I don't know much about EMF.

该模型基于图形,因此它具有节点和边(关系").通过调用例如MyNode node = ExampleFactory.eINSTANCE.createMyNode()并将新节点添加到图中例如graph.addMyNode(node)将元素添加到图中.

The model is graph-based, so it has nodes and edges ("relations"). Elements are added to the graph via calling, e.g., MyNode node = ExampleFactory.eINSTANCE.createMyNode() and adding the new node to the graph, e.g., graph.addMyNode(node).

由于缺乏有关EMF的知识,我无法理解的是模型中的扩展点".

What I don't understand due to my lack of knowldege concerning EMF is where the "extension point" in the model would be.

模型结构大致如下:

org.example.structure.MyGraph:

public interface MyGraph {
...
    MyRelation addMyNode(MyNode sourceMyNode, MyNode targetMyNode, 
        MYTYPE_NAME myRelationType);
...
}

然后有一个班级MyGraphImpl

org.example.structure.impl.MyGraphImpl:

public class MyGraphImpl extends Graph implements MyGraph {
...
protected MyGraphImpl() {
    super();
    this.init();
}
...
private void init()
{
    //creates indexes
}
...
@Override
public void addMyNode(MyNode myNode) 
{
    super.addNode(myNode);
}
...
}

我是否必须-出于缺乏知识而这样说-使用EMF扩展单个模型类(例如,如

Do I have to - to put it like that for want of knowledge - extend the single model classes with EMF (as described, e.g., on Lars Vogel's website), or can I extend the model "per hand"?

并且:我是否必须扩展模型的**interface**(例如MyGraph)或其实现的(例如MyGraphImpl)?

And: Do I have to extend the **interface**s of the model (e.g., MyGraph), or their implementation classes (e.g., MyGraphImpl)?

对于任何正确方向的指点,我将非常感谢...

I'll be very thankful for any pointers in the right direction...

谢谢!

推荐答案

EMF具有自己的Notification机制,无需添加其他侦听器机制,快速的google搜索为我提供了另外一个

EMF has its own Notification mechanism, there is no need to add another listener-mechanism, a quick google-search gave me another tutorial of Lars with a nice example that demonstrates this mechanism

这篇关于如何使用侦听器扩展基于EMF的模型以在GEF编辑器中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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