Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » help overriding createMoveCommand() or createDragAndDropCommand()
help overriding createMoveCommand() or createDragAndDropCommand() [message #558355] Sat, 11 September 2010 14:49 Go to next message
Jeff S. is currently offline Jeff S.Friend
Messages: 29
Registered: July 2009
Junior Member
I've been trying to figure out the best way to handle move/drag-n-drop
events for one of my objects. I will try to explain below. I've
searched the newsgroup and the EMF book, and am still having some
problems trying to solve my issue. I believe I want to override
createMoveCommand() or createDragAndDropCommand(), but can't find any
concrete examples, and am having problems debugging (and setting up
breakpoints in the right place).

Here's an example setup / ecore model:

MainObject
listA [0...100]: ObjectA
listB [0...200]: ObjectB
ObjectA
name: String
ObjectB
name: String
pointerToA: Int


When I drag and drop objects in listA, I would like to "fix" all the
ObjectB#pointerToA values based on a preference. If the preference is
true, then I need to update pointerToA with the new indexes of ObjectA;
if the preference is false, then I don't need to do anything: pointerA
can stay pointing at the old index.

This is a simplified example, but should describe my issue.

Anyways, in MainObjectItemProvider, I've tried overriding both
createDragAndDropCommand() and createMoveCommand().

When I return UnexecutableCommand.INSTANCE for
createDragAndDropCommand(), it seems to have no effect. I can move
ObjectA items around in my editor- and they behave the same way they did
before I overrode createDragAndDropCommand(). If I put a breakpoint in
that function, I see that it is never called when I drag-n-drop items.

When I add a breakpoint on createMoveCommand(), I see that it is being
called when I drag-n-drop ObjectA items in my editor. The problem is,
my breakpoint is triggered when I am "dragging" items. I don't know how
to set the breakpoint to only trigger when I "drop" the items.

Also, I can't figure out the correct implementation of
createMoveCommand(). It doesn't take a collection of items. How does it
know that a batch of items are being moved at once?

Another thing is, if I return UnexecutableCommand.INSTANCE in that
function, then dragging and dropping ObjectA items has "weird" behavior.
The dragged item seems to be copied into the new slot, and a null
exeception is thrown because an item appears to be removed from the end
of my listA.

Am I going about this the wrong way? Can anybody point me in the right
direction on how to set a breakpoint only for the "drop" action?

Also, I'm wondering how a compound command is achieved for
MoveCommand(). I don't see it accepting a collection, so how does it
know to undo/redo a whole batch of commands when moving multiple items
at once?

If I can figure out these things, I think I'll be closer to creating my
own compound command that will also "fix" pointerToA values when moving
items around.

Thanks for any help you can provide, and sorry for the long-winded question!

-Jeff
Re: help overriding createMoveCommand() or createDragAndDropCommand() [message #558364 is a reply to message #558355] Sat, 11 September 2010 18:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Jeff,

Comments below.

Jeff S. wrote:
> I've been trying to figure out the best way to handle move/drag-n-drop
> events for one of my objects. I will try to explain below. I've
> searched the newsgroup and the EMF book, and am still having some
> problems trying to solve my issue. I believe I want to override
> createMoveCommand() or createDragAndDropCommand(), but can't find any
> concrete examples, and am having problems debugging (and setting up
> breakpoints in the right place).
Debugging drag and drop is hard because stopping at a breakpoint kills
the flow of control...
>
> Here's an example setup / ecore model:
>
> MainObject
> listA [0...100]: ObjectA
> listB [0...200]: ObjectB
> ObjectA
> name: String
> ObjectB
> name: String
> pointerToA: Int
>
>
> When I drag and drop objects in listA, I would like to "fix" all the
> ObjectB#pointerToA values based on a preference. If the preference is
> true, then I need to update pointerToA with the new indexes of
> ObjectA; if the preference is false, then I don't need to do anything:
> pointerA can stay pointing at the old index.
>
> This is a simplified example, but should describe my issue.
>
> Anyways, in MainObjectItemProvider, I've tried overriding both
> createDragAndDropCommand() and createMoveCommand().
>
> When I return UnexecutableCommand.INSTANCE for
> createDragAndDropCommand(), it seems to have no effect. I can move
> ObjectA items around in my editor- and they behave the same way they
> did before I overrode createDragAndDropCommand(). If I put a
> breakpoint in that function, I see that it is never called when I
> drag-n-drop items.
EditingDomainViewerDropAdapter.DragAndDropCommandInformation .createCommand
calls DragAndDropCommand.create which calls
domain.createCommand(DragAndDropCommand.class which dispatches to the
owner, the thing onto which you are dropping. That might well be
another ObjectA instance.
>
> When I add a breakpoint on createMoveCommand(), I see that it is being
> called when I drag-n-drop ObjectA items in my editor. The problem is,
> my breakpoint is triggered when I am "dragging" items. I don't know
> how to set the breakpoint to only trigger when I "drop" the items.
Anything you do to affect the state should happen when the command is
executed, not when it's being created...
>
> Also, I can't figure out the correct implementation of
> createMoveCommand(). It doesn't take a collection of items. How does
> it know that a batch of items are being moved at once?
You'll see that DragAndDropCommand.prepareDropMoveInsert creates a bunch
of MoveCommands and composed them.
>
> Another thing is, if I return UnexecutableCommand.INSTANCE in that
> function, then dragging and dropping ObjectA items has "weird"
> behavior. The dragged item seems to be copied into the new slot, and
> a null exeception is thrown because an item appears to be removed from
> the end of my listA.
Not sure about that. DragAndDrop tries a whole bunch of different
things. If a move doesn't work, it will create a copy and try to add
that copy.
>
> Am I going about this the wrong way? Can anybody point me in the
> right direction on how to set a breakpoint only for the "drop" action?
In the end, cut and paste should do the same thing shouldn't it?
>
> Also, I'm wondering how a compound command is achieved for
> MoveCommand(). I don't see it accepting a collection, so how does it
> know to undo/redo a whole batch of commands when moving multiple items
> at once?
They're composed into a compound command which handles undo and redoing
each one.
>
> If I can figure out these things, I think I'll be closer to creating
> my own compound command that will also "fix" pointerToA values when
> moving items around.
Hopefully that's enough hints...
>
> Thanks for any help you can provide, and sorry for the long-winded
> question!
>
> -Jeff


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: help overriding createMoveCommand() or createDragAndDropCommand() [message #558369 is a reply to message #558364] Sat, 11 September 2010 18:59 Go to previous message
Jeff S. is currently offline Jeff S.Friend
Messages: 29
Registered: July 2009
Junior Member
Ed-

Thanks a lot for the help. You definitely gave me some places to start
looking.


On 9/11/2010 2:07 PM, Ed Merks wrote:
> Jeff,
>
> Comments below.
>
> Jeff S. wrote:
>> I've been trying to figure out the best way to handle move/drag-n-drop
>> events for one of my objects. I will try to explain below. I've
>> searched the newsgroup and the EMF book, and am still having some
>> problems trying to solve my issue. I believe I want to override
>> createMoveCommand() or createDragAndDropCommand(), but can't find any
>> concrete examples, and am having problems debugging (and setting up
>> breakpoints in the right place).
> Debugging drag and drop is hard because stopping at a breakpoint kills
> the flow of control...
>>
>> Here's an example setup / ecore model:
>>
>> MainObject
>> listA [0...100]: ObjectA
>> listB [0...200]: ObjectB
>> ObjectA
>> name: String
>> ObjectB
>> name: String
>> pointerToA: Int
>>
>>
>> When I drag and drop objects in listA, I would like to "fix" all the
>> ObjectB#pointerToA values based on a preference. If the preference is
>> true, then I need to update pointerToA with the new indexes of
>> ObjectA; if the preference is false, then I don't need to do anything:
>> pointerA can stay pointing at the old index.
>>
>> This is a simplified example, but should describe my issue.
>>
>> Anyways, in MainObjectItemProvider, I've tried overriding both
>> createDragAndDropCommand() and createMoveCommand().
>>
>> When I return UnexecutableCommand.INSTANCE for
>> createDragAndDropCommand(), it seems to have no effect. I can move
>> ObjectA items around in my editor- and they behave the same way they
>> did before I overrode createDragAndDropCommand(). If I put a
>> breakpoint in that function, I see that it is never called when I
>> drag-n-drop items.
> EditingDomainViewerDropAdapter.DragAndDropCommandInformation .createCommand
> calls DragAndDropCommand.create which calls
> domain.createCommand(DragAndDropCommand.class which dispatches to the
> owner, the thing onto which you are dropping. That might well be another
> ObjectA instance.
>>
>> When I add a breakpoint on createMoveCommand(), I see that it is being
>> called when I drag-n-drop ObjectA items in my editor. The problem is,
>> my breakpoint is triggered when I am "dragging" items. I don't know
>> how to set the breakpoint to only trigger when I "drop" the items.
> Anything you do to affect the state should happen when the command is
> executed, not when it's being created...
>>
>> Also, I can't figure out the correct implementation of
>> createMoveCommand(). It doesn't take a collection of items. How does
>> it know that a batch of items are being moved at once?
> You'll see that DragAndDropCommand.prepareDropMoveInsert creates a bunch
> of MoveCommands and composed them.
>>
>> Another thing is, if I return UnexecutableCommand.INSTANCE in that
>> function, then dragging and dropping ObjectA items has "weird"
>> behavior. The dragged item seems to be copied into the new slot, and a
>> null exeception is thrown because an item appears to be removed from
>> the end of my listA.
> Not sure about that. DragAndDrop tries a whole bunch of different
> things. If a move doesn't work, it will create a copy and try to add
> that copy.
>>
>> Am I going about this the wrong way? Can anybody point me in the right
>> direction on how to set a breakpoint only for the "drop" action?
> In the end, cut and paste should do the same thing shouldn't it?
>>
>> Also, I'm wondering how a compound command is achieved for
>> MoveCommand(). I don't see it accepting a collection, so how does it
>> know to undo/redo a whole batch of commands when moving multiple items
>> at once?
> They're composed into a compound command which handles undo and redoing
> each one.
>>
>> If I can figure out these things, I think I'll be closer to creating
>> my own compound command that will also "fix" pointerToA values when
>> moving items around.
> Hopefully that's enough hints...
>>
>> Thanks for any help you can provide, and sorry for the long-winded
>> question!
>>
>> -Jeff
Previous Topic:Getting Helios final version from git
Next Topic:[teneo] entity class not found
Goto Forum:
  


Current Time: Fri Apr 19 03:25:00 GMT 2024

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

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

Back to the top