View Full Version : Drag & Drop Copy/Move question

31 Jul 2009, 6:10 AM
Hi everyone.

I am using drag and drop for reordering/copying nodes over a tree.

I want to perform a Move operation by default, but I want to change the operation to Copy when the user presses the alt key while dragging...

Is it possible to achieve this behaviour?

Thanks for replying.


31 Jul 2009, 6:16 AM
extend your DragSource and override onDragDrop.

Operation o = e.getOperation();

I havent tested that good, but should work

31 Jul 2009, 6:31 AM
Tks for the reply sven...

But this didn't work.

The default operation (MOVE) was applied.

And even if this worked, I guess the icon used while dragging would also not be updated...

Do you have any other idea?

31 Jul 2009, 6:41 AM
Actually it almost worked...
Sorry, I did not what you were telling me to do... I created a listener... instead of override the TreePanelDragSource...

Anyway, the way you suggested actually did not move the node...
But the copy failed in some way...

Also, the icon while dragging was not updated as well... (as expected).
I will try to think about something else...
If someone knows something about this, please post it here..

Actually I don't care about the behaviour... this is ok for me if the new node is not created...
Since my tree structure is defined in the server side, a Operation.NONE for me would be the best one.
I just needed to define a different icon:
one icon for me copy operation
one icon for the move operation

3 Aug 2009, 4:25 AM
Ok, so I figured it out how to change the icons on the event.

You have to extend the TreeDropTarget (in my case I am using the Drop on a tree), overriding this two methods: handleAppend and handleInsert.

Then you can change your css in the following way (for example):

protected void handleAppend(DNDEvent event, TreeItem item) {
super.handleAppend(event, item);
if (event.isAltKey()) {
event.status.setStatus(true, "x-dd-drop-ok-add");
} else {
event.status.setStatus(true, "x-dd-drop-ok");

Hope this can be helpful for someone else as well.