Class VDragAndDropManager
- java.lang.Object
-
- com.vaadin.client.ui.dd.VDragAndDropManager
-
public class VDragAndDropManager extends Object
Helper class to manage the state of drag and drop event on Vaadin client side. Can be used to implement most of the drag and drop operation automatically via cross-browser event preview method or just as a helper when implementing own low level drag and drop operation (like with HTML5 api).Singleton. Only one drag and drop operation can be active anyways. Use
get()
to get instance. TODO cancel drag and drop if more than one touches !?
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
VDragAndDropManager.DDManagerMediator
Implementation if this interface is provided as a parameter to DDEventHandleStrategy methods.
-
Field Summary
Fields Modifier and Type Field Description static String
ACTIVE_DRAG_SOURCE_STYLENAME
static int
MINIMUM_DISTANCE_TO_START_DRAG
-
Constructor Summary
Constructors Modifier Constructor Description protected
VDragAndDropManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endDrag()
Drag is ended (drop happened) on current drop handler.void
executeWhenReady(com.google.gwt.user.client.Command command)
Method to execute commands when all existing dd related tasks are completed (some may require server visit).protected VDropHandler
findDragTarget(com.google.gwt.dom.client.Element element)
First seeks the widget from this element, then iterates widgets until one implement HasDropHandler.static VDragAndDropManager
get()
protected ApplicationConnection
getCurrentDragApplicationConnection()
VDropHandler
getCurrentDropHandler()
protected DDEventHandleStrategy
getEventHandleStrategy()
Returns DnD strategy to handle native preview events used by the manager.void
handleServerResponse(ValueMap valueMap)
void
interruptDrag()
The drag and drop operation is ended, but drop did not happen.void
setCurrentDropHandler(VDropHandler currentDropHandler)
If drag and drop operation is not handled byVDragAndDropManager
s internal handler, this can be used to update currentVDropHandler
.VDragEvent
startDrag(VTransferable transferable, com.google.gwt.dom.client.NativeEvent startEvent, boolean handleDragEvents)
This method is used to start Vaadin client side drag and drop operation.protected void
updateDragImagePosition(com.google.gwt.dom.client.NativeEvent gwtEvent, com.google.gwt.dom.client.Element dragImage)
void
visitServer(VDragEventServerCallback acceptCallback)
Visits server during drag and drop procedure.
-
-
-
Field Detail
-
ACTIVE_DRAG_SOURCE_STYLENAME
public static final String ACTIVE_DRAG_SOURCE_STYLENAME
- See Also:
- Constant Field Values
-
MINIMUM_DISTANCE_TO_START_DRAG
public static final int MINIMUM_DISTANCE_TO_START_DRAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCurrentDropHandler
public VDropHandler getCurrentDropHandler()
-
setCurrentDropHandler
public void setCurrentDropHandler(VDropHandler currentDropHandler)
If drag and drop operation is not handled byVDragAndDropManager
s internal handler, this can be used to update currentVDropHandler
.- Parameters:
currentDropHandler
-
-
get
public static VDragAndDropManager get()
-
startDrag
public VDragEvent startDrag(VTransferable transferable, com.google.gwt.dom.client.NativeEvent startEvent, boolean handleDragEvents)
This method is used to start Vaadin client side drag and drop operation. Operation may be started by virtually any Widget.Cancels possible existing drag. TODO figure out if this is always a bug if one is active. Maybe a good and cheap lifesaver thought.
If possible, method automatically detects current
VDropHandler
and firesVDropHandler.dragEnter(VDragEvent)
event on it.May also be used to control the drag and drop operation. If this option is used,
VDropHandler
is searched on mouse events and appropriate methods on it called automatically.- Parameters:
transferable
-nativeEvent
-handleDragEvents
- if true,VDragAndDropManager
handles the drag and drop operation GWT event preview.- Returns:
-
updateDragImagePosition
protected void updateDragImagePosition(com.google.gwt.dom.client.NativeEvent gwtEvent, com.google.gwt.dom.client.Element dragImage)
-
findDragTarget
protected VDropHandler findDragTarget(com.google.gwt.dom.client.Element element)
First seeks the widget from this element, then iterates widgets until one implement HasDropHandler. Returns DropHandler from that.- Parameters:
element
-- Returns:
-
endDrag
public void endDrag()
Drag is ended (drop happened) on current drop handler. Calls drop method on current drop handler and does appropriate cleanup.
-
interruptDrag
public void interruptDrag()
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.
-
visitServer
public void visitServer(VDragEventServerCallback acceptCallback)
Visits server during drag and drop procedure. Transferable and event type is given to server side counterpart of DropHandler. If another server visit is started before the current is received, the current is just dropped. TODO consider if callback should have interrupted() method for cleanup.- Parameters:
acceptCallback
-
-
handleServerResponse
public void handleServerResponse(ValueMap valueMap)
-
getEventHandleStrategy
protected DDEventHandleStrategy getEventHandleStrategy()
Returns DnD strategy to handle native preview events used by the manager. Subclasses can override this method to return custom strategy or use GWT deferred binding.- Returns:
- internal DnD native preview event handler
-
getCurrentDragApplicationConnection
protected ApplicationConnection getCurrentDragApplicationConnection()
-
executeWhenReady
public void executeWhenReady(com.google.gwt.user.client.Command command)
Method to execute commands when all existing dd related tasks are completed (some may require server visit).Using this method may be handy if criterion that uses lazy initialization are used. Check
TODO Optimization: consider if we actually only need to keep the last command in queue here.
- Parameters:
command
-
-
-