diff options
author | Marc Englund <marc@vaadin.com> | 2013-05-24 17:19:51 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-05 09:19:07 +0000 |
commit | 08ba394b1199797e3f0be7efead66e0b5393b5c3 (patch) | |
tree | b7f3259cef66dfa7517585255cd31c39b7117dfe /client | |
parent | d647d7a48a70cf6d4d86500311e235e0778c7dab (diff) | |
download | vaadin-framework-08ba394b1199797e3f0be7efead66e0b5393b5c3.tar.gz vaadin-framework-08ba394b1199797e3f0be7efead66e0b5393b5c3.zip |
Disable drag&drop when source or target component is disabled, re-implementation of 6.8 fix for #11801
Change-Id: Iacd167ad7075620dae59ff2c7789efaf32521c59
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VDragAndDropWrapper.java | 36 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java | 14 |
2 files changed, 37 insertions, 13 deletions
diff --git a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java index f23bf88969..1c1173c295 100644 --- a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -80,7 +80,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public void onMouseDown(MouseDownEvent event) { - if (startDrag(event.getNativeEvent())) { + if (getConnector().isEnabled() + && startDrag(event.getNativeEvent())) { event.preventDefault(); // prevent text selection } } @@ -90,7 +91,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public void onTouchStart(TouchStartEvent event) { - if (startDrag(event.getNativeEvent())) { + if (getConnector().isEnabled() + && startDrag(event.getNativeEvent())) { /* * Dont let eg. panel start scrolling. */ @@ -112,8 +114,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements private boolean startDrag(NativeEvent event) { if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) { VTransferable transferable = new VTransferable(); - transferable.setDragSource(ConnectorMap.get(client).getConnector( - VDragAndDropWrapper.this)); + transferable.setDragSource(getConnector()); ComponentConnector paintable = Util.findPaintable(client, (Element) event.getEventTarget().cast()); @@ -187,7 +188,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements private boolean uploading; - private ReadyStateChangeHandler readyStateChangeHandler = new ReadyStateChangeHandler() { + private final ReadyStateChangeHandler readyStateChangeHandler = new ReadyStateChangeHandler() { @Override public void onReadyStateChange(XMLHttpRequest xhr) { @@ -261,8 +262,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements } if (VDragAndDropManager.get().getCurrentDropHandler() != getDropHandler()) { VTransferable transferable = new VTransferable(); - transferable.setDragSource(ConnectorMap.get(client) - .getConnector(this)); + transferable.setDragSource(getConnector()); vaadinDragEvent = VDragAndDropManager.get().startDrag( transferable, event, false); @@ -458,6 +458,9 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public void dragEnter(VDragEvent drag) { + if (!getConnector().isEnabled()) { + return; + } updateDropDetails(drag); currentlyValid = false; super.dragEnter(drag); @@ -471,6 +474,9 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public void dragOver(final VDragEvent drag) { + if (!getConnector().isEnabled()) { + return; + } boolean detailsChanged = updateDropDetails(drag); if (detailsChanged) { currentlyValid = false; @@ -486,6 +492,9 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override public boolean drop(VDragEvent drag) { + if (!getConnector().isEnabled()) { + return false; + } deEmphasis(true); Map<String, Object> dd = drag.getDropDetails(); @@ -511,14 +520,16 @@ public class VDragAndDropWrapper extends VCustomComponent implements @Override protected void dragAccepted(VDragEvent drag) { + if (!getConnector().isEnabled()) { + return; + } currentlyValid = true; emphasis(drag); } @Override public ComponentConnector getConnector() { - return ConnectorMap.get(client).getConnector( - VDragAndDropWrapper.this); + return VDragAndDropWrapper.this.getConnector(); } @Override @@ -528,6 +539,10 @@ public class VDragAndDropWrapper extends VCustomComponent implements } + public ComponentConnector getConnector() { + return ConnectorMap.get(client).getConnector(this); + } + protected native void hookHtml5DragStart(Element el) /*-{ var me = this; @@ -594,8 +609,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements } private void notifySizePotentiallyChanged() { - LayoutManager.get(client).setNeedsMeasure( - ConnectorMap.get(client).getConnector(getElement())); + LayoutManager.get(client).setNeedsMeasure(getConnector()); } protected void emphasis(VDragEvent drag) { diff --git a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java index ffc146ad04..dd838fdeff 100644 --- a/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -287,7 +287,7 @@ public class VDragAndDropManager { protected VDragAndDropManager() { } - private NativePreviewHandler defaultDragAndDropEventHandler = new DefaultDragAndDropEventHandler(); + private final NativePreviewHandler defaultDragAndDropEventHandler = new DefaultDragAndDropEventHandler(); /** * Flag to indicate if drag operation has really started or not. Null check @@ -469,7 +469,8 @@ public class VDragAndDropManager { if (w == null) { return null; } - while (!(w instanceof VHasDropHandler)) { + while (!(w instanceof VHasDropHandler) + || !isDropEnabled((VHasDropHandler) w)) { w = w.getParent(); if (w == null) { break; @@ -492,6 +493,15 @@ public class VDragAndDropManager { } /** + * Checks if the given {@link VHasDropHandler} really is able to accept + * drops. + */ + private static boolean isDropEnabled(VHasDropHandler target) { + VDropHandler dh = target.getDropHandler(); + return dh != null && dh.getConnector().isEnabled(); + } + + /** * Drag is ended (drop happened) on current drop handler. Calls drop method * on current drop handler and does appropriate cleanup. */ |