Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to link to non modelelements(How to link to non modelelements)
How to link to non modelelements [message #550418] Fri, 30 July 2010 06:20 Go to next message
Jos Warmer is currently offline Jos Warmer
Messages: 66
Registered: July 2009
Member
I am trying to create a visual link between two elements that does not refer to a metaclass, but to a reference in the metamodel.

Example: I have an ecore metamodel with metaclass "BusinessClass" and a reference from DomainClass to itself called "superclass".

I create feature providers to create and add a "BusinessClass" and link the shape to the model object representing the BusinessClass.

Now I would like to have featureproviders to create/add the "superclass" reference between two existing BusinessClasses. As there is no metaclass representing the "superclass" (it is just a reference from one businessclass to another in the metamodel) I wonder how I should setup the Graphiti link from the "superclass" shape (a polyline) to the 'superclass model object, because there is no such model object.

Any pointers on how to achieve this?

-- Jos
Re: How to link to non modelelements [message #550451 is a reply to message #550418] Fri, 30 July 2010 07:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1587
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Normally, connections represent references. So I would suggest to reference
the "superclass" reference as the business object of the connection as it is
done in the tutorial feature to add an ERefernce:
public PictogramElement add(IAddContext context) {

IAddConnectionContext addConContext = (IAddConnectionContext) context;

EReference addedEReference = (EReference) context.getNewObject();


IPeCreateService peCreateService = Graphiti.getPeCreateService();

// CONNECTION WITH POLYLINE

Connection connection =
peCreateService.createFreeFormConnection(getDiagram());

connection.setStart(addConContext.getSourceAnchor());

connection.setEnd(addConContext.getTargetAnchor());


IGaService gaService = Graphiti.getGaService();

Polyline polyline = gaService.createPolyline(connection);

polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram())) ;


// create link and wire it

link(connection, addedEReference);

-Michael


"Jos Warmer" <jos.warmer@ordina.nl> wrote in message
news:i2u916$6vt$1@build.eclipse.org...
>I am trying to create a visual link between two elements that does not
>refer to a metaclass, but to a reference in the metamodel.
>
> Example: I have an ecore metamodel with metaclass "BusinessClass" and a
> reference from DomainClass to itself called "superclass".
>
> I create feature providers to create and add a "BusinessClass" and link
> the shape to the model object representing the BusinessClass.
>
> Now I would like to have featureproviders to create/add the "superclass"
> reference between two existing BusinessClasses. As there is no metaclass
> representing the "superclass" (it is just a reference from one
> businessclass to another in the metamodel) I wonder how I should setup the
> Graphiti link from the "superclass" shape (a polyline) to the 'superclass
> model object, because there is no such model object.
>
> Any pointers on how to achieve this?
>
> -- Jos
Re: How to link to non modelelements [message #550459 is a reply to message #550451] Fri, 30 July 2010 08:59 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 66
Registered: July 2009
Member
Michael,

In the tutorial EReference is a real metaclass (despite its name Smile)..Therefore you actually create an instance of EReference, so there is a clear model element in the underlying model to which you can link.
My example is different in the sense that all the model elements (the two BusinessClasses) already exist and by adding a superclass relation I only add a pointer from A top B. The metamodel llooks like:
http://wiki.eclipse.org/images/e/e7/BusinessClassExample.png

I can link the superclass relation to one of the BusinessClasses. Then I will have multiple graphical; element referring to the same BusinessClass. This means I have to ensure that I have specif 'delete/remove' feature providers for the superclass shape to make sure that the underlying BusinessClass is not removed/deleted when I delete/remove the superclass reference. Is this the way to go ?

-- Jos
Re: How to link to non modelelements [message #551869 is a reply to message #550459] Mon, 09 August 2010 16:59 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 66
Registered: July 2009
Member
Michael en I had an offline discussion about this issue when the Eclipse forum was down. The solution is to link the line shape to the BusinessClass and use the user properties of the line shape to add information about which reference is represented by the line. This allows one to distinguish between different references as well.

Along the way we found a bug that user properties were not persisted, which is already solved by Michael in the Graphiti repository.

-- Jos
Re: How to link to non modelelements [message #561997 is a reply to message #550418] Fri, 30 July 2010 07:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1587
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Normally, connections represent references. So I would suggest to reference
the "superclass" reference as the business object of the connection as it is
done in the tutorial feature to add an ERefernce:
public PictogramElement add(IAddContext context) {

IAddConnectionContext addConContext = (IAddConnectionContext) context;

EReference addedEReference = (EReference) context.getNewObject();


IPeCreateService peCreateService = Graphiti.getPeCreateService();

// CONNECTION WITH POLYLINE

Connection connection =
peCreateService.createFreeFormConnection(getDiagram());

connection.setStart(addConContext.getSourceAnchor());

connection.setEnd(addConContext.getTargetAnchor());


IGaService gaService = Graphiti.getGaService();

Polyline polyline = gaService.createPolyline(connection);

polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram())) ;


// create link and wire it

link(connection, addedEReference);

-Michael


"Jos Warmer" <jos.warmer@ordina.nl> wrote in message
news:i2u916$6vt$1@build.eclipse.org...
>I am trying to create a visual link between two elements that does not
>refer to a metaclass, but to a reference in the metamodel.
>
> Example: I have an ecore metamodel with metaclass "BusinessClass" and a
> reference from DomainClass to itself called "superclass".
>
> I create feature providers to create and add a "BusinessClass" and link
> the shape to the model object representing the BusinessClass.
>
> Now I would like to have featureproviders to create/add the "superclass"
> reference between two existing BusinessClasses. As there is no metaclass
> representing the "superclass" (it is just a reference from one
> businessclass to another in the metamodel) I wonder how I should setup the
> Graphiti link from the "superclass" shape (a polyline) to the 'superclass
> model object, because there is no such model object.
>
> Any pointers on how to achieve this?
>
> -- Jos
Re: How to link to non modelelements [message #562062 is a reply to message #550451] Fri, 30 July 2010 08:59 Go to previous messageGo to next message
Jos Warmer is currently offline Jos Warmer
Messages: 66
Registered: July 2009
Member
Michael,

In the tutorial EReference is a real metaclass (despite its name :))..Therefore you actually create an instance of EReference, so there is a clear model element in the underlying model to which you can link.
My example is different in the sense that all the model elements (the two BusinessClasses) already exist and by adding a superclass relation I only add a pointer from A top B. The metamodel llooks like:


I can link the superclass relation to one of the BusinessClasses. Then I will have multiple graphical; element referring to the same BusinessClass. This means I have to ensure that I have specif 'delete/remove' feature providers for the superclass shape to make sure that the underlying BusinessClass is not removed/deleted when I delete/remove the superclass reference. Is this the way to go ?

-- Jos
Re: How to link to non modelelements [message #562148 is a reply to message #562062] Mon, 09 August 2010 16:59 Go to previous message
Jos Warmer is currently offline Jos Warmer
Messages: 66
Registered: July 2009
Member
Michael en I had an offline discussion about this issue when the Eclipse forum was down. The solution is to link the line shape to the BusinessClass and use the user properties of the line shape to add information about which reference is represented by the line. This allows one to distinguish between different references as well.

Along the way we found a bug that user properties were not persisted, which is already solved by Michael in the Graphiti repository.

-- Jos
Previous Topic:where to add model listeners to refresh property view
Next Topic:Validation
Goto Forum:
  


Current Time: Thu Aug 28 07:35:11 EDT 2014

Powered by FUDForum. Page generated in 0.01822 seconds