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 |
Daniele 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 |
Michael Wenz Messages: 1931 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 |
Daniele 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 |
Michael Wenz Messages: 1931 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 |
Daniele 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
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
Thanks
Daniele
[Updated on: Mon, 25 October 2010 14:51] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Wed Sep 25 10:13:40 GMT 2024
Powered by FUDForum. Page generated in 0.03616 seconds
|