diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-30 14:45:02 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2010-03-30 14:45:02 +0000 |
commit | 9a552d520db49bdd7d68c8ad023124d692949c5b (patch) | |
tree | d3d71ebd55a43be526ac423dabd057d391ac4987 /src | |
parent | 95d94f7de2011c2b8c7ec20823f3c833339a0160 (diff) | |
download | vaadin-framework-9a552d520db49bdd7d68c8ad023124d692949c5b.tar.gz vaadin-framework-9a552d520db49bdd7d68c8ad023124d692949c5b.zip |
fixes #4392
svn changeset:12244/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java index 7fdf213956..e44a776f33 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragAndDropManager.java @@ -9,6 +9,7 @@ import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Event; @@ -41,10 +42,23 @@ public class VDragAndDropManager { public void onPreviewNativeEvent(NativePreviewEvent event) { NativeEvent nativeEvent = event.getNativeEvent(); + + int typeInt = event.getTypeInt(); + if (typeInt == Event.ONKEYDOWN) { + int keyCode = event.getNativeEvent().getKeyCode(); + if (keyCode == KeyCodes.KEY_ESCAPE) { + // end drag if ESC is hit + interruptDrag(); + event.cancel(); + event.getNativeEvent().preventDefault(); + } + // no use for handling for any key down event + return; + } + currentDrag.setCurrentGwtEvent(nativeEvent); updateDragImagePosition(); - int typeInt = event.getTypeInt(); Element targetElement = (Element) nativeEvent.getEventTarget() .cast(); if (dragElement != null && dragElement.isOrHasChild(targetElement)) { @@ -385,21 +399,6 @@ public class VDragAndDropManager { return currentDrag; } - public void interruptDrag() { - if (currentDrag != null) { - ApplicationConnection.getConsole() - .log("Drag operation interrupted"); - if (currentDropHandler != null) { - currentDrag.setCurrentGwtEvent(null); - currentDropHandler.dragLeave(currentDrag); - currentDropHandler = null; - serverCallback = null; - visitId = -1; // ignore possibly on going server check - } - currentDrag = null; - } - } - private void updateDragImagePosition() { if (currentDrag.getCurrentGwtEvent() != null && dragElement != null) { Style style = dragElement.getStyle(); @@ -452,20 +451,43 @@ public class VDragAndDropManager { } + /** + * Drag is ended (drop happened) on current drop handler. Calls drop method + * on current drop handler and does appropriate cleanup. + */ public void endDrag() { + endDrag(true); + } + + /** + * The drag and drop operation is ended, but drop did not happen. If + * operation is currently on a drop handler, its dragLeave method is called + * and appropriate cleanup happens. + */ + public void interruptDrag() { + endDrag(false); + } + + private void endDrag(boolean doDrop) { if (handlerRegistration != null) { handlerRegistration.removeHandler(); handlerRegistration = null; } if (currentDropHandler != null) { - // we have dropped on a drop target - boolean sendTransferableToServer = currentDropHandler - .drop(currentDrag); - if (sendTransferableToServer) { - doRequest(DragEventType.DROP); + if (doDrop) { + // we have dropped on a drop target + boolean sendTransferableToServer = currentDropHandler + .drop(currentDrag); + if (sendTransferableToServer) { + doRequest(DragEventType.DROP); + } + } else { + currentDrag.setCurrentGwtEvent(null); + currentDropHandler.dragLeave(currentDrag); } currentDropHandler = null; serverCallback = null; + visitId = -1; // ignore possibly on going server check } |