Class 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 !?

    • Constructor Detail

      • VDragAndDropManager

        protected VDragAndDropManager()
    • Method Detail

      • getCurrentDropHandler

        public VDropHandler getCurrentDropHandler()
      • setCurrentDropHandler

        public void setCurrentDropHandler​(VDropHandler currentDropHandler)
        If drag and drop operation is not handled by VDragAndDropManagers internal handler, this can be used to update current VDropHandler .
        Parameters:
        currentDropHandler -
      • 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 fires VDropHandler.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 -