diff options
author | Sebastian Nyholm <sebastian@vaadin.com> | 2014-05-27 14:46:47 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-08-18 11:34:03 +0000 |
commit | 1020faa337eddeb07f141cb7ef12fbb20bd2ded2 (patch) | |
tree | 3fe93c549eed111988c9c8f5d057b8cbadd5c9f0 /client | |
parent | a960cfd12b8fb42ae78e39ffb61c04e3a3b831bf (diff) | |
download | vaadin-framework-1020faa337eddeb07f141cb7ef12fbb20bd2ded2.tar.gz vaadin-framework-1020faa337eddeb07f141cb7ef12fbb20bd2ded2.zip |
Fixes DragAndDropWrapper does not support choosing a custom component as the drag image (#13836)
Amend : Fixes the comments for the last commit.
Amend 2: Fixes a nullpointer found in a certain test scenario
Change-Id: I72327f5f8ab9e46d88e1ebed8f1db3a7da39d7d8
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VDragAndDropWrapper.java | 27 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java | 26 |
2 files changed, 52 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java index 4010ffd542..7bf341a387 100644 --- a/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -114,7 +114,8 @@ public class VDragAndDropWrapper extends VCustomComponent implements * @return true if the event was handled as a drag start event */ private boolean startDrag(NativeEvent event) { - if (dragStartMode == WRAPPER || dragStartMode == COMPONENT) { + if (dragStartMode == WRAPPER || dragStartMode == COMPONENT + || dragStartMode == COMPONENT_OTHER) { VTransferable transferable = new VTransferable(); transferable.setDragSource(getConnector()); @@ -130,6 +131,10 @@ public class VDragAndDropWrapper extends VCustomComponent implements if (dragStartMode == WRAPPER) { dragEvent.createDragImage(getElement(), true); + } else if (dragStartMode == COMPONENT_OTHER + && getDragImageWidget() != null) { + dragEvent.createDragImage(getDragImageWidget().getElement(), + true); } else { dragEvent.createDragImage(widget.getElement(), true); } @@ -142,6 +147,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements protected final static int COMPONENT = 1; protected final static int WRAPPER = 2; protected final static int HTML5 = 3; + protected final static int COMPONENT_OTHER = 4; /** For internal use only. May be removed or replaced in the future. */ public int dragStartMode; @@ -458,6 +464,7 @@ public class VDragAndDropWrapper extends VCustomComponent implements * Flag used by html5 dd */ private boolean currentlyValid; + private Widget dragImageWidget; private static final String OVER_STYLE = "v-ddwrapper-over"; @@ -661,4 +668,22 @@ public class VDragAndDropWrapper extends VCustomComponent implements notifySizePotentiallyChanged(); } + /** + * Set the widget that will be used as the drag image when using + * DragStartMode {@link COMPONENT_OTHER} . + * + * @param widget + */ + public void setDragAndDropWidget(Widget widget) { + dragImageWidget = widget; + } + + /** + * @return the widget used as drag image. Returns <code>null</code> if no + * widget is set. + */ + public Widget getDragImageWidget() { + return dragImageWidget; + } + } diff --git a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java index afb521b141..f222721e24 100644 --- a/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java +++ b/client/src/com/vaadin/client/ui/draganddropwrapper/DragAndDropWrapperConnector.java @@ -17,8 +17,12 @@ package com.vaadin.client.ui.draganddropwrapper; import java.util.HashMap; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.client.ApplicationConnection; +import com.vaadin.client.ComponentConnector; +import com.vaadin.client.ConnectorMap; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; @@ -81,6 +85,25 @@ public class DragAndDropWrapperConnector extends CustomComponentConnector getWidget().dragStartMode = uidl .getIntAttribute(DragAndDropWrapperConstants.DRAG_START_MODE); + + String dragImageComponentConnectorId = uidl + .getStringAttribute(DragAndDropWrapperConstants.DRAG_START_COMPONENT_ATTRIBUTE); + + ComponentConnector connector = null; + if (dragImageComponentConnectorId != null) { + connector = (ComponentConnector) ConnectorMap.get(client) + .getConnector(dragImageComponentConnectorId); + + if (connector == null) { + getLogger().log( + Level.WARNING, + "DragAndDropWrapper drag image component" + + " connector now found. Make sure the" + + " component is attached."); + } else { + getWidget().setDragAndDropWidget(connector.getWidget()); + } + } getWidget().initDragStartMode(); getWidget().html5DataFlavors = uidl .getMapAttribute(DragAndDropWrapperConstants.HTML5_DATA_FLAVORS); @@ -95,4 +118,7 @@ public class DragAndDropWrapperConnector extends CustomComponentConnector return (VDragAndDropWrapper) super.getWidget(); } + private static Logger getLogger() { + return Logger.getLogger(DragAndDropWrapperConnector.class.getName()); + } } |