Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Unable to create working Element based edge
Unable to create working Element based edge [message #1817002] Wed, 13 November 2019 15:27 Go to next message
Ilenia Salvadori is currently offline Ilenia SalvadoriFriend
Messages: 3
Registered: November 2019
Junior Member
Hi,
I am trying to create a Sirius diagram for my EMF model. The main ingredients of the model are 5 classes: "Instance", "Signature", "Field", "Tuple" and "Atom".
An Instance can have multiple Signatures as well as Fields. Signature can have multiple Atoms, while Field have Tuples, which are in turns made of two Atoms.
What I was able to achieve so far is to create a Container for my Signature instances, with a Sub Node for the Atoms. Then, I did the same for the Field, with their Tuple and Atoms (two container with at the end a sub node).
Now, I would like to display the relation between atoms of different signatures, as it is expressed in the field tuples. So, basically, if a Field named "address" contains a tuple with atoms {person0, address0} I would like to display a relation between the atom "person0" of the signature Person and the atom "address0" of the signature Address.
To achieve that I have tried to create an Element Based Edge, but I was not able to obtain anything working.
Here is what I tried so far:

1) Domain class: Tuple
Source Mapping: Atom Sub Node
Source Finder Expression: [self.atom->at(0).findTargetAtoms(diagram) /]
Target Mapping: Atom Sub Node
Target Finder Expression: [self.atom->at(1).findTargetAtoms(diagram)/]
Semantic Candidate Expression: [diagram.findSourceTuple()/]

where the method I am using are defined as Java services, as:

public Atom findTargetAtoms(Atom atom, DDiagram diagram) {
    	List<DDiagramElementContainer> containers = diagram.getContainers(); 
    	containers = containers.stream().filter(n->n.getTarget() instanceof Signature).collect(Collectors.toList());
    	if(!containers.isEmpty()) {
    		Signature sig = (Signature) containers.get(0).getTarget();    		
    		List<Atom> atomList = sig.getAtom();
    		for(Atom a : atomList) {    			
    			if(atom.getLabel().equals(a.getLabel())) {
    				return a;
    			}  				  			
    		}
    	}
    	return atom;
    }


and

public List<Tuple> findSourceTuple(DDiagram diagram) {
    	List<Tuple> sourceTuples = new LinkedList<Tuple>();
    	List<DNode> nodes = diagram.getNodes();
    	nodes = nodes.stream().filter(n->n.getTarget() instanceof Instance).collect(Collectors.toList());
    	if(!nodes.isEmpty()) {
    		Instance instance = (Instance) nodes.get(0).getTarget();
    		List<Field> fieldList = instance.getField();
    		for(Field field : fieldList) {
    			sourceTuples.addAll(field.getTuple());
    		}
    	}
    	return sourceTuples;
    }


The container are shown fine, but I am not able to make the relations work.
Thanks in advance for the help!

Ilenia
Re: Unable to create working Element based edge [message #1817022 is a reply to message #1817002] Thu, 14 November 2019 09:15 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 516
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Ilenia,

From your description I expected to find references from Signature and Tuple to Atom in the provided sample model, but it seems that Atom elements are contained by Tuple and Signature elements. It seems you have "containment" references in your MM.
So I assume you want to "match" atoms which have the same labels.

I would try the following Element Based Edge mapping:

Domain class : Tuple

Semantic candidates expression:
- From the Alloy used as root element of the diagram, find all tuples you might want to see on the diagram
- First try: aql:self.instance.field.tuple (from your sample model, to check with your metamodel definition)
- Note that you can use the Interpreter view (Sirius Interpreter) and a sample model to test your expression, you can also use the auto-completion and the validation in the .odesign editor.
- Then regarding how select the instance nodes you display on the diagram you might want to filter those elements.


Source finder expression
- From each tuple found during the evaluation of the semantic candidate, we have to find the source element of the edge.
- From your description, I assume that from the first Atom of the tuple, you want to retrieve an Atom in a signature which would have the same label
- aql:self.atom->first().findTargetAtoms(diagram) with you service
- but IMO I would go only on the domain model level: aql: self.eContainer(AlloyAnalyzer::Instance).sig.atom->select(a | a.name = self.atom->first())

Target finder expression
- aql:self.atom->last().findTargetAtoms(diagram) with you service
- but IMO I would go only on the domain model level: aql: self.eContainer(AlloyAnalyzer::Instance).sig.atom->select(a | a.name = self.atom->last())

I am note sure for AlloyAnalyzer::Instance, you might have to check the name of your EPackage.

Regards




Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Thu, 14 November 2019 09:16]

Report message to a moderator

Re: Unable to create working Element based edge [message #1817080 is a reply to message #1817022] Fri, 15 November 2019 08:49 Go to previous message
Ilenia Salvadori is currently offline Ilenia SalvadoriFriend
Messages: 3
Registered: November 2019
Junior Member
Thank you very much for your prompt reply.
First of all, yes, Atom are indeed contained both in Signature and Tuple and I want to match atoms with the same label in order to show the relation in the diagram.
After your suggestions this is what I tried.

Domain class: alloyanalyzer::Tuple

Source Finder Expression

[self.eContainer(alloyanalyzer::Field).eContainer(alloyanalyzer::Instance).sig.atom->select(a : alloyanalyzer::Atom| a.label = self.atom->first().label)/]


Target Finder Expression

[self.eContainer(alloyanalyzer::Field).eContainer(alloyanalyzer::Instance).sig.atom->select(a : alloyanalyzer::Atom| a.label = self.atom->last().label)/]


Semantic Candidate Expression

[self.instance.field.tuple/]


I tested all the expressions with the Sirius interpreter and my test model and they seem to point to the right elements. However, still no relation is displayed on the diagram.

I have also a question. The "self" I am using in the Semantic Candidate Expression then, is always the root element of the diagram (in my case the Alloy element), while the "self" I am using in the finder expressions is always of type Domain Class (in my case a Tuple). Is that correct?

Thank you very much for your help!
Ilenia
Previous Topic:How to control size of drawing canvas
Next Topic:trigger refresh on filter
Goto Forum:
  


Current Time: Fri Apr 19 00:13:25 GMT 2024

Powered by FUDForum. Page generated in 0.02185 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top