Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to extends the copy/paste command ?(emf, copy, paste, extend)
How to extends the copy/paste command ? [message #1700600] Sat, 04 July 2015 15:17 Go to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi,

I'd like to add a post-processing to the creation of an element done with Copy/Paste or Drag/Drop in an EMF editor. More precisally, , I'd like to modify an attribute of the copied element so that it differs from the original element (Basically an attribute "name" so that name "X" would be set as "Copy_of_X" if copied under the same parent).

I took a look at the class initializeCopyCommand, but it is called upon selection of an element, and at this time, I still don't know where it will be copied...

Can someone give me any good advise to achieve this ?

Thanks.
Re: How to extends the copy/paste command ? [message #1700714 is a reply to message #1700600] Mon, 06 July 2015 15:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Vincent,

Comments below.

On 04/07/2015 5:17 PM, Vincent De Bry wrote:
> Hi,
>
> I'd like to add a post-processing to the creation of an element done
> with Copy/Paste or Drag/Drop in an EMF editor. More precisally, , I'd
> like to modify an attribute of the copied element so that it differs
> from the original element (Basically an attribute "name" so that name
> "X" would be set as "Copy_of_X" if copied under the same parent).
>
> I took a look at the class initializeCopyCommand, but it is called
> upon selection of an element, and at this time, I still don't know
> where it will be copied...
What you've describe above doesn't require you to know where it is
copied to does it? All the commands are created upon selection, and at
this point your specialized initialization of the copy can do what you
want. If/when the user hits Ctrl-C, the command will be executed to put
your specially initialized copy in the clipboard...
>
> Can someone give me any good advise to achieve this ?
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to extends the copy/paste command ? [message #1700748 is a reply to message #1700714] Mon, 06 July 2015 19:02 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi Ed, Thanks for answering.

Yes, I need to know where the copy will be created: imagine I have the model below:

A1
--- B
A2

I want to copy B;
If the copy has to be created ander A1: I want to have:

A1
--- B
--- Copy_of_B
A2

If the copy has to be created ander A2: I want to have:

A1
--- B
A2
--- B

Actually, as a copy of file in the windows explorer.

So I need to post process the creation, and not only consier the command created upon selection.
Re: How to extends the copy/paste command ? [message #1700751 is a reply to message #1700748] Mon, 06 July 2015 19:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Vincent,

I see, you want to make sure the name is unique at the target. Only the
AddCommand really knows where the object is being added, so you'd need
to specialize it. Of course there are many cases to consider, i.e.,
just moving the object with drag and drop, or with cut and paste is
similar, but not so much copying involved, i.e., the object is removed
from the original location in those cases. So yes, you can specialize
the add command creation, and use that hook to modify the object being
added. You'd want to be careful to do the modification also via a
command so that an undo will always work properly, i.e., in the case of
a move drag and drop, move it back and set the name back to the
original. CompoundCommand is of course useful for composing such logic.

On 06/07/2015 9:02 PM, Vincent De Bry wrote:
> Hi Ed, Thanks for answering.
>
> Yes, I need to know where the copy will be created: imagine I have the
> model below:
>
> A1
> --- B
> A2
>
> I want to copy B;
> If the copy has to be created ander A1: I want to have:
>
> A1
> --- B
> --- Copy_of_B
> A2
>
> If the copy has to be created ander A2: I want to have:
>
> A1
> --- B
> A2
> --- B
>
> Actually, as a copy of file in the windows explorer.
>
> So I need to post process the creation, and not only consier the
> command created upon selection.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to extends the copy/paste command ? [message #1700846 is a reply to message #1700751] Tue, 07 July 2015 14:42 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Ed,

AddCommand is referenced by many classes. Where/how should I reference the extension I will do so it will be called by after every kinds of copy (Paste, cut, Drag&Drop...) ?

Thanks.
Re: How to extends the copy/paste command ? [message #1700865 is a reply to message #1700846] Tue, 07 July 2015 17:51 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Vincent,

You can specialize
org.eclipse.emf.edit.provider.ItemProviderAdapter.createAddCommand(EditingDomain,
EObject, EStructuralFeature, Collection<?>, int). Note that the method
can return any type of command, though it must of course have the
effective of doing an add.

On 07/07/2015 4:42 PM, Vincent De Bry wrote:
> Ed,
>
> AddCommand is referenced by many classes. Where/how should I reference
> the extension I will do so it will be called by after every kinds of
> copy (Paste, cut, Drag&Drop...) ?
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to extends the copy/paste command ? [message #1700907 is a reply to message #1700865] Wed, 08 July 2015 06:53 Go to previous message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Thank you Ed,

I specialized this class so that I manage the collection according to the EObject (owner). It seems I achieve what I wanted.
Thans again.
Previous Topic:Class cast exception trying to modify values in a property sheet
Next Topic:I don't understand TransactionalEditingDomain.runExclusive
Goto Forum:
  


Current Time: Fri Apr 19 02:22:18 GMT 2024

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

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

Back to the top