Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Rename in EObject creates new Diagram
Rename in EObject creates new Diagram [message #1726684] Tue, 15 March 2016 17:12 Go to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
When using the rename option in the XtextEditor, for an EObject that is used to open a diagram, the reference to the diagram is lost. The old diagram can no longer be found since the uri of the object is changed. It looks like i need to extend the rename functionality to also rename the resources in sirius.
Is this the correct solution? has anyone done this before?

[Updated on: Tue, 15 March 2016 17:13]

Report message to a moderator

Re: Rename in EObject creates new Diagram [message #1726784 is a reply to message #1726684] Wed, 16 March 2016 13:28 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Koen,

I have already encountered this kind of issue, but before a little
question :

Do you share a same ResourceSet instance between your Xtext editor and
Sirius editor? if it is not the case, this can be done using
"org.eclipse.sirius.common.xtext" integration plugin.

After that to manage refactoring in XText editor, you must provide your
own refactoring participant or customize one provided by XText.
This refactoring participant will update the references of impacted
EObjects, i.e. EObjects referencing the renamed EObject.
If the referencing EObject is an EMF proxy, you can simply update the
proxy URI.

This is due to fact that XText parse again the textual result of your
change and create a new EObject to replace the old one, instead of
update only the impacted EObject feature.

Best Regards.

Le 15/03/2016 18:12, Koen Staal a écrit :
> When using the rename option in the XtextEditor, for a EObject that is
> used to open a diagram, the reference to the diagram is lost. The old
> diagram can no longer be found since the uri of the object is changed.
> It looks like i need to extend the rename functionality to also rename
> the resources in sirius.
> Is this the correct solution? has anyone done this before?



--
Esteban Dugueperoux - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Rename in EObject creates new Diagram [message #1726869 is a reply to message #1726784] Thu, 17 March 2016 07:58 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
Hi, thanks for your response

I am using the "org.eclipse.sirius.common.xtext" integration plugin. It uses XtextResourceSetFactory in it to create a new instance of a XtextResourceSet., called from SessionFactoryImp.createSession.r83. It seems that Sirius and Xtext not use the same ResourceSet instance.

I always got the correct eobject in the sirius resourceset to open the diagram by using the object uri, which now has changed.
EObject object = session.getTransactionalEditingDomain().getResourceSet().getEObject(EcoreUtil.getURI(target),false);

(In xtext the refactor only sets the name attribute of the Eobject which is an EKey.)


Is the xtext and sirius integration setup correct?





[Updated on: Thu, 17 March 2016 08:00]

Report message to a moderator

Re: Rename in EObject creates new Diagram [message #1726881 is a reply to message #1726869] Thu, 17 March 2016 08:59 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Koen,

See my answers below :

Le 17/03/2016 08:58, Koen Staal a écrit :
> Hi thanks for you response
>
> I am using the "org.eclipse.sirius.common.xtext" integration plugin. It
> uses XtextResourceSetFactory in it to create a new instance of a
> XtextResourceSet. Called from SessionFactoryImp.createSession.r83. It
> seems that Sirius and Xtext not use the same ResourceSet instance.

Having XTextResourceSetFactory called we should have a same instance of
ResourceSet between Xtext and Sirius editors, i.e. a XtextResourceSet
instance.

>
> I always got the correct object by using the object uri, which now has
> changed.
> EObject object =
> session.getTransactionalEditingDomain().getResourceSet().getEObject(EcoreUtil.getURI(target),false);
>
>
> (In xtext the refactor only sets the name attribute of the Eobject which
> is an EKey.)

If XText refactoring change the name EAttribute which is an EKey then
this refactoring will change the URI of the EObject.

>
> Is the xtext and sirius integration setup correct?

If you have the "org.eclipse.sirius.common.xtext" integration plugin
your setup is correct.

>
>
>
>
>
>


Best Regards.

--
Esteban Dugueperoux - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Rename in EObject creates new Diagram [message #1726899 is a reply to message #1726881] Thu, 17 March 2016 11:09 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
Thanks for your fast response
-Ok so the xtext integration is correct
-The rename of an object will cause the loss of the diagram.
-To open the same diagram before the rename i need to implement my own refactoring participant or customized XText one.

I customized the Xtext IRenameStrategy to call the following rename method:

	public void renameObject(Session session, final URI targetElementOriginalURI, final EAttribute nameAttribute,
			final String newName) {
			final EObject object = session.getTransactionalEditingDomain().getResourceSet()
					.getEObject(targetElementOriginalURI, false);
			if (object != null) {
				session.getTransactionalEditingDomain().getCommandStack()
						.execute(new RecordingCommand(session.getTransactionalEditingDomain()) {
							@Override
							protected void doExecute() {
								object.eSet(nameAttribute, newName);
							}
						});
			}
		
	}


It does the job! However updating the sirius object(calling the above method) causes to show the dialog "Reload the resource? the platform:/.../.. resource has been externally changed, should we reload it?"
I dont want to bother the user with this dialog, is there a way around this?

[Updated on: Tue, 22 March 2016 12:31]

Report message to a moderator

Re: Rename in EObject creates new Diagram [message #1726916 is a reply to message #1726899] Thu, 17 March 2016 12:30 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
If you have this popup, it means there is an issue.
But if you want yet to avoid this popup, you can provide your own
ReloadingPolicy implementation in Session interface through
Session.setReloadingPolicy() method.

Le 17/03/2016 12:09, Koen Staal a écrit :
> Ok so the xtext integration is correct The rename of an object will
> cause the loss of the diagram. To open the same diagram before the
> rename i need to implement my own refactoring participant or customized
> XText one.
>
> I customized the Xtext IRenameStrategy to call the following rename method:
>
> public void renameObject(Session session, final URI
> targetElementOriginalURI, final EAttribute nameAttribute,
> final String newName) {
> if (targetElementOriginalURI != null &&
> targetElementOriginalURI.isPlatform()) {
>
> final EObject object =
> session.getTransactionalEditingDomain().getResourceSet()
> .getEObject(targetElementOriginalURI, false);
> if (object != null) {
> session.getTransactionalEditingDomain().getCommandStack()
> .execute(new
> RecordingCommand(session.getTransactionalEditingDomain()) {
> @Override
> protected void doExecute() {
> object.eSet(nameAttribute, newName);
> }
> });
> }
> }
> }
>
>
> It does the job! However updating the sirius object causes to show the
> dialog "Reload the resource? the platform:/.../.. resource has been
> externally changed, should we reload it?"
> I dont want to bother the user with this dialog, is there a way around
> this?
>



--
Esteban Dugueperoux - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Rename in EObject creates new Diagram [message #1727038 is a reply to message #1726916] Fri, 18 March 2016 12:21 Go to previous messageGo to next message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
The rename action is started in xtexteditor and the popup was also directly shown on the XtextEditor, probably because i was also changing the object in sirius

[Updated on: Tue, 22 March 2016 11:00]

Report message to a moderator

Re: Rename in EObject creates new Diagram [message #1727590 is a reply to message #1727038] Thu, 24 March 2016 09:07 Go to previous message
Koen Staal is currently offline Koen StaalFriend
Messages: 70
Registered: October 2014
Member
The rename issue is still not resolved so i would like to describe the complete picture of the problem and what i have tried.

-An object is the target/owner of a diagram .
-I am initiating a rename of this object in the XtextEditor
-The name of the Object is its Ekey, which means its uri changes when the object is renamed.
-After the rename the diagram of the object can no longer be found.
--
I am using the "org.eclipse.sirius.common.xtext" integration plugin and XTextResourceSetFactory gets called to create a XtextResourceSet when a session created
The project is a xtext project (not a project with an javanature, XTextResourceSetFactory does some extra configuration with a java project)

Without any rename customization sirius gets a notification that the resource is changed. By adding the resourcesetListener i could determine what information sirius actually gets and it is what Esteban described. The notifications contain information that basically a whole file is removed and the same file is added (using a notification that says the file's root eobject is removed and the same object is added in another notification. The renamed object is present in the added root eobject, but i can never be sure if its renamed or just a new object.


What i tried:

The ResourceSetListener as described above contains no information which object is renamed.
Changing the reloading Policy, the reloading policy just like the resourcesetListener only contains the changed resource. No information on which object is changed.

I added to the Xtext defaultRenameStrategy (IRenameStrategy) , to also rename the object in the Sirius XtextResourceSet. Since the rename is initiated in the xtexteditor this will now give the popup "Reload the resource? the platform:/.../.. resource has been externally changed, should we reload it?" Now the resourceSetListener gets the information exactly about which object is renamed.

I spend some time into creating my own RenameParticipant but it this will probably end in the same result as the defaultRenamyStrategy. Changing the sirius resourceset and getting the popup again in the xtexteditor.

--

Supporting textual rename seems alot harder then i suspected and it makes me wonder what i am doing wrong.
At this point it seems setting the name not as Ekey as the easiest solution, but this would change diagrams if code is reordered in the text editor.
Another option is to change the session file (.aird) textually from the xtext renamestrategy or RenameParticipant but this more like hacking.
Is it even possible at all to support rename from xtext with the object's name as ekey without popup






Previous Topic:Minimal Runtime Configuration
Next Topic:Professional support for Sirius
Goto Forum:
  


Current Time: Wed Apr 21 20:51:33 GMT 2021

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

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

Back to the top