How to extend an EMF-based model with listeners for use in a GEF editor?

蓝咒 提交于 2019-12-11 04:12:40

问题


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

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.

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);
}

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.

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).

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

The model structure is approximately as follows:

org.example.structure.MyGraph:

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

Then there is als a class 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);
}
...
}

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"?

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...

Thanks!


回答1:


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




回答2:


There is little to no reasons in using EMF and GEF together. If you model in EMF and using GEF as an editing framework you should consider using GMF http://www.eclipse.org/modeling/gmp/ insted. GMF provides an extension on Draw2D, GEF and EMF, which glues it together seamlessly. And if you're just building nodes and edges considef using Graphity as a much easier framework then GEF of EMF, which will give you quick and nice results very soon.



来源:https://stackoverflow.com/questions/9820510/how-to-extend-an-emf-based-model-with-listeners-for-use-in-a-gef-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!