Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Adding operation to D&D (or copy-) behavior
Adding operation to D&D (or copy-) behavior [message #895003] Wed, 11 July 2012 11:33 Go to next message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi guys,

I'm afraid I will need your help again.
What I want to do is slightly change the Drag and Drop behavior, or the copy behavior in general.

My class has an ID attribute and an origin-ID attribute which is empty be default. If I copy an item, possibly by drag and drop, what I want to do is write the source's "ID" into the target's "origin ID" (both just string type) field on top of copying all other attributes and references (just regular behavior).

I tried debugging through the D&D functionality with the help I got from other posts in this forum.

By creating my own ViewerDropAdapter I can override the dropAccept function or even the helper.

My concrete problem is that I never found the exact spot where the new element is being created. By intuition, I would have expected the (copy-)constructor of my class to be called at some point, but it seems that's not the case. In ViewerDropAdapter.helper I can access a source and target object, but the target seems to be container of the new element, so its parent in the tree. I would expect a new child to be created underneath that "target" at some point, which would the exactly the spot I'd like to modify, but I can't find it.
Is a new object even created somewhere, or is the copy process solved on the resource level somehow? Or am I missing something completely?

If I could automatically get the same thing to work if I copied and pasted an element in the editor by hand, that would be even better.

Maybe someone has wanted to do the same thing before and could point out to me where exactly I could stick the handle to add the small additional operation of setting an extra attribute?

Thank you very much!
Re: Adding operation to D&D (or copy-) behavior [message #895028 is a reply to message #895003] Wed, 11 July 2012 12:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30452
Registered: July 2009
Senior Member
Markus,

Comments below.

On 11/07/2012 1:33 PM, Markus G wrote:
> Hi guys,
>
> I'm afraid I will need your help again.
> What I want to do is slightly change the Drag and Drop behavior, or
> the copy behavior in general.
>
> My class has an ID attribute and an origin-ID attribute which is empty
> be default. If I copy an item, possibly by drag and drop, what I want
> to do is write the source's "ID" into the target's "origin ID" (both
> just string type) field on top of copying all other attributes and
> references (just regular behavior).
>
> I tried debugging through the D&D functionality with the help I got
> from other posts in this forum.
>
> By creating my own ViewerDropAdapter I can override the dropAccept
> function or even the helper.
You shouldn't have to work at that level. All this copying and all the
rest of it is done by EMF commands that you can specialize.
> My concrete problem is that I never found the exact spot where the new
> element is being created. By intuition, I would have expected the
> (copy-)constructor of my class to be called at some point, but it
> seems that's not the case. In ViewerDropAdapter.helper I can access a
> source and target object, but the target seems to be container of the
> new element, so its parent in the tree. I would expect a new child to
> be created underneath that "target" at some point, which would the
> exactly the spot I'd like to modify, but I can't find it.
If a new instance is really being created, the generated constructor
will be called.
> Is a new object even created somewhere, or is the copy process solved
> on the resource level somehow? Or am I missing something completely?
>
> If I could automatically get the same thing to work if I copied and
> pasted an element in the editor by hand, that would be even better.
> Maybe someone has wanted to do the same thing before and could point
> out to me where exactly I could stick the handle to add the small
> additional operation of setting an extra attribute?
>
> Thank you very much!
Most likely you should be specializing the generated item providers
createInitializeCopyCommand method to produce a specialized
InitializeCopyCommand. You can look in EReferenceItemProvider for a
simple example (where opposites need specialized support).
Re: Adding operation to D&D (or copy-) behavior [message #895836 is a reply to message #895028] Mon, 16 July 2012 09:11 Go to previous message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi,

since I have been having some trouble solving this, I will post my solution here in case someone else will have the same problems some time:

Thanks a lot, Ed, for the point in the right direction:

The copy-object is accessible in the InitializeCopyCommand, so what I did was override the createInitializeCopyCommand in my ItemProvider, and inside I've overridden the doExecute() method. Inside here you have access to the "owner" object and the "copy" object and can make additional modifications.

Hope this might help someone else some time.
Thanks again!
Previous Topic:exception when creating genmodel (Juno)
Next Topic:[CDO 4.1] : Reattachment issue with EOpposite
Goto Forum:
  


Current Time: Thu Sep 19 19:24:33 GMT 2019

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

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

Back to the top