Rename in EObject creates new Diagram [message #1726684] |
Tue, 15 March 2016 13:12  |
Eclipse User |
|
|
|
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 13:13] by Moderator
|
|
|
Re: Rename in EObject creates new Diagram [message #1726784 is a reply to message #1726684] |
Wed, 16 March 2016 09:28   |
Eclipse User |
|
|
|
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 #1726916 is a reply to message #1726899] |
Thu, 17 March 2016 08:30   |
Eclipse User |
|
|
|
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 #1727590 is a reply to message #1727038] |
Thu, 24 March 2016 05:07  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04170 seconds