Home » Eclipse Projects » Sirius » Finding the target of the edge for setting the label
|Finding the target of the edge for setting the label [message #1250793]
||Wed, 19 February 2014 16:05
| Wilbert Alberts
Registered: June 2010
I have a problem defining the expression that gives the correct label for an relation based edge.
Suppose that my meta model contains the following entities: Component and Interface.
Components define and provide Interfaces by containing them. Furthermore, Components might depend on Interfaces provided by other Components. (A simple dependsOn property of a Component.)
Suppose that I want to provide a diagram only containing Components. If a Component depends on one ore more Interfaces provided by another Component, I want to draw an edge. The label of that edge should consist of the names of the interfaces representing the relationship between the components.
For example: Three components, A, B, C. B provides interface IB1 and IB2 and C provides interface IC1 and IC2. A depends on IB1, IB2 and IC1.
Then I want to have diagram consisting of three nodes representing A, B and C. Between A and B, an edge should be drawn with the label '[IB1 IB2]' and between A and C, an edge should be drawn labeled '[IC1]'.
In order to draw the edge between two components, I used a target finder expression like: [self.dependsOn.eContainer()/] This results in the component providing the interface self depends on.
However, if I want to provide an expression that generates the label of the edge, I'm running into problems: [self.dependsOn.name/] clearly is wrong. That one will result in all interface names (including IC2 where A is not depending on).
I'm looking for an expression like: [self.dependsOn->select(i | target.provides->includes(i)).name/]
However, 'target' is not available as a variable.
How can I solve this?
|Re: Finding the target of the edge for setting the label [message #1250846 is a reply to message #1250793]
||Wed, 19 February 2014 17:04
|| Pierre-Charles David
Registered: July 2009
Le 19/02/2014 17:05, Wilbert Alberts a écrit :|
> I have a problem defining the expression that gives the correct label
> for an relation based edge.
> I'm looking for an expression like: [self.dependsOn->select(i |
> However, 'target' is not available as a variable.
> How can I solve this?
I've just tried to reproduce the same kind of structure using Ecore, and
it is indeed possible, but definitely not trivial. You were on the right
track, the structure of your expression is correct and you need the
equivalent of "target", i.e. a pointer to the element "at the other end"
of the specific edge for which you are computing the label.
The expression you need to put instead of the non-existing "target"
variable is the following:
It is verbose because OCL needs explicit casting at each navigation
step. Removing these casts for readability we get:
It works like this:
1. It starts from the "view" variable that Sirius supplies. This points
to the model element used by Sirius to represent the graphical edge
itself (it is of type DEdge, from the Sirius metamodel).
2. From there, it find the edge's targetNode. This gives use another
Sirius model element, the one representing the other end of the edge
(the shape representing your component). It is still an element from the
Sirius metamodel (so we need to cast it to DDiagramElement, another
Sirius metamodel type).
3. All Sirius model elements which "stand for" a domain element in your
diagram have a "target" reference to get this semantic element, so we
follow this "target" reference and get the actual Component at the end
of the edge.
So in the end, because your label must be different for each edge, you
can not simply navigate at the level of the domain model but need to
navigate one level "above" in the Sirius model part, from the "view"
variable, and at the end go back to you domain.
I have tried to be clear but I understand that it needs some knowledge
of how Sirius works underneath, so don't hesitate if you need more
Pierre-Charles David - Obeo
Need training or professional services for Sirius?
Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
Current Time: Tue Sep 26 07:31:29 GMT 2017
Powered by FUDForum
. Page generated in 0.06165 seconds