Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Remove a link from the model along with its source or target
Remove a link from the model along with its source or target [message #90434] Mon, 08 January 2007 08:51 Go to next message
Eclipse UserFriend
Hi,
Let A and B be two nodes linked through a link L in a diagram. If I remove
one of the two nodes from the diagram (the element related to this node is
removed from the model), only the view and not also the element of the link
L is removed (this element remains into the model). Please, can you explain
me why it happens? Once a node is removed, a link that refers to it becames
unnecessary (Is this correct?)
For a link, I would like to remove also the element from the model and not
only its view when I remove the source or the target of this link. What
should I do? Have I to modify anything?

Thanks in advance.

Best regards,
Fabio.
Re: Remove a link from the model along with its source or target [message #90496 is a reply to message #90434] Mon, 08 January 2007 10:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

In the edit helper corresponding to the model type you delete:

public abstract class EndEditHelper extends AbstractEditHelper {
/**
* Gets a command to destroy the connections incident to this block
*/
protected ICommand getDestroyDependentsCommand(
DestroyDependentsRequest request) {
End end = (End) request.getElementToDestroy();

Set ret = new HashSet();
ret.addAll(end.getOutgoingConnections());
ret.addAll(end.getIncomingConnections());

return request.getDestroyDependentsCommand(ret);
}

.....
}

You might have to do a little bit of debugging in case this method is not
called by the generated code.

-Vlad

On Mon, 08 Jan 2007 14:51:52 +0100, Fabio
Centineo wrote:

> Hi,
> Let A and B be two nodes linked through a link L in a diagram. If I remove
> one of the two nodes from the diagram (the element related to this node is
> removed from the model), only the view and not also the element of the link
> L is removed (this element remains into the model). Please, can you explain
> me why it happens? Once a node is removed, a link that refers to it becames
> unnecessary (Is this correct?)
> For a link, I would like to remove also the element from the model and not
> only its view when I remove the source or the target of this link. What
> should I do? Have I to modify anything?
>
> Thanks in advance.
>
> Best regards,
> Fabio.
Re: Remove a link from the model along with its source or target [message #90556 is a reply to message #90496] Mon, 08 January 2007 11:43 Go to previous messageGo to next message
Eclipse UserFriend
Hi Vlad,
thanks for your reply.
Unfortunately, the target node I remove doesn't know the link(s) which it
belongs to. The meta-association I use is navigable only in one direction.
Thus, I can't fill the following lines:

> ret.addAll(end.getOutgoingConnections());
> ret.addAll(end.getIncomingConnections());

When I remove the source node instead, the link(s) is removed as this node
is its container.
Have you any idea? What can I do?

Thank again.

Regards,
Fabio.


"Vlad Ciubotariu" <vcciubot@uwaterloo.ca> ha scritto nel messaggio
news:pan.2007.01.08.15.33.28.258293@uwaterloo.ca...
> In the edit helper corresponding to the model type you delete:
>
> public abstract class EndEditHelper extends AbstractEditHelper {
> /**
> * Gets a command to destroy the connections incident to this block
> */
> protected ICommand getDestroyDependentsCommand(
> DestroyDependentsRequest request) {
> End end = (End) request.getElementToDestroy();
>
> Set ret = new HashSet();
> ret.addAll(end.getOutgoingConnections());
> ret.addAll(end.getIncomingConnections());
>
> return request.getDestroyDependentsCommand(ret);
> }
>
> ....
> }
>
> You might have to do a little bit of debugging in case this method is not
> called by the generated code.
>
> -Vlad
>
> On Mon, 08 Jan 2007 14:51:52 +0100, Fabio
> Centineo wrote:
>
>> Hi,
>> Let A and B be two nodes linked through a link L in a diagram. If I
>> remove
>> one of the two nodes from the diagram (the element related to this node
>> is
>> removed from the model), only the view and not also the element of the
>> link
>> L is removed (this element remains into the model). Please, can you
>> explain
>> me why it happens? Once a node is removed, a link that refers to it
>> becames
>> unnecessary (Is this correct?)
>> For a link, I would like to remove also the element from the model and
>> not
>> only its view when I remove the source or the target of this link. What
>> should I do? Have I to modify anything?
>>
>> Thanks in advance.
>>
>> Best regards,
>> Fabio.
>
Re: Remove a link from the model along with its source or target [message #90619 is a reply to message #90556] Mon, 08 January 2007 12:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vcciubot.uwaterloo.ca

Why don't you model the inverse reference in you metamodel? EMF maintains
the inverse for free, you only have to declare it in your ecore file.

vlad

On Mon, 08 Jan 2007 17:43:17 +0100, Fabio Centineo wrote:

> Hi Vlad,
> thanks for your reply.
> Unfortunately, the target node I remove doesn't know the link(s) which it
> belongs to. The meta-association I use is navigable only in one direction.
> Thus, I can't fill the following lines:
>
>> ret.addAll(end.getOutgoingConnections());
>> ret.addAll(end.getIncomingConnections());
>
> When I remove the source node instead, the link(s) is removed as this node
> is its container.
> Have you any idea? What can I do?
>
> Thank again.
>
> Regards,
> Fabio.
>
>
> "Vlad Ciubotariu" <vcciubot@uwaterloo.ca> ha scritto nel messaggio
> news:pan.2007.01.08.15.33.28.258293@uwaterloo.ca...
>> In the edit helper corresponding to the model type you delete:
>>
>> public abstract class EndEditHelper extends AbstractEditHelper {
>> /**
>> * Gets a command to destroy the connections incident to this block
>> */
>> protected ICommand getDestroyDependentsCommand(
>> DestroyDependentsRequest request) {
>> End end = (End) request.getElementToDestroy();
>>
>> Set ret = new HashSet();
>> ret.addAll(end.getOutgoingConnections());
>> ret.addAll(end.getIncomingConnections());
>>
>> return request.getDestroyDependentsCommand(ret);
>> }
>>
>> ....
>> }
>>
>> You might have to do a little bit of debugging in case this method is not
>> called by the generated code.
>>
>> -Vlad
>>
>> On Mon, 08 Jan 2007 14:51:52 +0100, Fabio
>> Centineo wrote:
>>
>>> Hi,
>>> Let A and B be two nodes linked through a link L in a diagram. If I
>>> remove
>>> one of the two nodes from the diagram (the element related to this node
>>> is
>>> removed from the model), only the view and not also the element of the
>>> link
>>> L is removed (this element remains into the model). Please, can you
>>> explain
>>> me why it happens? Once a node is removed, a link that refers to it
>>> becames
>>> unnecessary (Is this correct?)
>>> For a link, I would like to remove also the element from the model and
>>> not
>>> only its view when I remove the source or the target of this link. What
>>> should I do? Have I to modify anything?
>>>
>>> Thanks in advance.
>>>
>>> Best regards,
>>> Fabio.
>>
Re: Remove a link from the model along with its source or target [message #90803 is a reply to message #90496] Tue, 09 January 2007 05:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tobk.gmx.de

Hello,

I had the same problem some time ago and solved it (thanks to this ng!).

Here some additions:

1.: I encountered problems in GMF1.0. In GMF2M2 now[1] everything works
well.

I also did some changes on some other methods (maybe redundant or bad style,
but IIRC it didn't work without these).

2.: in getInsteadCommand (the second line is for fixing another problem) :
//return eh command only
if (req instanceof DestroyElementRequest
|| req instanceof ReorientRelationshipRequest) {
return ehCommand;
}
I do not know exactly why, but without this there are problems with undo
(and reconnecting does not work). Maybe because of the wrapper, or because
the ep's command might be an UnexecutableCommand or so... ask the
professionals *g*

3.: further I made the edit helper's getDestroyCommand return super instead
of null:
protected ICommand getDestroyElementCommand(DestroyElementRequest req) {
return super.getDestroyElementCommand(req);
}
Without this it didn't work at all.

I put all the changes in the BaseEdithelper, with a little distinguishing
if-query. In case you have several types of nodes this might save you from
some code-duplication.

Tobias

[1] Yes, still stuck with M2. Somehow the new milestones don't move me to
changing yet. I'll wait for the final.


Vlad Ciubotariu wrote:
> In the edit helper corresponding to the model type you delete:
>
> public abstract class EndEditHelper extends AbstractEditHelper {
> /**
> * Gets a command to destroy the connections incident to this block
> */
> protected ICommand getDestroyDependentsCommand(
> DestroyDependentsRequest request) {
> End end = (End) request.getElementToDestroy();
>
> Set ret = new HashSet();
> ret.addAll(end.getOutgoingConnections());
> ret.addAll(end.getIncomingConnections());
>
> return request.getDestroyDependentsCommand(ret);
> }
>
> ....
> }
>
> You might have to do a little bit of debugging in case this method is not
> called by the generated code.
>
> -Vlad
>
> On Mon, 08 Jan 2007 14:51:52 +0100, Fabio
> Centineo wrote:
>
>> Hi,
>> Let A and B be two nodes linked through a link L in a diagram. If I
>> remove one of the two nodes from the diagram (the element related to this
>> node is
>> removed from the model), only the view and not also the element of the
>> link L is removed (this element remains into the model). Please, can you
>> explain me why it happens? Once a node is removed, a link that refers to
>> it becames unnecessary (Is this correct?)
>> For a link, I would like to remove also the element from the model and
>> not only its view when I remove the source or the target of this link.
>> What should I do? Have I to modify anything?
>>
>> Thanks in advance.
>>
>> Best regards,
>> Fabio.
Re: Remove a link from the model along with its source or target [message #91149 is a reply to message #90803] Wed, 10 January 2007 09:47 Go to previous message
Eclipse UserFriend
Hi tobias,
thanks for your help.
Unfortunately, I'm still using GMF 1.0 :-( and I will attend next July for
GMF 2.0.
Thus, we had to find another solution for our problem (listed below) but it
is a bit more overloaded.

//this method returns all cross references between my model elements
Map map = CrossReferencer.find(model.getModelElements());

//from the above map I get all cross references interested by the element I
want to remove
ArrayList values = (ArrayList) map.get(eObject);

// Create a list of the links I want to remove
List<Object> links = new ArrayList<Object>();
for(int i=0; i<values.size(); i++)
{
if(values.get(i) instanceof DerivedUnionEObjectEList)
{
DerivedUnionEObjectEList derived = (DerivedUnionEObjectEList)
values.get(i);
if(derived.getEObject() instanceof //link type for which I'm
lookink for)
{
if(!links.contains(derived.getEObject()))
links.add(derived.getEObject());
}
}
}

At last I remove through a CompositeCommand all the objects contained in the
above list.
We have tryed this procedure and it works very well.
Surely, when we change our GMF version a we will need to do a lot of work
:-(.

Thanks again.

Regards,
Fabio.



"tobias" <tobk@gmx.de> ha scritto nel messaggio
news:envr17$b3v$1@utils.eclipse.org...
> Hello,
>
> I had the same problem some time ago and solved it (thanks to this ng!).
>
> Here some additions:
>
> 1.: I encountered problems in GMF1.0. In GMF2M2 now[1] everything works
> well.
>
> I also did some changes on some other methods (maybe redundant or bad
> style,
> but IIRC it didn't work without these).
>
> 2.: in getInsteadCommand (the second line is for fixing another problem) :
> //return eh command only
> if (req instanceof DestroyElementRequest
> || req instanceof ReorientRelationshipRequest) {
> return ehCommand;
> }
> I do not know exactly why, but without this there are problems with undo
> (and reconnecting does not work). Maybe because of the wrapper, or because
> the ep's command might be an UnexecutableCommand or so... ask the
> professionals *g*
>
> 3.: further I made the edit helper's getDestroyCommand return super
> instead
> of null:
> protected ICommand getDestroyElementCommand(DestroyElementRequest req) {
> return super.getDestroyElementCommand(req);
> }
> Without this it didn't work at all.
>
> I put all the changes in the BaseEdithelper, with a little distinguishing
> if-query. In case you have several types of nodes this might save you from
> some code-duplication.
>
> Tobias
>
> [1] Yes, still stuck with M2. Somehow the new milestones don't move me to
> changing yet. I'll wait for the final.
>
>
> Vlad Ciubotariu wrote:
>> In the edit helper corresponding to the model type you delete:
>>
>> public abstract class EndEditHelper extends AbstractEditHelper {
>> /**
>> * Gets a command to destroy the connections incident to this block
>> */
>> protected ICommand getDestroyDependentsCommand(
>> DestroyDependentsRequest request) {
>> End end = (End) request.getElementToDestroy();
>>
>> Set ret = new HashSet();
>> ret.addAll(end.getOutgoingConnections());
>> ret.addAll(end.getIncomingConnections());
>>
>> return request.getDestroyDependentsCommand(ret);
>> }
>>
>> ....
>> }
>>
>> You might have to do a little bit of debugging in case this method is not
>> called by the generated code.
>>
>> -Vlad
>>
>> On Mon, 08 Jan 2007 14:51:52 +0100, Fabio
>> Centineo wrote:
>>
>>> Hi,
>>> Let A and B be two nodes linked through a link L in a diagram. If I
>>> remove one of the two nodes from the diagram (the element related to
>>> this
>>> node is
>>> removed from the model), only the view and not also the element of the
>>> link L is removed (this element remains into the model). Please, can you
>>> explain me why it happens? Once a node is removed, a link that refers to
>>> it becames unnecessary (Is this correct?)
>>> For a link, I would like to remove also the element from the model and
>>> not only its view when I remove the source or the target of this link.
>>> What should I do? Have I to modify anything?
>>>
>>> Thanks in advance.
>>>
>>> Best regards,
>>> Fabio.
>
Previous Topic:Integrating GMf Editor in Other Plugins' Editor.
Next Topic:Strange Behaviour of GMF M4
Goto Forum:
  


Current Time: Mon May 12 22:26:48 EDT 2025

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

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

Back to the top