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 16:31 Go to next message
Che Bumagat is currently offline Che Bumagat
Messages: 31
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 06:30 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
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 16:25 Go to previous messageGo to next message
Che Bumagat is currently offline Che Bumagat
Messages: 31
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 04:20 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph Gerbig
Messages: 697
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 10:55 Go to previous message
Che Bumagat is currently offline Che Bumagat
Messages: 31
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 Jul 25 11:58:50 EDT 2014

Powered by FUDForum. Page generated in 0.03871 seconds