fredsa / gwt-dnd

Library providing easy to use mouse or touch based drag-and-drop capabilities to GWT
42 stars 41 forks source link

throw new VetoDragException() leaves MouseDragHandler in inconsistent state #114

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of GWT are you using? 1.3.3? 1.4.60? Other?

v2.0.3

What version of the gwt-dnd jar file or library file are you using?

v3.0.1

What operating system(s) are you using? Windows? Linux? Mac?

All of the above

Does the issue occur in web mode, hosted mode, both or don't know?

At least hosted mode, didn't test web mode but considering the nature of the 
bug I would assume both.

What browser(s) do you use? Firefox, IE, Safari, other?

All of the above

What is the browser version (if you know) from Help->About?

Irrelevant

What steps will reproduce the problem? Please attach sample code if you
can.
1.  throw new VetoDragException() inside the DragHandler.onPreviewDragStart() 
method
2.
3.

What is the expected output? What do you see instead?

Throwing the VetoDragException does indeed cancel the drag operation, but it 
leaves com.allen_sauer.gwt.dnd.client.MouseDragHandler in a state such that 
dragging cannot be initiated again without it first receiving an onMouseUp() 
event.

Basically, the static variable MouseDragHandler.mouseDownWidget doesn't get 
reset to null when MouseDragHandler.startDragging() catches the 
VetoDragException, which causes subsequent calls into 
MouseDragHandler.onMouseDown() to return on line 117.

My patch for this is:

Index: src/com/allen_sauer/gwt/dnd/client/MouseDragHandler.java
===================================================================
--- src/com/allen_sauer/gwt/dnd/client/MouseDragHandler.java    (revision 10904)
+++ src/com/allen_sauer/gwt/dnd/client/MouseDragHandler.java    (working copy)
@@ -353,6 +353,7 @@
     } catch (VetoDragException ex) {
       context.vetoException = ex;
       mouseDown = false;
+      mouseDownWidget = null;
       return;
     }
     context.dragController.dragStart();

Do you have a workaround?

Locally patch MouseDragHandler.java

Please provide any additional information below.

This seems like the correct fix after tracing through the code, but there might 
be a better way.  It does seem strange to me that 'mouseDownWidget' is declared 
static, but since the user wouldn't have clicked on more than 1 Widget at a 
time, I suppose it doesn't really matter.  Making it non-static wouldn't fix 
the problem anyways since MouseDragHandler is instantiated once per 
AbstractDragController instance.

FWIW, my DragController setup code goes a little sumthin' like this:

    _dragController = new PickupDragController(_panel, true);
        _dragController.addDragHandler(new DragHandler() {
            public void onDragEnd(DragEndEvent event) {
            }

            public void onDragStart(DragStartEvent event) {
            }

            public void onPreviewDragEnd(DragEndEvent event) throws VetoDragException {
            }

            public void onPreviewDragStart(DragStartEvent event) throws VetoDragException {
                Event e = Event.getCurrentEvent();
                if (e.getShiftKey())    // if the shift key is down, we don't allow dragging
                    throw new VetoDragException();
            }
        });

Original issue reported on code.google.com by eeb...@gmail.com on 15 Jun 2010 at 11:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I'm issuing the same problem in version 3.0.2. 

Original comment by thobias....@gmail.com on 27 Sep 2010 at 9:32

GoogleCodeExporter commented 9 years ago
Same here. Would really appreciate if this could be fixed soon.

Original comment by andreas....@gmail.com on 27 Sep 2010 at 9:47

GoogleCodeExporter commented 9 years ago
I believe this was fixed in r1027 for issue 106.

Original comment by fredsa@google.com on 29 Sep 2010 at 5:18