Bug 286772 - Want to be able to cancel a drag by returning event.doit = false in setDragData
Summary: Want to be able to cancel a drag by returning event.doit = false in setDragData
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Windows Vista
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-17 04:23 EDT by saurav sarkar CLA
Modified: 2019-09-06 15:29 EDT (History)
2 users (show)

See Also:


Attachments
Error Log (2.58 KB, text/plain)
2009-08-17 04:23 EDT, saurav sarkar CLA
no flags Details
Implementaion fo CommonDragAdapter (1.87 KB, application/octet-stream)
2009-08-25 01:53 EDT, saurav sarkar CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description saurav sarkar CLA 2009-08-17 04:23:08 EDT
Created attachment 144648 [details]
Error Log

Build ID: M20090211-1700

Steps To Reproduce:
1. An extension extends the CommonDragAdapterAssistant.
2. Get Transfer types returns a Text transfer object.
3. setDragData method in the CommonDragAdatperAssistant returns event.doIt false under some conditions.But still the drag continues for those conditions which results the attached log.


More information:
org.eclipse.swt.SWTException: Data does not have correct format for type
at org.eclipse.swt.dnd.DND.error(DND.java:277)
at org.eclipse.swt.dnd.DND.error(DND.java:228)
at org.eclipse.swt.dnd.TextTransfer.javaToNative(TextTransfer.java:61)
at org.eclipse.swt.dnd.DragSource.GetData(DragSource.java:469)
at org.eclipse.swt.dnd.DragSource.access$7(DragSource.java:435)
at org.eclipse.swt.dnd.DragSource$4.method3(DragSource.java:258)
at org.eclipse.swt.internal.ole.win32.COMObject.callback3(COMObject.java:92)
at org.eclipse.swt.internal.ole.win32.COM.DoDragDrop(Native Method)
at org.eclipse.swt.dnd.DragSource.drag(DragSource.java:362)
at org.eclipse.swt.dnd.DragSource.access$0(DragSource.java:288)
at org.eclipse.swt.dnd.DragSource$1.handleEvent(DragSource.java:171)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Comment 3 Francis Upton IV CLA 2009-08-17 10:20:36 EDT
(In reply to comment #2)
Unfortunately i am not able to test in 3.5 as our
> productized IDE has not still migrated to 3.5.

You are aware I hope that even if this is a bug in 3.5 (or 3.6) there are no further releases of 3.4.x, a fix will be provided only in 3.6 (and possibly 3.5.1 or 2).
Comment 4 Francis Upton IV CLA 2009-08-20 01:19:34 EDT
Make sure you return "true" from setDragData() if you are setting event.doIt to false, this should cancel the drag.  If you are returning false from setDragData() it will continue looking for another way to set the data, which is probably not what you want.

I'm going to close this; if my suggestion does not fix your problem, please reopen this, and please provide your CommonDragAdapterAssistant subclass.
Comment 5 saurav sarkar CLA 2009-08-25 01:11:19 EDT
(In reply to comment #4)
> Make sure you return "true" from setDragData() if you are setting event.doIt to
> false, this should cancel the drag.  If you are returning false from
> setDragData() it will continue looking for another way to set the data, which
> is probably not what you want.
> I'm going to close this; if my suggestion does not fix your problem, please
> reopen this, and please provide your CommonDragAdapterAssistant subclass.

I tried everything it did not work.

Below is the Code from the CommonDragAdapter


[code]

if(assistants[i].setDragData(event,
									(IStructuredSelection) selection)) {
								return;
							}
						} catch (RuntimeException re) {
							NavigatorPlugin.logError(0, re.getMessage(), re);
						}
					}

				}
			}

			event.doit = false;
[/code]

My case it returns false so it sets event.doit=false;

there is no checkingfor event.doit done in CNF acc. to me
which is done in DelegatingDragAdpater in normal JFace viewer.
I am not very sure so could you please provide your inputs on this.
So reopening the bug.

cheers,
Saurav
Comment 6 Francis Upton IV CLA 2009-08-25 01:23:41 EDT
(In reply to comment #5)

> 
> My case it returns false so it sets event.doit=false;
Your implementation of the method setDragData() should return true if you want to have event.doit used.  If you return false from setDragData() whatever you set event.doit to will be ignored. 

> 
> there is no checkingfor event.doit done in CNF acc. to me
Look at the CommonDragAdapter.dragSetData() where it calls setDragData(), note that it returns if you return true, and if you have set event.doit to false, then that should apply.

Again, I'm closing.  If you are still having trouble please reopen and please provide your complete implementation of your CommonDragAdaptorAssistant subclass (you did not provide that as far as I can see).


Comment 7 saurav sarkar CLA 2009-08-25 01:53:30 EDT
Created attachment 145511 [details]
Implementaion fo CommonDragAdapter
Comment 8 saurav sarkar CLA 2009-08-25 01:55:06 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > 
> > My case it returns false so it sets event.doit=false;
> Your implementation of the method setDragData() should return true if you want
> to have event.doit used.  If you return false from setDragData() whatever you
> set event.doit to will be ignored. 
> > 
> > there is no checkingfor event.doit done in CNF acc. to me
> Look at the CommonDragAdapter.dragSetData() where it calls setDragData(), note
> that it returns if you return true, and if you have set event.doit to false,
> then that should apply.
> Again, I'm closing.  If you are still having trouble please reopen and please
> provide your complete implementation of your CommonDragAdaptorAssistant
> subclass (you did not provide that as far as I can see).

In the attachement you could find the condition having the comments.
I returned true as well as have set the event.doit=false.But still getting the same error.Any other variable of the event object i need to set?
Comment 9 Francis Upton IV CLA 2009-08-25 02:09:51 EDT
Ok, now I'm remembering this.  The problem is that event.doit has no effect on a setDragData call.  Once you have agreed to start the drag, it must finish.  You can't cancel it at setDragData time.  See SWT DragSourceEvent (the description of the doit flag).  Also see the SWT DragSourceListener.

I'm remembering in 3.5 we had some conversations with the SWT about doing someting about this because sometimes it's desirable to be able to cancel the drag if you don't like the data that you have, but I have been unable to find any of the bug reports that touched this area.

I'm going to transfer this to SWT for comment to see if they remember anything.
Comment 10 Eclipse Webmaster CLA 2019-09-06 15:29:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.