Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] copy of referenced object between models
[EMF] copy of referenced object between models [message #424841] Thu, 06 November 2008 15:36 Go to next message
vincent pucheux is currently offline vincent pucheuxFriend
Messages: 15
Registered: July 2009
Junior Member
hi all,
We came to a problem with editors/models that share the same clipboard.

The clipboard of our editing domain is defined as static, so that we can
copy object from a model to another, and everything's working fine.

But a problem appeared when we wanted to copy Object that are refencing
other Objects in the model, because objects are well copied, but the
referenced objects is not, so the copied object reference another object
which is in the other model.

In fact we would like to copy the reference as well, and these
references can also reference other objects that need to be copied too,
and so, and so.

We tried to override the copyReferences() of the createInitializeCommand
and we tried to ovveride as well doGetChildrenToCopy() of the
createCreateCommand to include these referenced objects.

So if anybody knows how to add these referenced objects to the copied
element, or if there is a best practise in this case, i would be
grateful to explain it to me.

thanks,
vincent.
Re: [EMF] copy of referenced object between models [message #424842 is a reply to message #424841] Thu, 06 November 2008 15:40 Go to previous messageGo to next message
vincent pucheux is currently offline vincent pucheuxFriend
Messages: 15
Registered: July 2009
Junior Member
vincent a écrit :
> hi all,
> We came to a problem with editors/models that share the same clipboard.
>
> The clipboard of our editing domain is defined as static, so that we can
> copy object from a model to another, and everything's working fine.
>
> But a problem appeared when we wanted to copy Object that are refencing
> other Objects in the model, because objects are well copied, but the
> referenced objects is not, so the copied object reference another object
> which is in the other model.
>
> In fact we would like to copy the reference as well, and these
> references can also reference other objects that need to be copied too,
> and so, and so.
>
> We tried to override the copyReferences() of the createInitializeCommand
> and we tried to ovveride as well doGetChildrenToCopy() of the
> createCreateCommand to include these referenced objects.
>
> So if anybody knows how to add these referenced objects to the copied
> element, or if there is a best practise in this case, i would be
> grateful to explain it to me.
>
> thanks,
> vincent.
>
>


I would really be grateful to explain it to me, but i can't, so if You
can explain it to me... ;-]

thanks,
vincent.
Re: [EMF] copy of referenced object between models [message #424845 is a reply to message #424841] Thu, 06 November 2008 16:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Vincent,

Copying is quite a tricky thing. Consider that if you copy some object
and it has references to other objects which now you say you want to
copy as well, when you paste the one copied object, those other copied
objects will need to be added somewhere into some containment reference
or they'll just be dangling references to objects that aren't contained
anywhere. It's just not clear what kind of behavior you're hoping will
come out of this for those other copies object. Maybe you should be
specializing the copy so that any references to objects not contained
within the copy are discarded...



vincent wrote:
> hi all,
> We came to a problem with editors/models that share the same clipboard.
>
> The clipboard of our editing domain is defined as static, so that we
> can copy object from a model to another, and everything's working fine.
>
> But a problem appeared when we wanted to copy Object that are
> refencing other Objects in the model, because objects are well copied,
> but the referenced objects is not, so the copied object reference
> another object which is in the other model.
>
> In fact we would like to copy the reference as well, and these
> references can also reference other objects that need to be copied
> too, and so, and so.
>
> We tried to override the copyReferences() of the
> createInitializeCommand and we tried to ovveride as well
> doGetChildrenToCopy() of the createCreateCommand to include these
> referenced objects.
>
> So if anybody knows how to add these referenced objects to the copied
> element, or if there is a best practise in this case, i would be
> grateful to explain it to me.
>
> thanks,
> vincent.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] copy of referenced object between models [message #424848 is a reply to message #424845] Thu, 06 November 2008 18:27 Go to previous messageGo to next message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

Thanks Ed!

In our particular case we really don't want to discard references to
objects not contained within the copy; moreover, we precisely know where
to add the dangling copies, but we need the right place to do this (i.e.
we need to "repair" every reference to dangling items, adding the
referenced item to the right container)... What we've done at the moment
is to override the createAddCommand of the container of both the
"copyRoot" and its "referenced siblings", to have the ability to fix
every dangling object referenced by the "copyRoot", right after this
copyRoot has been added to its container

Any better ideas are welcome anyway :)
Thanks,
Benjamin


Ed Merks a écrit :
> Vincent,
>
> Copying is quite a tricky thing. Consider that if you copy some object
> and it has references to other objects which now you say you want to
> copy as well, when you paste the one copied object, those other copied
> objects will need to be added somewhere into some containment reference
> or they'll just be dangling references to objects that aren't contained
> anywhere. It's just not clear what kind of behavior you're hoping will
> come out of this for those other copies object. Maybe you should be
> specializing the copy so that any references to objects not contained
> within the copy are discarded...
>
>
>
> vincent wrote:
>> hi all,
>> We came to a problem with editors/models that share the same clipboard.
>>
>> The clipboard of our editing domain is defined as static, so that we
>> can copy object from a model to another, and everything's working fine.
>>
>> But a problem appeared when we wanted to copy Object that are
>> refencing other Objects in the model, because objects are well copied,
>> but the referenced objects is not, so the copied object reference
>> another object which is in the other model.
>>
>> In fact we would like to copy the reference as well, and these
>> references can also reference other objects that need to be copied
>> too, and so, and so.
>>
>> We tried to override the copyReferences() of the
>> createInitializeCommand and we tried to ovveride as well
>> doGetChildrenToCopy() of the createCreateCommand to include these
>> referenced objects.
>>
>> So if anybody knows how to add these referenced objects to the copied
>> element, or if there is a best practise in this case, i would be
>> grateful to explain it to me.
>>
>> thanks,
>> vincent.
>>
>>


Re: [EMF] copy of referenced object between models [message #424850 is a reply to message #424848] Thu, 06 November 2008 18:57 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Benjamin,

Hmmm. Well CopyCommand.addCreateCommandCommands is recursive, and
thereby walks the whole containment tree. But you'd want it to be
recursive not just over the contained children, EObject.eContents(), but
also to eCrossReferences as well. You'd have to be careful to write
your visitor to avoid infinite recursion, but you could imagine how
you'd use EObject.eCrossReferences as additional objects to visit ,
using that to compute the closure of all reachable objects, and then
create CreateCopyCommands for all those...



Benjamin CABE wrote:
> Thanks Ed!
>
> In our particular case we really don't want to discard references to
> objects not contained within the copy; moreover, we precisely know
> where to add the dangling copies, but we need the right place to do
> this (i.e. we need to "repair" every reference to dangling items,
> adding the referenced item to the right container)... What we've done
> at the moment is to override the createAddCommand of the container of
> both the "copyRoot" and its "referenced siblings", to have the ability
> to fix every dangling object referenced by the "copyRoot", right after
> this copyRoot has been added to its container
>
> Any better ideas are welcome anyway :)
> Thanks,
> Benjamin
>
>
> Ed Merks a écrit :
>> Vincent,
>>
>> Copying is quite a tricky thing. Consider that if you copy some
>> object and it has references to other objects which now you say you
>> want to copy as well, when you paste the one copied object, those
>> other copied objects will need to be added somewhere into some
>> containment reference or they'll just be dangling references to
>> objects that aren't contained anywhere. It's just not clear what
>> kind of behavior you're hoping will come out of this for those other
>> copies object. Maybe you should be specializing the copy so that any
>> references to objects not contained within the copy are discarded...
>>
>>
>>
>> vincent wrote:
>>> hi all,
>>> We came to a problem with editors/models that share the same clipboard.
>>>
>>> The clipboard of our editing domain is defined as static, so that we
>>> can copy object from a model to another, and everything's working fine.
>>>
>>> But a problem appeared when we wanted to copy Object that are
>>> refencing other Objects in the model, because objects are well
>>> copied, but the referenced objects is not, so the copied object
>>> reference another object which is in the other model.
>>>
>>> In fact we would like to copy the reference as well, and these
>>> references can also reference other objects that need to be copied
>>> too, and so, and so.
>>>
>>> We tried to override the copyReferences() of the
>>> createInitializeCommand and we tried to ovveride as well
>>> doGetChildrenToCopy() of the createCreateCommand to include these
>>> referenced objects.
>>>
>>> So if anybody knows how to add these referenced objects to the
>>> copied element, or if there is a best practise in this case, i would
>>> be grateful to explain it to me.
>>>
>>> thanks,
>>> vincent.
>>>
>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] eStore() returns null which results in a NPE
Next Topic:Re: Non lazy Ocl Validation through Dynamic Constaint Provider
Goto Forum:
  


Current Time: Wed Apr 24 18:22:14 GMT 2024

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

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

Back to the top