Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Getting a ServiceRegistry for an EMF Resource
Getting a ServiceRegistry for an EMF Resource [message #1455873] Wed, 29 October 2014 21:11 Go to next message
Bérenger Dulac is currently offline Bérenger DulacFriend
Messages: 2
Registered: January 2014
Junior Member
My objective is to attach a ResourceSetListener to Papyrus TransactionalEditDomain. I read the available documentation on the topic.

I concluded that I needed a ServiceRegistry to get a TransactionalEditDomain.

I try to get a ServiceRegistry for an EMF resource using a ServiceUtilsForResource:

Here is the code:
ServiceUtilsForResource serviceUtils = ServiceUtilsForResource.getInstance();

serviceUtils.getServiceRegistry(emfResource());


I got the following exception message (ServiceNotFoundException):
The resource set was not initialized as a service.


I guess the ResourceSet attached to the EMF Resource was not built the proper way.

I have two problems here:


  • How to create properly a ResourceSet (recognized by Papyrus) ?
  • Is my approach correct for getting the TransactionalEditDomain of a Papyrus editor from an external plugin ?
Re: Getting a ServiceRegistry for an EMF Resource [message #1456869 is a reply to message #1455873] Thu, 30 October 2014 20:22 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1206
Registered: July 2009
Location: Canada
Senior Member

Hi,

The TransactionUtil class should help you to get the (transactional)
editing domain of an EObject or Resource.

You will generally only find a service registry associated with an
editing domain when that editing domain is constructed by the service
registry. That is to say, the service registry exists a priori.
Generally speaking, the only thing that ever creates a service registry
is the Papyrus editor (some other transient registries my be created
here and there, such as in the Model Search user interface, but they
aren't interesting).

You ask how to properly create a resource set. Why are you creating a
resource set? What kind of extension are you building on Papyrus that
doesn't use the resource set of the Papyrus editor?

HTH,

Christian


On 2014-10-30 12:53:49 +0000, Bérenger Bérenger said:

> My objective is to attach a ResourceSetListener to Papyrus
> TransactionalEditDomain. I read the
> https://wiki.eclipse.org/Papyrus_Developer_Guide/Editing_Domains_and_Commands
> on the topic.
>
> I concluded that I needed a ServiceRegistry to get a TransactionalEditDomain.
>
> I try to get a ServiceRegistry for an EMF resource using a
> http://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.papyrus/trunk/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResource.java:
>
>
> Here is the code:
> ServiceUtilsForResource serviceUtils = ServiceUtilsForResource.getInstance();
>
> serviceUtils.getServiceRegistry(emfResource());
>
>
> I got the following exception message (ServiceNotFoundException):
>
> The resource set was not initialized as a service.
>
>
> I guess the ResourceSet attached to the EMF Resource was not built the
> proper way.
>
> I have two problems here:
>
> How to create properly a ResourceSet (recognized by Papyrus) ?
> Is my approach correct for getting the TransactionalEditDomain of a
> Papyrus editor from an external plugin ?
Re: Getting a ServiceRegistry for an EMF Resource [message #1457975 is a reply to message #1456869] Fri, 31 October 2014 22:54 Go to previous messageGo to next message
Bérenger Dulac is currently offline Bérenger DulacFriend
Messages: 2
Registered: January 2014
Junior Member
Thank you for your answer.

I have an UML model which elements are linked to Java elements (generated by my own plugin). I try to propagate changes applied on the model with JDT refactorings (mainly renaming). Initially the project used Eclipse UML2Tools which seems to be discontinued for years (I have been quite busy lately and my plugin needs to be refactored).

I adapt my plugin to work with other editors. Papyrus by the way it the new editor supported by the Eclipse foundation.

I noticed that modifications on the UML model using the UML2 tree editor are propagated in the Papyrus class diagram editor, and vice-versa. I thought that changes where propagated by a ResourceSetListener.

This seems to the best approach. At first glance it seems to remove a direct dependency on the editor used to edit the model. For that I need the TransactionalEditDomain. Following the Javadoc, I first thought that the TransactionalEditDomain should be available via the Registry (this seems to be the preferred web for sharing the edit domain with other applications).

I did not found the Papyrus TransactionalEditDomain in the Registry. So I had a look at the ServiceRegistry.

But as I understand, it is not possible to get the TransactionalEditDomain without an access on the editor. The ServiceRegistry holds the TransactionalEditDomain and it is linked with the Papyrus editor.

So I should generate programmatically the Papyrus diagram file from my UML model, open an editor and retrieve the TransactionalEditingDomain from that editor ? Is there no simpler way for getting the TransactionalEditingDomain ? The process for generating the diagram file seems to be rather complex...

I must be missing something: how are changes propagated between the Papyrus editor and the UML2 tree editor ?

[Updated on: Sat, 01 November 2014 21:47]

Report message to a moderator

Re: Getting a ServiceRegistry for an EMF Resource [message #1464032 is a reply to message #1457975] Fri, 07 November 2014 05:30 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1206
Registered: July 2009
Location: Canada
Senior Member

Hi,

A ResourceSetListener is intended for reacting to changes in the UML
model, but it seems that you want to change the model according to
refactorings of Java code. So ResourceSetListener doesn't really enter
the picture.

If you know which are the UML model resource that needs to be updated
for the Java refactoring, then you can (a) check whether there is
currently a Papyrus editor open on that resource and (b) if so, access
its service registry (the editor provides an adapter of type
ServicesRegistry via the IAdaptable protocol) or (c) if an editor is
not open, just load the resource in a simple ResourceSet and modify it.
No need for any TransactionalEditingDomains or editors in that case.

HTH,

Christian


On 2014-10-31 22:54:26 +0000, Bérenger Bérenger said:

> Thank you for your answer.
>
> I have an UML model which elements are linked to Java elements. I try
> to propagate change applied on the model with JDT refactorings (mainly
> renaming). Initially the project used Eclipse UML2Tools which seems to
> be discontinued for years (I have been quite busy lately and my plugin
> needs to be refactored).
>
> I adapt my plugin to work with other editors. Papyrus by the way it the
> new editor supported by the Eclipse foundation. The best approach
> seems to be a ResourceSetListener. At first glance it seems to remove a
> direct dependency on the editor used on the model. For that I need the
> TransactionalEditDomain. Following
> http://download.eclipse.org/modeling/emf/transaction/javadoc/1.1.1/org/eclipse/emf/transaction/TransactionalEditingDomain.html,
> I first thought that the TransactionalEditDomain should be available
> via the Registry (this seems to be the preferred web for sharing the
> edit domain with other applications).
>
> I noticed that modifications on the UML model in the UML2 tree editor
> propagates changes in the Papyrus class diagram editor, and vice-versa.
> I thought that changes where propagated by such a listener.
>
> But as I understand, this is not possible to get the
> TransactionalEditDomain without an access on the editor. The
> ServiceRegistry holds the TransactionalEditDomain and it is linked with
> the Papyrus editor.
>
> So I should generate programmatically the Papyrus diagram file from my
> UML model, open an editor and retrieve the TransactionalEditingDomain
> from that editor ? Is there no simpler way for getting it ? The process
> for generating the diagram file seems to be rather complex...
Previous Topic:Unable to install Moka.
Next Topic:No Model Explorer Window
Goto Forum:
  


Current Time: Wed Jul 15 12:46:09 GMT 2020

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

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

Back to the top