Interface DragSource<T extends Component>

  • Type Parameters:
    T - the type of the drag source component
    All Superinterfaces:
    HasElement, Serializable

    @JsModule("./dndConnector-es6.js")
    public interface DragSource<T extends Component>
    extends HasElement
    Mixin interface that provides basic drag source API for any component.

    This can be used by either implementing this interface, or with the static API create(Component), configure(Component) or configure(Component, boolean).

    NOTE: Starting a drag from a component that has contents inside shadow dom does not work in Firefox due to https://bugzilla.mozilla .org/show_bug.cgi?id=1521471. Thus currently Vaadin components like TextField, DatePicker and ComboBox cannot be dragged by the user in Firefox.

    Since:
    2.0
    Author:
    Vaadin Ltd
    See Also:
    DropTarget
    • Method Detail

      • configure

        static <T extends ComponentDragSource<T> configure​(T component,
                                                             boolean draggable)
        Gives access to the generic drag source API for the given component and applies the given draggable status to it.

        This method is a shorthand for calling configure(Component) and setDraggable(boolean).

        The component draggable state can be changed later on with setDraggable(boolean).

        Type Parameters:
        T - the type of the component
        Parameters:
        component - the component to make draggable
        draggable - true to make draggable, false to not
        Returns:
        drag source API mapping to the component
        See Also:
        create(Component), configure(Component, boolean)
      • getDragSourceComponent

        default T getDragSourceComponent()
        Returns the drag source component. This component is used in the drag start and end events, and set as active drag source for the UI when dragged.

        The default implementation of this method returns this. This method exists for type safe access for the drag source component.

        Returns:
        the drag source component
      • getElement

        default Element getElement()
        Description copied from interface: HasElement
        Gets the element associated with this instance.
        Specified by:
        getElement in interface HasElement
        Returns:
        the element associated with this instance
      • getDraggableElement

        default Element getDraggableElement()
        Returns the element where the draggable attribute is applied, making it draggable by the user. By default it is the element of the component returned by getDragSourceComponent().

        Override this method to provide another element to be draggable instead of the root element of the component.

        Returns:
        the element made draggable
        Since:
        2.1
      • setDraggable

        default void setDraggable​(boolean draggable)
        Sets this component as draggable. By default it is not.
        Parameters:
        draggable - true for enable dragging, false to prevent
      • isDraggable

        default boolean isDraggable()
        Is this component currently draggable. By default it is not.
        Returns:
        true draggable, false if not
      • getDragData

        default 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.
      • setEffectAllowed

        default 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.

        NOTE: The effect should be set in advance, setting it after the user has started dragging and the DragStartEvent has been fired is too late - it will take effect only for next drag operation.

        NOTE 2: Edge, Safari and IE11 will allow the drop to occur even when the effect allowed does not match the drop effect set on the drop target. Chrome and Firefox prevent the drop if those do not match.

        Parameters:
        effect - Effects to allow for this draggable element. Cannot be null.
        See Also:
        MDN web docs for more information.
      • getEffectAllowed

        default EffectAllowed getEffectAllowed()
        Returns the allowed effects for the current drag source element. Used to set client side DataTransfer.effectAllowed parameter for the drag event.
        Returns:
        effects that are allowed for this draggable element.
      • addDragStartListener

        default Registration addDragStartListener​(ComponentEventListener<DragStartEvent<T>> listener)
        Attaches dragstart listener for the current drag source. The listener is triggered 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

        default Registration addDragEndListener​(ComponentEventListener<DragEndEvent<T>> listener)
        Attaches dragend listener for the current drag source.The listener is triggered when dragend event happens on the client side.
        Parameters:
        listener - Listener to handle dragend event.
        Returns:
        Handle to be used to remove this listener.