Skip to main content


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: 83
Registered: June 2012
Location: Stockholm , Sweden
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: 31
Registered: April 2013
Location: Laval, France
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
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: 83
Registered: June 2012
Location: Stockholm , Sweden
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.



Thomas Wiman
MetaModelAgent Product Manager
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: 31
Registered: April 2013
Location: Laval, France
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
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: 83
Registered: June 2012
Location: Stockholm , Sweden
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


Thomas Wiman
MetaModelAgent Product Manager
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: 952
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
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: 83
Registered: June 2012
Location: Stockholm , Sweden
Member

Thanks Camille,

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

/Thomas


Thomas Wiman
MetaModelAgent Product Manager
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
Denes Harmath is currently offline Denes HarmathFriend
Messages: 9
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 messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
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
Re: How to listen to models being loaded? [message #1691610 is a reply to message #1623789] Wed, 08 April 2015 13:07 Go to previous message
Denes Harmath is currently offline Denes HarmathFriend
Messages: 9
Registered: August 2014
Junior Member
Thanks, Camille, this works great!
For the record, my plugin.xml looks like this:

<extension
         point="org.eclipse.papyrus.infra.core.service">
      <service
            classname="service.Service1"
            priority="1"
            startKind="startup">
         <dependsOn
               serviceKeyRef="org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor"></dependsOn>
         <dependsOn
               serviceKeyRef="org.eclipse.papyrus.infra.core.resource.ModelSet">
         </dependsOn>
      </service>
   </extension>


And the Service1 class:

	public void startService() throws ServiceException {
		ModelSet modelSet = servicesRegistry.getService(ModelSet.class);
		IMultiDiagramEditor diagramEditor = servicesRegistry.getService(IMultiDiagramEditor.class);
        }
Previous Topic:Member End in association links in Use Case Diagrams
Next Topic:Problems while installing MARTE over Payrus
Goto Forum:
  


Current Time: Fri Apr 19 01:14:42 GMT 2024

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

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

Back to the top