com.vaadin.flow.component.dnd.
Interface DropTarget<T extends Component>
Type Parameters:
T
- the type of the drop target component
All Superinterfaces:
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 TypeMethodDescriptiondefault Registration
addDropListener
(ComponentEventListener<DropEvent<T>> listener) 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
isActive()
Gets whether this drop target is activate or not.
default void
setActive
(boolean active) Activate or deactivate this drop target.
default void
setDropEffect
(DropEffect dropEffect) Sets the drop effect for the current drop target.
-
Method Details
-
create
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)
orsetActive(boolean)
.Type Parameters:
T
- the type of the componentParameters:
component
- the component to make a drop targetReturns:
drop target API for the component
See Also:
-
configure
Gives access to the generic drop target 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 a drop targetReturns:
drop target API for the component
See Also:
-
configure
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)
andsetActive(boolean)
.The drop target active state can be changed at any time with
setActive(boolean)
.Type Parameters:
T
- the type of the componentParameters:
component
- the component to provide drop target API foractive
-true
to set the component as an active drop target,false
for notReturns:
the drop target API for the component
See Also:
-
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
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 interfaceHasElement
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
Sets the drop effect for the current drop target. This is set to the dropEffect on
dragenter
,dragover
anddrop
events and needs to match theeffectAllowed
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.
- MDN web docs for more information.
Parameters:
dropEffect
- the drop effect to be set ornull
to not modifySee Also:
-
getDropEffect
Returns the drop effect for the current drop target.
Returns:
The drop effect of this drop target or
null
if none setSee Also:
-
addDropListener
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 (seeDragSource.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.
-