Interface DropTarget<T extends Component>

Type Parameters:
T - the type of the drop target component
All Superinterfaces:
HasElement, Serializable

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

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

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

    Modifier and Type
    Method
    Description
    default Registration
    Attaches drop listener for the component this maps to.
    static <T extends Component>
    DropTarget<T>
    configure(T component)
    Gives access to the generic drop target API for the given component.
    static <T extends Component>
    DropTarget<T>
    configure(T component, boolean active)
    Gives access to the generic drop target API for the given component and either activates or deactivates the drop target.
    static <T extends Component>
    DropTarget<T>
    create(T component)
    Makes the given component a drop target and gives access to the generic drop target API for the component.
    default DropEffect
    Returns the drop effect for the current drop target.
    default T
    Returns the drop target component.
    default Element
    Returns the element which is made as a drop target in the UI.
    default boolean
    Gets whether this drop target is activate or not.
    default void
    setActive(boolean active)
    Activate or deactivate this drop target.
    default void
    Sets the drop effect for the current drop target.
  • Method Details

    • create

      static <T extends Component> DropTarget<T> create(T component)
      Makes the given component a drop target and gives access to the generic drop target API for the component.

      The given component will be always set an active drop target, if this is not desired, use either method configure(Component, boolean) or setActive(boolean).

      Type Parameters:
      T - the type of the component
      Parameters:
      component - the component to make a drop target
      Returns:
      drop target API for the component
      See Also:
    • configure

      static <T extends Component> DropTarget<T> configure(T component)
      Gives access to the generic drop target 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 a drop target
      Returns:
      drop target API for the component
      See Also:
    • configure

      static <T extends Component> DropTarget<T> configure(T component, boolean active)
      Gives access to the generic drop target API for the given component and either activates or deactivates the drop target.

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

      The drop target active state can be changed at any time with setActive(boolean).

      Type Parameters:
      T - the type of the component
      Parameters:
      component - the component to provide drop target API for
      active - true to set the component as an active drop target, false for not
      Returns:
      the drop target API for the component
      See Also:
    • getDropTargetComponent

      default T getDropTargetComponent()
      Returns the drop target component. This component is used in the drop event as the source, and its element is made as a drop target by default.

      The default implementation of this method returns this. This method exists for type safe access for the drop target component and being able to provide access to drop target API for any component.

      Returns:
      the drop target component
    • getElement

      default Element getElement()
      Returns the element which is made as a drop target in the UI. By default it is the element of the component returned by getDropTargetComponent().
      Specified by:
      getElement in interface HasElement
      Returns:
      the element that is a drop target
    • setActive

      default void setActive(boolean active)
      Activate or deactivate this drop target. By default, it is not active.
      Parameters:
      active - true to allow drops, false to not
    • isActive

      default boolean isActive()
      Gets whether this drop target is activate or not. By default, it is not.
      Returns:
      true to allow drops, false to not
    • setDropEffect

      default void setDropEffect(DropEffect dropEffect)
      Sets the drop effect for the current drop target. This is set to the dropEffect on dragenter, dragover and drop events and needs to match the effectAllowed property for the drag operation.

      NOTE: If the drop effect that doesn't match the effectAllowed of the drag source, it DOES NOT prevent drop on IE11 and Safari! For FireFox and Chrome the drop is prevented if the properties don't match.

      Parameters:
      dropEffect - the drop effect to be set or null to not modify
      See Also:
    • getDropEffect

      default DropEffect getDropEffect()
      Returns the drop effect for the current drop target.
      Returns:
      The drop effect of this drop target or null if none set
      See Also:
    • addDropListener

      default Registration addDropListener(ComponentEventListener<DropEvent<T>> listener)
      Attaches drop listener for the component this maps to. The listener is triggered when the user performs a drop operation on the client side, and the criteria set with setDropEffect(DropEffect) matches a one set for the drag operation (see DragSource.setEffectAllowed(EffectAllowed)).

      NOTE: the drop listener might be triggered for a drop inside another drop target that is inside this drop target component! For this, the setActive(boolean) does not have effect.

      Parameters:
      listener - Listener to handle drop event.
      Returns:
      Handle to be used to remove this listener.