Adding operation to D&D (or copy-) behavior [message #895003] |
Wed, 11 July 2012 11:33 |
Markus G 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 |
Ed Merks Messages: 33217 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).
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02610 seconds