Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to create relationships such as eSuperTypes
How to create relationships such as eSuperTypes [message #634268] Thu, 21 October 2010 05:05 Go to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi there,

The graphiti tutorial shows how to create features for EClass and EReference by adding for each one, PE and BO in the diagram file.

My question is:

Is it possible to create in a similar way relationships such as the eSuperTypes relationship among two EClasses?

(look here -> http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/o rg/eclipse/emf/ecore/package-summary.html)

Indeed, I would like to:

1) define in my diagram a PE-eSuperType relationship representing a BO-eSuperType relationship among two (PE- and) BO-EClasses.

2) change the corresponding BO-EClasses ' attriibutes to store the BO-eSuperType relationship, e.g., the BO-Eclass father has its "isSuperClassOf" attribute containing all the BO-EClasses sons.

3) delete the PE-eSuperType relationship among two PE-EClasses and remove from the corresponding BO-EClasses attributes the values representing the BO-eSuperType relationship, e.g., from the BO-EClass father "IsSuperClassOf" attribute I want to delete the corresponding BO-EClass son.

In some way, I did the 1) and 2) but I have some problem with the 3) point.

Indeed, I am using an instruction similar to:

link (PE-eSuperType_Releationship, new Object []{BO-EClassFather,BO- EClassSon} )

When I delete the PE-eSuperType_Rreleationship from the diagram the two PE (and BO) are also deleted, which is not what I want.

I would like to eliminate just the PE-eSuperType_Releationship and propagate such a change only to the corresponding BO-EClasses father and son attributes to reflect such a deletion.

Obviously, I am just using the tutorial example to explain my issue; but if you have an example on how to do that I will able to customize it for my project.

Thanks in advance for any suggestions
Daniele

[Updated on: Thu, 21 October 2010 05:06]

Report message to a moderator

Re: How to create relationships such as eSuperTypes [message #634280 is a reply to message #634268] Thu, 21 October 2010 06:44 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
The Graphiti default delete works like this: it finds all links for the PE
in the diagram. Then it deletes all the BO that are target of the founds
links. That's why delete of the supertype relationship PE also deletes the
tow BO classes.

In order to change that you can implement your own delete feature for the
supertype relation. It needs to be returned in the feature providers
getDeleteFeature method for connections of this type and would analyse in
its delete method the links and only delete the relation (update the
references and attributes involved) but not the two linked classes. To
actually update the diagram and remove the connection from it you can still
use the default remove feature provided by the framework (see the
implementation of DefaultDeleteFeature how to do that).

Michael


"Daniele" <barone.daniele@gmail.com> wrote in message
news:i9ohgu$rvg$1@news.eclipse.org...
> Hi there,
> The graphiti tutorial shows how to create features for EClass and
> EReference by adding for each one, PE and BO in the diagram file.
>
> My question is:
>
> Is is possible to create in a similar way relationships such as the
> eSuperTypes relationship among two EClasses?
>
> (look here ->
> http://download.eclipse.org/modeling/emf/emf/javadoc/2.6.0/o rg/eclipse/emf/ecore/package-summary.html)
>
> Indeed, I would like to:
>
> 1) define in my diagram a PE-eSuperType relationship representing a
> BO-eSuperType relationship among two (PE- and) BO-EClasses.
> 2) change the corresponding BO-EClasses ' attriibutes to store the
> BO-eSuperType relationship, e.g., the BO-Eclass father has its
> "isSuperClassOf" attribute containing all the BO-EClasses sons.
>
> 3) delete the PE-eSuperType relationship among two PE-EClasses and remove
> from the corresponding BO-EClasses attributes the values representing the
> BO-eSuperType relationship, e.g., from the BO-EClass father
> "IsSuperClassOf" attribute I want to delete the corresponding BO-EClass
> son.
>
> In some way, I did the 1) and 2) but I have some problem with the 3)
> point.
>
> Indeed, I am using an instruction similar to:
>
> link (PE-eSuperType_Releationship, new Object []{BO-EClassFather,BO-
> EClassSon} )
>
> When I delete the PE-eSuperType_Rreleationship from the diagram the two PE
> (and BO) are also deleted, which is not what I want.
>
> I would like to eliminate just the PE-eSuperType_Releationship and
> propagate such a change only to the corresponding BO-EClasses father and
> son attributes to reflect such a deletion.
>
> Obviously, I am just using the tutorial example to explain my issue; but
> if you have an example on how to do that I will able to customize it for
> my project.
>
> Thanks in advance for any suggestions
> Daniele
Re: How to create relationships such as eSuperTypes [message #634511 is a reply to message #634280] Fri, 22 October 2010 03:28 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Michael,
thank you very much for your answer which I am trying to implement.

Actually, I have a problem with the getDeleteFeature which will allow me to call my own DeleteXXXFeature().
Indeed, I don't know how to understand (using the IDeleteContext parameter) which is the PE relationship I am deleting since no BO is associated to such a PE relationship (in fact in the corresponding createMyRelationshipFeature I am not using the "addContext.newObject(BO)" instruction since I have not any BO to attach).

Therefore, to do the job in the getAddFeature, I used the IAddConnectionContext as described below (mainly, I checked the type of the BOs associated to the PE source and PE target of the relationship), but for the getDeleteFeature there is not any similar class, e.g., IDeleteConnectionContext.


Thank you for your help Michael
Daniele



@Override
public IAddFeature getAddFeature(IAddContext context) {
...
EClass source=null;
EClass target=null;
IAddConnectionContext addConContext=null;

// Check if I am adding a relationship
if(context instanceof IAddConnectionContext){
addConContext = (IAddConnectionContext) context;
source= getEClass(addConContext.getSourceAnchor());
target = getEClass(addConContext.getTargetAnchor());

}

// Note: EClass is a superclass of EClassType1
// Check if I am adding a EClassType1
if (context.getNewObject() instanceof EClassType1) {
return new AddEClassType1Feature(this);
}
// Check if I am adding a EClassType2
else if (context.getNewObject() instanceof EClassType2) {
return new AddEClassType2Feature(this);
}
// Check if I am adding a relationship among EClassType1 and EClassType2, e.g. a eSuperType
else if( source instanceof EClassType1 && target instanceof EClassType2){

return new AddMyRelationshipFeature(this);
}
...
}

@Override
public IDeleteFeature getDeleteFeature(IDeleteContext context) {
...
// Check if I am deleting a relationship
if(context instanceof IDeleteConnectionContext){
...but there is not any IDeleteConnectionContext
}

}

[Updated on: Fri, 22 October 2010 03:38]

Report message to a moderator

Re: How to create relationships such as eSuperTypes [message #634959 is a reply to message #634511] Mon, 25 October 2010 08:51 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I hope I understood your problem correctly. Here's my try to solve this:

Instead of using the linking mechanism to identify your BO for the
connection (which is not existing), you might use the anchors of the
connection and their parent PEs (in case they are linked to a BO) to
identify the BOs for the connection ends. From there you should be able to
identify what the connection represents.

Michael

"Daniele" <barone.daniele@gmail.com> wrote in message
news:i9r066$kcq$1@news.eclipse.org...
> Hi Michael,
> thank you very much for your answer which I am trying to implement.
>
> Actually, I have a problem with the getDeleteFeature which will allow me
> to call my own DeleteXXXFeature().
> Indeed, I don't know how to understand (using the IDeleteContext
> parameter) which is the PE relationship I am deleting since no BO is
> associated to such a PE relationship (in fact in the corresponding
> createMyRelationshipFeature I am not using the "addContext.newObject(BO)"
> instruction since I have not any BO to attach).
>
> Therefore, to do the job in the getAddFeature, I used the
> IAddConnectionContext as described below, but for the getDeleteFeature
> there is not any similar class, e.g., IDeleteConnectionContext.
>
>
> Thank you for your help Michael
> Daniele
>
>
>
> @Override
> public IAddFeature getAddFeature(IAddContext context) {
> ...
> EClass source=null;
> EClass target=null;
> IAddConnectionContext addConContext=null;
>
> // Check if I am adding a relationship
> if(context instanceof IAddConnectionContext){
> addConContext = (IAddConnectionContext) context;
> source= getEClass(addConContext.getSourceAnchor());
> target = getEClass(addConContext.getTargetAnchor());
>
> }
>
> // Note: EClass is a superclass of EClassType1
> // Check if I am adding a EClassType1 if
> (context.getNewObject() instanceof EClassType1) {
> return new AddEClassType1Feature(this);
> }
> // Check if I am adding a EClassType2 else if
> (context.getNewObject() instanceof EClassType2) {
> return new AddEClassType2Feature(this);
> }
> // Check if I am adding a relationship among EClassType1 and EClassType2,
> e.g. a eSuperType
> else if( source instanceof EClassType1 && target instanceof EClassType2){
>
> return new AddMyRelationshipFeature(this);
> }
> ...
> }
>
> @Override
> public IDeleteFeature getDeleteFeature(IDeleteContext context) {
> ...
> // Check if I am deleting a relationship
> if(context instanceof IDeleteConnectionContext){
> ...but there is not any IDeleteConnectionContext
> }
>
> }
>
>
Re: How to create relationships such as eSuperTypes [message #635061 is a reply to message #634959] Mon, 25 October 2010 14:48 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Michael,

thank you for your continued and efficient support.

What you suggested is exactly what I am trying to do Sad

In fact, in the code I posted previously, I adopted such a solution in the getAddFeature (IAddContext context) where:

if the IAddContext context is a normal PE I just use the context to select the correct addPEXXFeature(this) by relying on the command INSTANCEOF

if the IAddContext context is an INSTANCEOF IAddConnectionContext, I know that I am adding a connection, therefore I can convert the IAddContext context in a addConContext = (IAddConnectionContext) context in order to use the getSourceAnchor and getTargetAnchor methods provided by the IAddConnectionContext class, and implement the solution you suggested.


Now, I want to do the same for the getDeleteFeature (IDeleteContext context) but since there is not a IDeleteConnectionContex class provided by graphiti, I don't know how to distinguish a PE context from a Connection context, in order to have for the latter the two methods getTargetAnchor and getSourceAnchor that I need to select and call the correct addConnectionXXFetaure method.

I hope to this more clear now Sad
Thanks
Daniele

[Updated on: Mon, 25 October 2010 14:51]

Report message to a moderator

Re: How to create relationships such as eSuperTypes [message #635150 is a reply to message #635061] Mon, 25 October 2010 18:38 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Micheal,

I opted to use:


if(context.getPictogramElement() instanceof FreeFormConnection){
FreeFormConnection connection = (FreeFormConnection)context.getPictogramElement();

source= getEClass(connection.getStart());
target = getEClass(connection.getEnd());

};

and it seems to work

Michael really thanks for your help

You guys are doing a terrific job with this framework

Daniele
p.s. maybe, it could be useful to have in the graphiti framwork an interface IDeleteConnectionContext ( similar to what you have defined for the IAddConnectionContext)
Re: How to create relationships such as eSuperTypes [message #635250 is a reply to message #635150] Tue, 26 October 2010 07:48 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
That's actually what I meant to do. Sorry if I didn't state it that
clearly...

Thanks for the suggestion, we will spend some thoughs on that.

Michael


"Daniele" <barone.daniele@gmail.com> wrote in message
news:ia4ik6$en2$1@news.eclipse.org...
> Hi Micheal,
> I opted to use:
>
>
> if(context.getPictogramElement() instanceof FreeFormConnection){
> FreeFormConnection connection =
> (FreeFormConnection)context.getPictogramElement();
>
> source= getEClass(connection.getStart());
> target = getEClass(connection.getEnd());
>
> };
>
> and it seems to work
>
> Michael really thanks for your help
>
> You guys are doing a terrific job with this framework
>
> Daniele
> p.s. maybe, it could be useful to have in the graphiti framwork an
> interface IDeleteConnectionContext ( similar to what you have defined for
> the IAddConnectionContext)
>
Re: How to create relationships such as eSuperTypes [message #635371 is a reply to message #635250] Tue, 26 October 2010 15:18 Go to previous message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Thanks to you Michael
Daniele
Previous Topic:Adding an action to context menu
Next Topic:Adding an action to context menu
Goto Forum:
  


Current Time: Sun Mar 29 20:49:37 GMT 2020

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

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

Back to the top