Class DropEvent<T extends com.vaadin.flow.component.Component>

java.lang.Object
java.util.EventObject
com.vaadin.flow.component.ComponentEvent<T>
com.vaadin.flow.component.dnd.AbstractDnDEvent<T>
com.vaadin.flow.component.dnd.DropEvent<T>
Type Parameters:
T - Type of the drop target component.
All Implemented Interfaces:
Serializable

@DomEvent("drop") public class DropEvent<T extends com.vaadin.flow.component.Component> extends AbstractDnDEvent<T>
Server side drop event. Fired when an HTML5 drop happens on a valid drop target.
Since:
2.0
Author:
Vaadin Ltd
See Also:
  • Field Summary

    Fields inherited from class java.util.EventObject

    source
  • Constructor Summary

    Constructors
    Constructor
    Description
    DropEvent(T source, boolean fromClient, String effectAllowed)
    Deprecated, for removal: This API element is subject to removal in a future version.
    since 25.2, for removal.
    DropEvent(T source, boolean fromClient, String effectAllowed, int clientX, int clientY, int offsetX, int offsetY)
    Creates a server side drop event.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the server side drag data.
    Optional<com.vaadin.flow.component.Component>
    Returns the drag source component if the drag originated from a component in the same UI as the drop target component, or an empty optional.
    int
    Gets the x coordinate of the mouse pointer relative to the drag source element when the drag started.
    int
    Gets the y coordinate of the mouse pointer relative to the drag source element when the drag started.
    Get the desired dropEffect for the drop event.
    Get the effectAllowed set by the drag source.
    int
    Gets the x coordinate of the drop position relative to the drop target element.
    int
    Gets the y coordinate of the drop position relative to the drop target element.

    Methods inherited from class com.vaadin.flow.component.dnd.AbstractDnDEvent

    getClientX, getClientY, getComponent

    Methods inherited from class com.vaadin.flow.component.ComponentEvent

    getSource, getUI, isFromClient, unregisterListener

    Methods inherited from class java.util.EventObject

    toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DropEvent

      @Deprecated(since="25.2", forRemoval=true) public DropEvent(T source, boolean fromClient, String effectAllowed)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 25.2, for removal. Use DropEvent(Component, boolean, String, int, int, int, int) which also captures the pointer's client and drop-target offset coordinates. When this constructor is used, AbstractDnDEvent.getClientX(), AbstractDnDEvent.getClientY(), getOffsetX() and getOffsetY() return 0.
      Creates a server side drop event.
      Parameters:
      source - Component that received the drop.
      fromClient - true if the event originated from the client side, false otherwise
      effectAllowed - the effect allowed by the drag source
    • DropEvent

      public DropEvent(T source, boolean fromClient, @EventData("event.dataTransfer.effectAllowed") String effectAllowed, @EventData("event.clientX") int clientX, @EventData("event.clientY") int clientY, @EventData("event.clientX - event.currentTarget.getBoundingClientRect().left") int offsetX, @EventData("event.clientY - event.currentTarget.getBoundingClientRect().top") int offsetY)
      Creates a server side drop event.
      Parameters:
      source - Component that received the drop.
      fromClient - true if the event originated from the client side, false otherwise
      effectAllowed - the effect allowed by the drag source
      clientX - the x coordinate of the mouse pointer relative to the viewport
      clientY - the y coordinate of the mouse pointer relative to the viewport
      offsetX - the x coordinate of the mouse pointer relative to the drop target element
      offsetY - the y coordinate of the mouse pointer relative to the drop target element
  • Method Details

    • getDragData

      public Optional<Object> getDragData()
      Gets the server side drag data. This data can be set during the drag start event on the server side and can be used to transfer data between drag source and drop target when they are in the same UI.
      Returns:
      Optional server side drag data if set and the drag source and the drop target are in the same UI, otherwise empty Optional.
    • getDropEffect

      public DropEffect getDropEffect()
      Get the desired dropEffect for the drop event.
      Returns:
      the drop effect set to the drop target, or null if nothing set
      See Also:
    • getEffectAllowed

      public EffectAllowed getEffectAllowed()
      Get the effectAllowed set by the drag source.
      Returns:
      the effect allowed by the drag source
      See Also:
    • getDragSourceComponent

      public Optional<com.vaadin.flow.component.Component> getDragSourceComponent()
      Returns the drag source component if the drag originated from a component in the same UI as the drop target component, or an empty optional.
      Returns:
      Drag source component from the same UI or an empty optional.
    • getOffsetX

      public int getOffsetX()
      Gets the x coordinate of the drop position relative to the drop target element.

      This is useful for positioning dropped items within the drop target container using absolute or relative positioning.

      Returns:
      the x coordinate relative to the drop target element
    • getOffsetY

      public int getOffsetY()
      Gets the y coordinate of the drop position relative to the drop target element.

      This is useful for positioning dropped items within the drop target container using absolute or relative positioning.

      Returns:
      the y coordinate relative to the drop target element
    • getDragStartOffsetX

      public int getDragStartOffsetX()
      Gets the x coordinate of the mouse pointer relative to the drag source element when the drag started.

      This is useful for maintaining the relative grab position when positioning dropped items. For example, if you want items to appear where they were grabbed (not where the cursor is), subtract this value from getOffsetX().

      Returns:
      the drag start x offset if the drag source is in the same UI, otherwise 0
    • getDragStartOffsetY

      public int getDragStartOffsetY()
      Gets the y coordinate of the mouse pointer relative to the drag source element when the drag started.

      This is useful for maintaining the relative grab position when positioning dropped items. For example, if you want items to appear where they were grabbed (not where the cursor is), subtract this value from getOffsetY().

      Returns:
      the drag start y offset if the drag source is in the same UI, otherwise 0