Home » Modeling » GMF (Graphical Modeling Framework) » issues with copy & paste
issues with copy & paste [message #78901] |
Mon, 20 November 2006 11:02  |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
Hi all,
I'm looking for help on how to fix the following problems with copy &
paste:
(1) Copying non-containment references:
This is the case when I copy and paste model elements with connections.
After overriding
public boolean isCopyAlways(EObject context, EReference eReference,Object
value)
in the ClipboardSupport class, connections get copies, however the inverse
references don't get updated properly.
+------+ +------+
| | | |
| A +---------/ B |
| \ | |
| |\ | |
+------+ \ +------+
\
\
\
\
\ +-------+
\ | |
\| B' |
| |
| |
+-------+
So If I copy B, it's connections get copied, too. The new connection's
ends are set to A and B' correctly. However, The list of connections A has
doesn't get updated.
(2) Is there away to automatically configure the pasted element using the
right edit helper for it?
Thanks for you help,
vlad
|
|
|
Re: issues with copy & paste [message #80784 is a reply to message #78901] |
Fri, 24 November 2006 14:53   |
Eclipse User |
|
|
|
Hi Vlad,
I'm not sure if you are still trying to solve these issues, but I will
try to help.
(1) Copying non-containment references
Just to make sure I understand the issue, the EMF Clipboard support does
not copy connections unless both ends are connected which is why you are
implementing this yourself. Is that correct?
The CopyOperation will eventually call copyReferences() on an
ECoreUtil.Copier instance. This should update the references as you
would expect; however, since A did not get copied, it is probably not in
the map for which the references are updated.
I fixed this for the specific case of the duplicate action. The
duplicate action will duplicate all the views selected AND create a deep
copy of the semantic element. This will also work when a connection is
selected, but not its source and/or target (unlike copy/paste). To get
this working, I added custom code in the DuplicateViewsCommand to handle
this. Search the DuplicateViewsCommand for this comment to see how it
was done:
// If the source/target wasn't duplicated, then the copier
// would not have set the source/target.
(2) I don't think there is a way to configure the pasted element using
the correct edithelper. To support copy/paste to another document (e.g.
a Word doc) you only need to copy the views. What is the purpose of
your copy/paste? If you are trying to create a copy of the view and
element, maybe you should be using the duplicate action for this. In
this case, you don't need to serialize everything so it is a bit
simpler. Plus, there is a method in the edithelpers called
getDuplicateCommand() that is used for this purpose. Maybe this is
something you want to consider.
I hope this is of assistance. If anything is unclear, let me know.
Regards,
Cherie
Vlad Ciubotariu wrote:
> Hi all,
>
> I'm looking for help on how to fix the following problems with copy &
> paste:
>
> (1) Copying non-containment references:
>
> This is the case when I copy and paste model elements with connections.
> After overriding
>
> public boolean isCopyAlways(EObject context, EReference eReference,Object
> value)
>
> in the ClipboardSupport class, connections get copies, however the inverse
> references don't get updated properly.
>
>
>
> +------+ +------+
> | | | |
> | A +---------/ B |
> | \ | |
> | |\ | |
> +------+ \ +------+
> \
> \
> \
> \
> \ +-------+
> \ | |
> \| B' |
> | |
> | |
> +-------+
>
>
> So If I copy B, it's connections get copied, too. The new connection's
> ends are set to A and B' correctly. However, The list of connections A has
> doesn't get updated.
>
>
> (2) Is there away to automatically configure the pasted element using the
> right edit helper for it?
>
>
> Thanks for you help,
>
> vlad
|
|
|
Re: issues with copy & paste [message #81758 is a reply to message #80784] |
Wed, 29 November 2006 12:53  |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
Thanks, Cherie, for the detailed info. I understand that at copy time we
cannot modify the elements being copied, so that's why inverse of a
reference does not get properly set.
After some more tracing I realized that my problem would be solved if I
could override
PasteChildOperation#protected EObject doPasteInto(EObject
pasteIntoEObject, EReference reference)
to set the opposite reference.
My fix for now is to listen to the changes in the model and fix those
connections after they get pasted.
thanks again,
vlad
On Fri, 24 Nov 2006 14:53:25 -0500, Cherie Revells wrote:
> Hi Vlad,
>
> I'm not sure if you are still trying to solve these issues, but I will
> try to help.
>
> (1) Copying non-containment references
>
> Just to make sure I understand the issue, the EMF Clipboard support does
> not copy connections unless both ends are connected which is why you are
> implementing this yourself. Is that correct?
>
> The CopyOperation will eventually call copyReferences() on an
> ECoreUtil.Copier instance. This should update the references as you
> would expect; however, since A did not get copied, it is probably not in
> the map for which the references are updated.
>
> I fixed this for the specific case of the duplicate action. The
> duplicate action will duplicate all the views selected AND create a deep
> copy of the semantic element. This will also work when a connection is
> selected, but not its source and/or target (unlike copy/paste). To get
> this working, I added custom code in the DuplicateViewsCommand to handle
> this. Search the DuplicateViewsCommand for this comment to see how it
> was done:
> // If the source/target wasn't duplicated, then the copier
> // would not have set the source/target.
>
> (2) I don't think there is a way to configure the pasted element using
> the correct edithelper. To support copy/paste to another document (e.g.
> a Word doc) you only need to copy the views. What is the purpose of
> your copy/paste? If you are trying to create a copy of the view and
> element, maybe you should be using the duplicate action for this. In
> this case, you don't need to serialize everything so it is a bit
> simpler. Plus, there is a method in the edithelpers called
> getDuplicateCommand() that is used for this purpose. Maybe this is
> something you want to consider.
>
> I hope this is of assistance. If anything is unclear, let me know.
>
> Regards,
> Cherie
>
>
> Vlad Ciubotariu wrote:
>> Hi all,
>>
>> I'm looking for help on how to fix the following problems with copy &
>> paste:
>>
>> (1) Copying non-containment references:
>>
>> This is the case when I copy and paste model elements with connections.
>> After overriding
>>
>> public boolean isCopyAlways(EObject context, EReference eReference,Object
>> value)
>>
>> in the ClipboardSupport class, connections get copies, however the inverse
>> references don't get updated properly.
>>
>>
>>
>> +------+ +------+
>> | | | |
>> | A +---------/ B |
>> | \ | |
>> | |\ | |
>> +------+ \ +------+
>> \
>> \
>> \
>> \
>> \ +-------+
>> \ | |
>> \| B' |
>> | |
>> | |
>> +-------+
>>
>>
>> So If I copy B, it's connections get copied, too. The new connection's
>> ends are set to A and B' correctly. However, The list of connections A has
>> doesn't get updated.
>>
>>
>> (2) Is there away to automatically configure the pasted element using the
>> right edit helper for it?
>>
>>
>> Thanks for you help,
>>
>> vlad
|
|
|
Goto Forum:
Current Time: Sat Jul 19 19:37:41 EDT 2025
Powered by FUDForum. Page generated in 0.24679 seconds
|