com.vaadin.ui.dnd.

Class DragSourceExtension<T extends AbstractComponent>

    • Constructor Detail

      • DragSourceExtension

        public DragSourceExtension​(T target)

        Extends target component and makes it a drag source.

        Parameters:

        target - Component to be extended.

    • Method Detail

      • registerDragSourceRpc

        protected void registerDragSourceRpc()

        Registers the server side RPC methods invoked from client side on dragstart and dragend events.

        Override this method if you have custom RPC interface for transmitting those events with more data. If just need to do additional things before firing the events, then you should override onDragStart() and onDragEnd(DropEffect) instead.

      • onDragStart

        protected void onDragStart()

        Method invoked when a dragstart has been sent from client side. Fires the DragStartEvent.

      • onDragEnd

        protected void onDragEnd​(DropEffect dropEffect)

        Method invoked when a dragend has been sent from client side. Fires the DragEndEvent.

        Parameters:

        dropEffect - the drop effect on the dragend

      • remove

        public void remove()

        Description copied from interface: Extension

        Remove this extension from its target. After an extension has been removed, it cannot be attached again.

        Specified by:

        remove in interface Extension

        Overrides:

        remove in class AbstractExtension

      • setEffectAllowed

        public void setEffectAllowed​(EffectAllowed effect)

        Sets the allowed effects for the current drag source element. Used for setting client side DataTransfer.effectAllowed parameter for the drag event.

        By default the value is EffectAllowed.UNINITIALIZED which is equivalent to EffectAllowed.ALL.

        Parameters:

        effect - Effects to allow for this draggable element. Cannot be null.

      • getEffectAllowed

        public EffectAllowed getEffectAllowed()

        Returns the allowed effects for the current drag source element. Used to set client side DataTransfer.effectAllowed parameter for the drag event.

        You can use different types of data to support dragging to different targets. Accepted types depend on the drop target and those can be platform specific. See https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types for examples on different types.

        NOTE: IE11 only supports type ' text', which can be set using setDataTransferText(String data)

        Returns:

        Effects that are allowed for this draggable element.

      • setDataTransferData

        public void setDataTransferData​(String type,
                                        String data)

        Sets data for this drag source element with the given type. The data is set for the client side draggable element using DataTransfer.setData(type, data) method.

        Note that "text" is the only cross browser supported data type. Use setDataTransferText(String) method instead if your application supports IE11.

        Parameters:

        type - Type of the data to be set for the client side draggable element, e.g. text/plain. Cannot be null.

        data - Data to be set for the client side draggable element. Cannot be null.

      • getDataTransferData

        public String getDataTransferData​(String type)

        Returns the data stored with type type in this drag source element.

        Parameters:

        type - Type of the requested data, e.g. text/plain.

        Returns:

        Data of type type stored in this drag source element.

      • getDataTransferData

        public Map<String,​String> getDataTransferData()

        Returns the map of data stored in this drag source element. The returned map preserves the order of storage and is unmodifiable.

        Returns:

        Unmodifiable copy of the map of data in the order the data was stored.

      • setDataTransferText

        public void setDataTransferText​(String data)

        Sets data of type "text" for this drag source element. The data is set for the client side draggable element using the DataTransfer.setData("text", data) method.

        Note that "text" is the only cross browser supported data type. Use this method if your application supports IE11.

        Parameters:

        data - Data to be set for the client side draggable element.

        See Also:

        setDataTransferData(String, String)

      • getDataTransferText

        public String getDataTransferText()

        Returns the data stored with type "text" in this drag source element.

        Returns:

        Data of type "text" stored in this drag source element.

      • clearDataTransferData

        public void clearDataTransferData​(String type)

        Clears data with the given type for this drag source element when present.

        Parameters:

        type - Type of data to be cleared. Cannot be null.

      • clearDataTransferData

        public void clearDataTransferData()

        Clears all data for this drag source element.

      • setPayload

        public void setPayload​(String key,
                               String value)

        Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format: "v-item:string:key:value". The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.

        Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.

        Parameters:

        key - key of the payload to be transferred

        value - value of the payload to be transferred

        See Also:

        DropTargetExtension.setDropCriterion(String, String)

      • setPayload

        public void setPayload​(String key,
                               int value)

        Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format: "v-item:integer:key:value". The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.

        Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.

        Parameters:

        key - key of the payload to be transferred

        value - value of the payload to be transferred

        See Also:

        DropTargetExtension#setDropCriterion(String, ComparisonOperator, int)

      • setPayload

        public void setPayload​(String key,
                               double value)

        Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format: "v-item:double:key:value". The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.

        Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.

        Parameters:

        key - key of the payload to be transferred

        value - value of the payload to be transferred

        See Also:

        DropTargetExtension#setDropCriterion(String, ComparisonOperator, double)

      • setDragData

        public void setDragData​(Object data)

        Set server side drag data. This data is available in the drop event and can be used to transfer data between drag source and drop target if they are in the same UI.

        Parameters:

        data - Data to transfer to drop event.

      • getDragData

        public Object getDragData()

        Get server side drag data. This data is available in the drop event and can be used to transfer data between drag source and drop target if they are in the same UI.

        Returns:

        Server side drag data if set, otherwise null.

      • addDragStartListener

        public Registration addDragStartListener​(DragStartListener<T> listener)

        Attaches dragstart listener for the current drag source. DragStartListener.dragStart(DragStartEvent) is called when dragstart event happens on the client side.

        Parameters:

        listener - Listener to handle dragstart event.

        Returns:

        Handle to be used to remove this listener.

      • addDragEndListener

        public Registration addDragEndListener​(DragEndListener<T> listener)

        Attaches dragend listener for the current drag source. DragEndListener.dragEnd(DragEndEvent) is called when dragend event happens on the client side.

        Parameters:

        listener - Listener to handle dragend event.

        Returns:

        Handle to be used to remove this listener.

      • setDragImage

        public void setDragImage​(Resource imageResource)

        Set a custom drag image for the current drag source.

        Parameters:

        imageResource - Resource of the image to be displayed as drag image.

      • getState

        protected DragSourceState getState()

        Description copied from class: AbstractClientConnector

        Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.

        As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use getState(false) to avoid marking the connector as dirty.

        Overrides:

        getState in class AbstractClientConnector

        Returns:

        The shared state for this connector. Never null.