Search code examples
eclipse-emfemfeclipse-emf-ecore

modeling self referencing nodes in EMF and edit them with ECP


I'm trying to model a network with EMF. The network should be made up of nodes connected to each other. Each node should have one or many connections to the others, like a mesh network.

The model should be editable by the EMF Client Platforms (ECP) Demo Application. When the user creates nodes, in ECPs model-explorer, he/she can set the connections to the other nodes, preferably in a list.

First try was a self-reference, but the problem is there are no bidirectional self-references. This results in, not seeing the connection from the opposite node.

My next idea was to use an intermediate connection class, which leads to another problem. I would like to create this connection automatically without a connection class appearing in the model-explorer. Which would be possible to achieve in the generated EMF viewer, but not in the ECP demo application I'm using.

Third Idea: The only way I can think of solving the last idea, is using a tableControl in the view of the node, to edit the connection class in there. But then the problem with hiding the connection class in the model-explorer remains and the connection class appears in the project folder (highest level) and not in their containing class (in my case a network class).

Doe's anyone have some ideas, how to solve any of my problems?

edit: additional information

The connections between the nodes are by definition full duplex. And the graph should afterwards be used as input for a shortest path algorithm.


Solution

  • Your first try is the good one. Actually, you can model opposite in Ecore. To do so, you have to model two EReferences towards the same object (so two reflexives references), then set the property eOpposite of one of your EReference to the other one.

    Here is a simple metamodel with the eOpposite set: https://repository.genmymodel.com/vincent.aranega/NodeGraph

    In the Ecore-XMI, it looks like this (note the eOpposite value):

    <eStructuralFeatures xsi:type="ecore:EReference" xmi:id="_pwXZhv1pEeW9zv77lynsJg"
        name="references" upperBound="-1" eType="#_pwXZg_1pEeW9zv77lynsJg" eOpposite="#_pwXZiv1pEeW9zv77lynsJg"/>
    
    <eStructuralFeatures xsi:type="ecore:EReference" xmi:id="_pwXZiv1pEeW9zv77lynsJg"
        name="relatives" upperBound="-1" eType="#_pwXZg_1pEeW9zv77lynsJg" eOpposite="#_pwXZhv1pEeW9zv77lynsJg" />
    

    With this metamodel, you are able to create a Graph that contains many Node. Each node can reference other nodes. If a Node A as a reference to another named B, the relatives collection of B is automatically updated with A.