com.vaadin.flow.component.dnd.
Interface DragSource<T extends Component>
Type Parameters:
T
- the type of the drag source component
All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptiondefault 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.
default Registration
addDragStartListener
(ComponentEventListener<DragStartEvent<T>> listener) Attaches dragstart listener for the current drag source.
static <T extends Component>
DragSource<T>configure
(T component) Gives access to the generic drag source API for the given component.
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.
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.
default Object
Get server side drag data.
default Element
Returns the element where the
draggable
attribute is applied, making it draggable by the user.default Component
Get server side drag image.
default T
Returns the drag source component.
default EffectAllowed
Returns the allowed effects for the current drag source element.
default Element
Gets the element associated with this instance.
default boolean
Is this component currently draggable.
default void
setDragData
(Object data) Set server side drag data.
default void
setDraggable
(boolean draggable) Sets this component as draggable.
default void
setDragImage
(Component dragImage) Sets the drag image for the current drag source element.
default void
setDragImage
(Component dragImage, int offsetX, int offsetY) Sets the drag image for the current drag source element.
default void
setEffectAllowed
(EffectAllowed effect) Sets the allowed effects for the current drag source element.
-
Method Details
-
create
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)
orsetDraggable(boolean)
.Type Parameters:
T
- the type of the componentParameters:
component
- the component to make draggableReturns:
drag source API mapping to the component
See Also:
-
configure
Gives access to the generic drag source API for the given component.
Unlike
create(Component)
andconfigure(Component, boolean)
, this method does not change the active drop target status of the given component.Type Parameters:
T
- the type of the componentParameters:
component
- the component to make draggableReturns:
drag source API mapping to the component
See Also:
-
configure
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)
andsetDraggable(boolean)
.The component draggable state can be changed later on with
setDraggable(boolean)
.Type Parameters:
T
- the type of the componentParameters:
component
- the component to make draggabledraggable
-true
to make draggable,false
to notReturns:
drag source API mapping to the component
See Also:
-
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
Description copied from interface:
HasElement
Gets the element associated with this instance.
Specified by:
getElement
in interfaceHasElement
Returns:
the element associated with this instance
-
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 bygetDragSourceComponent()
.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
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)
usingDragStartEvent.setDragData(Object)
.Parameters:
data
- Data to transfer to drop event.See Also:
-
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
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 toEffectAllowed.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.
- MDN web docs for more information.
Parameters:
effect
- Effects to allow for this draggable element. Cannot benull
.See Also:
-
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.
-
setDragImage
Sets the drag image for the current drag source element. The image is applied automatically in the next drag start event in the browser. Drag image is shown by default with zero offset which means that pointer location is in the top left corner of the image.
com.vaadin.flow.component.html.Image
is fully supported as a drag image component. Other components can be used as well, but the support may vary between browsers. If given component is visible element in the viewport, browser can show it as a drag image.- MDN web docs for more information.
Parameters:
dragImage
- the image to be used as drag image or null to remove itSee Also:
-
setDragImage
Sets the drag image for the current drag source element. The image is applied automatically in the next drag start event in the browser. Coordinates define the offset of the pointer location from the top left corner of the image.
com.vaadin.flow.component.html.Image
is fully supported as a drag image component. Other components can be used as well, but the support may vary between browsers. If given component is visible element in the viewport, browser can show it as a drag image.- MDN web docs for more information.
Parameters:
dragImage
- the image to be used as drag image or null to remove itoffsetX
- the x-offset of the drag imageoffsetY
- the y-offset of the drag imageSee Also:
-
getDragImage
Get server side drag image. This image is applied automatically in the next drag start event in the browser.
Returns:
Server side drag image if set, otherwise null.
-
addDragStartListener
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
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.
-