Interface DragSource<T extends Component>

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

@JsModule("./dndConnector.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).

Since:
2.0
Author:
Vaadin Ltd
See Also:
  • Method Details

    • create

      static <T extends Component> DragSource<T> create(T component)
      Makes the given component draggable and gives access to the generic drag source API for the component.

      The given component will be always set as draggable, if this is not desired, use either method configure(Component, boolean) or setDraggable(boolean).

      Type Parameters:
      T - the type of the component
      Parameters:
      component - the component to make draggable
      Returns:
      drag source API mapping to the component
      See Also:
    • configure

      static <T extends Component> DragSource<T> configure(T component)
      Gives access to the generic drag source API for the given component.

      Unlike create(Component) and configure(Component, boolean), this method does not change the active drop target status of the given component.

      Type Parameters:
      T - the type of the component
      Parameters:
      component - the component to make draggable
      Returns:
      drag source API mapping to the component
      See Also:
    • configure

      static <T extends Component> DragSource<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:
    • 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
    • setDragData

      default 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 DropTarget if they are in the same UI.

      The drag data can be set also in the drag start event listener added with addDragStartListener(ComponentEventListener) using DragStartEvent.setDragData(Object).

      Parameters:
      data - Data to transfer to drop event.
      See Also:
    • 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:
    • 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.