Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to listen to models being loaded?
How to listen to models being loaded? [message #1406934] Mon, 11 August 2014 13:20 Go to next message
Thomas Wiman is currently offline Thomas WimanFriend
Messages: 12
Registered: June 2012
Junior Member
What is the proper way to, from a plug-in, listen to and act upon a model being loaded in Papyrus 1.0, e.g. opened in the Model Explorer.
I assume there is some way to register a listener on models being loaded, but I cannot find the proper way to do so by studying the Papyrus source code.

Thanks in advance,
Thomas
Re: How to listen to models being loaded? [message #1406952 is a reply to message #1406934] Mon, 11 August 2014 13:59 Go to previous messageGo to next message
Gabriel Pascual is currently offline Gabriel PascualFriend
Messages: 19
Registered: April 2013
Location: Laval, France
Junior Member
Hi,

I think you can look IPapyrusListener to use with the extension point:
org.eclipse.papyrus.infra.core.modellistener


Regards

Gabriel


Software Development Engineer
ALL4TEC
Re: How to listen to models being loaded? [message #1406978 is a reply to message #1406952] Mon, 11 August 2014 15:22 Go to previous messageGo to next message
Thomas Wiman is currently offline Thomas WimanFriend
Messages: 12
Registered: June 2012
Junior Member
Thanks for the quick answer but I get no notifications on model opening/loading.

I have implemented the IPapyrusListener interface and registered it into the org.eclipse.papyrus.infra.core.modellistener extension.
It will give me a lot of notifications when things are happening in a loaded model, but NOT any notification on the actual opening/loading of the model.
If I have an empty model without any profile applications, the registered listener will not give me any notifications at all when the model is opened/loaded.

Re: How to listen to models being loaded? [message #1406985 is a reply to message #1406978] Mon, 11 August 2014 15:44 Go to previous messageGo to next message
Gabriel Pascual is currently offline Gabriel PascualFriend
Messages: 19
Registered: April 2013
Location: Laval, France
Junior Member
My second solution is to use IModeSnippet which is defined with the extension point :
org.eclipse.papyrus.infra.core.model

To illustrate how use it, there is UmlSnippet. I think this is performed at model loading.

Regards

Gabriel


Software Development Engineer
ALL4TEC
Re: How to listen to models being loaded? [message #1407271 is a reply to message #1406985] Tue, 12 August 2014 08:25 Go to previous messageGo to next message
Thomas Wiman is currently offline Thomas WimanFriend
Messages: 12
Registered: June 2012
Junior Member
Your second solution worked!
I am able to get hold of the model being loaded by implementing the IModelSnippet interface and using the proposed extension point.

Thanks!

/Thomas
Re: How to listen to models being loaded? [message #1409504 is a reply to message #1407271] Mon, 18 August 2014 09:20 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 602
Registered: February 2011
Senior Member
Hi Thomas,

Startup services might be more appropriate, as you can add dependencies, especially to the IMultiDiagramEditor service.

Models/ModelSnippets will be called for each model loaded in memory, which isn't necessarily related to opening an editor. For example, when using the Model Search on the workspace, models are loaded in-memory but not opened in an editor.

So, registering a startup service (via the org.eclipse.papyrus.infra.core.services extension point) with a dependency to the editor service (org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor) is probably the most reliable solution

Regards,
Camille


Camille Letavernier
Papyrus developer
Re: How to listen to models being loaded? [message #1410706 is a reply to message #1409504] Thu, 21 August 2014 12:30 Go to previous messageGo to next message
Thomas Wiman is currently offline Thomas WimanFriend
Messages: 12
Registered: June 2012
Junior Member
Thanks Camille,

Your solution works fine and probably even better than the previous one.

/Thomas
Re: How to listen to models being loaded? [message #1622812 is a reply to message #1410706] Wed, 18 February 2015 19:17 Go to previous messageGo to next message
Dénes Harmath is currently offline Dénes HarmathFriend
Messages: 2
Registered: August 2014
Junior Member
Hi all,
can you tell me how you can get the opened ModelSet from the startup service?
Thanks in advance!
Re: How to listen to models being loaded? [message #1623789 is a reply to message #1622812] Thu, 19 February 2015 10:24 Go to previous message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 602
Registered: February 2011
Senior Member
Hi,

When you implement the IService interface in Papyrus, you have the init() method which receives the current ServicesRegistry.

The ModelSet is registered as a service in the ServicesRegistry, so you can use the following code:

private ServicesRegistry servicesRegistry;

@Override
public void init(ServicesRegistry servicesRegistry) {
	this.servicesRegistry = servicesRegistry;		
}

@Override
public void startService() throws ServiceException {
	ModelSet modelSet = servicesRegistry.getService(ModelSet.class); //Get the ModelSet service from the ServicesRegistry
	//Do something
}


Don't forget to add a dependency between your service and the ModelSet (This can be done in the service extension point)

Regards,
Camille


Camille Letavernier
Papyrus developer
Previous Topic:Code generation building a plugin (help and advise)
Next Topic:State machine execution in Moka
Goto Forum:
  


Current Time: Mon Mar 30 13:07:44 GMT 2015

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

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