Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Native DND drag over effect
Native DND drag over effect [message #897786] Wed, 25 July 2012 09:02 Go to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
Hello!

I have a table where i have set up native DND to handle drag and drop between my editor and that table. But i want to change the visual "drag over effect" when i drag a table item over my editor. See the attached file. Instead of seeing the row that is dragged i want to display my own custom figure. Anyone got any good advices on how to solve this?

Best regards
Martin
  • Attachment: test.png
    (Size: 21.18KB, Downloaded 128 times)
Re: Native DND drag over effect [message #897883 is a reply to message #897786] Wed, 25 July 2012 11:13 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Martin,

although I haven't any concrete advice for you, you could find some inspiration in this article
http://www.eclipse.org/articles/Article-GEF-dnd/GEF-dnd.html
Re: Native DND drag over effect [message #898725 is a reply to message #897883] Fri, 27 July 2012 11:15 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
Thank you Jan,

but i still can't figure out where the "drag over effect" is painted or how to replace it with a figure i can decide. Someone got a hint? Smile
Re: Native DND drag over effect [message #898732 is a reply to message #898725] Fri, 27 July 2012 11:39 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Do you want to change the drag effect over the table or over the GEF editor?
Re: Native DND drag over effect [message #898734 is a reply to message #898732] Fri, 27 July 2012 11:44 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
I want to change it when it is dragged over the editor.
Re: Native DND drag over effect [message #898772 is a reply to message #898734] Fri, 27 July 2012 14:00 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
You have to extend the AbstractTransferDropTargetListener and add this listener to the EditPartViewer:
getGraphicalViewer().addDropTargetListener(new YourViewerimpl(getGraphicalViewer()));

The abstract class has many useful you can override. By the way, looking at the source code, it calls showTargetFeedback() on the target EditPart.
Re: Native DND drag over effect [message #898794 is a reply to message #898772] Fri, 27 July 2012 16:03 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
Thank you for your help Jan, i will look in to this after the weekend.

Best
Martin
Re: Native DND drag over effect [message #899685 is a reply to message #898772] Wed, 01 August 2012 20:29 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
This was not exactly was I was looking for (i think). I want to change what is called the drag source feedback image/figure.

I use a DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) as listener on the item in my table, but if i extend that i am only allowed to change the image when starting the drag not during the drag.

In my editor i use corresponding DropTargetAdapter to listen for drops. If i extend the dragOver method here i can edit when dragging over my editor occurs. However i dont know how to access the drag source feedback from here. I think that I in some way need to access the DragSourceEvent. Is this the right way to go?
Re: Native DND drag over effect [message #899787 is a reply to message #899685] Thu, 02 August 2012 11:14 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Well, I have two facts for you:

1) You can set the event.image in the org.eclipse.swt.dnd.DragSourceAdapter.dragStart(DragSourceEvent event) method.
This image will be shown all the time the drag&drop occurs, even if the cursor gets over the GEF edior.

2) You can show any figure you want in the editor using the target editPart's layout editPolicy's showLayoutTargetFeedback(Request request) method.
Again, take a look at the article I posted to you.

Normally, the data object being dragged is accessible only in drop and not in hover of the DropTargetListener.
So you could show a "dumb" feedback figure, but not the real data that are dragged from the table.

I don't know if this is true for all platforms, but on Windows you can get the data even in the hover like this:

TextTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType)

Note it's called in the org.eclipse.gef.dnd.AbstractTransferDropTargetListener.handleDragOver() method.
Re: Native DND drag over effect [message #900202 is a reply to message #899787] Sun, 05 August 2012 12:34 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
Thank you Jan!

1) I have tried this, but since i do want to change the figure depending on whats beneath the mouse this do not work.

2) Tried this as well, but since i need to access the data that is being dragged when i update the feedback figure i cant get this to work. Since the CreateRequest is only issued when the actual drop occurs.

Have also just tried to use the dragOver method in the DropTargetAdapter and access the feedback layer directly to add a figure there. But then i cannot manage to remove the feedback figure that is created by the DragSource. What am i missing?

Best Regards
Martin
Re: Native DND drag over effect [message #900249 is a reply to message #900202] Mon, 06 August 2012 07:32 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
As I wrote.

If you are running on the windows, you can get the data being dragged from the transfer you use e.g. TextTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType) in the org.eclipse.gef.dnd.AbstractTransferDropTargetListener.handleDragOver() method.
If you look at the handleDragOver:
/**
 * Called whenever the User drags over the target. By default, the target Request and
 * target EditPart are updated, feedback is shown, and auto-expose occurs.
 */
protected void handleDragOver() {
	updateTargetRequest();
	updateTargetEditPart();
	showTargetFeedback();
	if (exposeHelper != null) {
		//If the expose helper does not wish to continue, set helper to null.
		if (!exposeHelper.step(getDropLocation()))
			exposeHelper = null;
	}
}

it calls all you need to show your feedback figure. You have to set the data to the Request and maybe current mouse location.

DropTargetAdapter is pure SWT class, GEF uses its own mechanism above it. So don't use the adapter directly, you should use AbstractTransferDropTargetListener.
Re: Native DND drag over effect [message #900415 is a reply to message #900249] Mon, 06 August 2012 23:00 Go to previous messageGo to next message
Martin Missing name is currently offline Martin Missing nameFriend
Messages: 14
Registered: June 2011
Junior Member
Thank you again for your answer Jan.

I use OSX. Everything works as expected when i add my feedback figure. Except that i don't know how to remove the "original" feedback coming from the DragSource (event.image). I could set event.image to a dummy figure, but i want to have this original feedback outside of the editor if this is possible?

Best Regards
Martin
Re: Native DND drag over effect [message #900442 is a reply to message #900415] Tue, 07 August 2012 06:40 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I don't think so. If you set an image to event.image, it will be shown all the time until the drop is occurred or the drag is canceled.
Previous Topic:Selectable but non dragable editpart
Next Topic:SelectionProvider
Goto Forum:
  


Current Time: Thu Dec 18 11:42:45 GMT 2014

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

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