Rename in EObject creates new Diagram [message #1726684] |
Tue, 15 March 2016 17:12 |
Koen Staal 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 |
Esteban Dugueperoux 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 |
Koen Staal 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 #1726899 is a reply to message #1726881] |
Thu, 17 March 2016 11:09 |
Koen Staal 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 |
Esteban Dugueperoux 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04082 seconds