Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to execute an action after the diagram is loaded or a connection/link is deleted(execute action programatically)
How to execute an action after the diagram is loaded or a connection/link is deleted [message #893138] Mon, 02 July 2012 20:31 Go to next message
Che Bumagat is currently offline Che BumagatFriend
Messages: 46
Registered: February 2012
Member
Hi GMF Experts,

I need your help. I just like to ask how do you call an action/command after all the figures in the diagram is loaded and also call a command after you create or delete a figure.

Basically, what I would like to call is the Validate function in GMF. I want to validate the model after the diagram is loaded, a figure is created and deleted.

Is this possible? what code needs to be changed?

Thanks again!

Che
Re: How to execute an action after the diagram is loaded or a connection/link is deleted [message #893242 is a reply to message #893138] Tue, 03 July 2012 10:30 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you can override createPartControl in xxxDiagramEditor to react on the diagram opening. There you can also start listening to changes by using a ResourceSetListener.

TransactionUtil.getEditingDomain(getDiagram().getElement()).addResourceSetListener(YourResourceSetListenerImplementation)


Ralph
Re: How to execute an action after the diagram is loaded or a connection/link is deleted [message #893395 is a reply to message #893242] Tue, 03 July 2012 20:25 Go to previous messageGo to next message
Che Bumagat is currently offline Che BumagatFriend
Messages: 46
Registered: February 2012
Member
Thanks Ralph!

I was able to run Validation when the diagram opens. It works perfect.

However, for my listener implementation, I extended the ResourceSetListenerImpl and I see during runtime, when I added a new line/connection in the diagram, the method resourceSetChanged(Event) is being called 5 times. There are also different combinations of notifications in the event object.

If I put the code to call my ValidationAction here, it will be called 5x.

Would you know if there's a better way to do it? Or am I doing it incorrectly?

Basically, I'd like to call Validation everytime I create or delete a line in the diagram.

Thanks!
Che
Re: How to execute an action after the diagram is loaded or a connection/link is deleted [message #893674 is a reply to message #893395] Thu, 05 July 2012 08:20 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

you need to filter for the notification you are interested in (event.getNotifications()). You can do this by something like this:

if (notification.getNotifier() instanceof AAAA)
  execute validation;


You can also listen to changes in an EMF model via an EContentAdapter (http://wiki.eclipse.org/EMF/Recipes#Recipe:_Use_EContentAdapter_to_receive_notifications_from_a_whole_containment_tree) or by overriding the handleNotification method of you EditParts. However, these will have the same problem of getting called multiple times.

Ralph
Re: How to execute an action after the diagram is loaded or a connection/link is deleted [message #894084 is a reply to message #893674] Fri, 06 July 2012 14:55 Go to previous message
Che Bumagat is currently offline Che BumagatFriend
Messages: 46
Registered: February 2012
Member
Thanks Ralph!

Yeah, I think I'm just going to add the filters.

Thanks again for your help! Smile
Previous Topic:Difference Canvas vs. Diagram
Next Topic:complex link mapping
Goto Forum:
  


Current Time: Fri Apr 19 18:29:49 GMT 2024

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

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

Back to the top