Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Copying & Replacing EObjects.
Copying & Replacing EObjects. [message #886126] Thu, 14 June 2012 09:42 Go to next message
Frank Goldwin is currently offline Frank GoldwinFriend
Messages: 10
Registered: May 2012
Junior Member
Hi,

I use a JFace dialog with databinding to set values on an EObject.
If the users presses Cancel on the dialog the changes should be discarded.
Therefore, I make a copy of the EObject (EcoreUtil.copy(EObject)) and pass it to the dialog.
Upon exist, if the user has pressed Cancel I simply don't do anything with the copy.
If the users presses OK I need to replace the original (unchanged) object with the populated copy.
I see two choices here:
1 - Write some code, based on EcoreUtil.copy, that takes 2 EObjects and copies features from one to the other.
2 - Get the container feature of the original object (EObject.eContainingFeature()) remove the original object from it and substitute it with the copy object.
This quickly becomes complicated because the original object is inside a many-valued feature (which appears to be a java.util.Collection).

Still, I feel there must be a more elegant solution.
Is the solution in the JFace dialog domain?
Am I missing some EMF feature to simply copy an object on top of the other?
I'm using EMF 2.7.2 thus will changes to the copy object go through the Command stack?

Thank you.

Regards,
Frank
Re: Copying & Replacing EObjects. [message #886128 is a reply to message #886126] Thu, 14 June 2012 09:49 Go to previous messageGo to next message
Frank Goldwin is currently offline Frank GoldwinFriend
Messages: 10
Registered: May 2012
Junior Member
I found the 'elegant' solution thanks to the magnificent EcoreUtil.
I've used EcoreUtil.replace(obj1, obje2) to replace it.
It seems to work like a charm.

Thank you EMF team for your great work.
You've thought of everything!

Regards,
Frank
Re: Copying & Replacing EObjects. [message #886486 is a reply to message #886128] Fri, 15 June 2012 03:03 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Frank,

Another thing you might try: attach a ChangeRecorder to your model
when the dialog opens. Let the dialog make changes, as usual. If OK
is pressed, fine. Remove the ChangeRecorder and continue. If Cancel
is pressed, stop the ChangeRecorder and apply() the ChangeDescription
to undo all of the changes that were made by the dialog.

Does EcoreUtil::replace() handle references to the objects that were
copied from objects that weren't copied? Does it change those
references to point to the replacements? That would, indeed, be cool
and EMF-like.

Cheers,

Christian


On 2012-06-14 09:49:12 +0000, Frank Goldwin said:

> I found the 'elegant' solution thanks to the magnificent EcoreUtil.
> I've used EcoreUtil.replace(obj1, obje2) to replace it.
> It seems to work like a charm.
>
> Thank you EMF team for your great work.
> You've thought of everything!
>
> Regards,
> Frank
Previous Topic:Re: [ATL] Invoking an ATL transformation on a part of a model, not on a whole model
Next Topic:Teneo & Juno
Goto Forum:
  


Current Time: Thu Mar 28 17:27:23 GMT 2024

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

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

Back to the top