Copy between resources - Dangling References [message #1009516] |
Fri, 15 February 2013 04:07  |
Eclipse User |
|
|
|
Hello,
I've implemented a mechanism to copy EObjects from one resource into another (via Drag & Drop). I'm basically using EcoreUtil#copyAll(Collection) and AddCommands.
It works fine as long as there are no EObjects in the target model that have the same ID as the ones that should be copied.
If that happens, I am trying to replace the existing EObjects with the new ones, but I failing here.
First I tried RemoveCommand -> CreateCommand. This seems to work at first but on validation I get "The feature [...] contains a dangling reference [...]" on every other EObject that references the removed existing one.
Then I tried the ReplaceCommand - same Problem.
How can I replace an EObject and fix all references to it?
Is there a way to completely replace every feature of an EObject (including containments) by using SetCommand(s)?
Thanks in advance!
Best regards,
Ralph
|
|
|
Re: Copy between resources - Dangling References [message #1009570 is a reply to message #1009516] |
Fri, 15 February 2013 05:29   |
Eclipse User |
|
|
|
Ralph,
Comments below.
On 15/02/2013 10:07 AM, Ralph P wrote:
> Hello,
>
> I've implemented a mechanism to copy EObjects from one resource into
> another (via Drag & Drop). I'm basically using
> EcoreUtil#copyAll(Collection) and AddCommands.
>
> It works fine as long as there are no EObjects in the target model
> that have the same ID as the ones that should be copied.
> If that happens, I am trying to replace the existing EObjects with the
> new ones, but I failing here.
>
> First I tried RemoveCommand -> CreateCommand. This seems to work at
> first but on validation I get "The feature [...] contains a dangling
> reference [...]" on every other EObject that references the removed
> existing one.
Yes, you'd need to use a DeleteCommand, but that's probably not going to
do what you want either; I assume you'd want all those other things to
reference the replacement...
> Then I tried the ReplaceCommand - same Problem.
Yes, the incoming references to the thing you've replaced will still dangle.
>
> How can I replace an EObject and fix all references to it?
> Is there a way to completely replace every feature of an EObject
> (including containments) by using SetCommand(s)?
Yes, you'd have to have to compose such a SetCommand for each feature.
>
> Thanks in advance!
I think you'd want something very similar to what DeleteCommand does,
but instead of deleting the reference, you'd want to use a
ReplaceCommand to replace it with a reference to the replacement.
>
> Best regards,
> Ralph
>
|
|
|
|
|
|
Re: Copy between resources - Dangling References [message #1010111 is a reply to message #1009680] |
Sat, 16 February 2013 10:24  |
Eclipse User |
|
|
|
Ralph,
Comments below.
On 15/02/2013 3:06 PM, Ralph P wrote:
> I see... That's why the DeleteCommand uses the RemoveCommand on "if
> (eStructuralFeature.isMany() {...})", right?
Yes, but that will remove the one object from that one feature. So be
careful with your set command that you specify the index.
>
> I will test that as well, many thanks!
|
|
|
Powered by
FUDForum. Page generated in 0.50846 seconds