T
- the type of the drag source component@JavaScript(value="frontend://dndConnector.js") @JsModule(value="./dndConnector-es6.js") public interface DragSource<T extends Component> extends HasElement
This can be used by either implementing this interface, or with the static
API create(Component)
, configure(Component)
or
configure(Component, boolean)
.
NOTE: Starting a drag from a component that has contents inside shadow dom does not work in Firefox due to https://bugzilla.mozilla .org/show_bug.cgi?id=1521471. Thus currently Vaadin components like TextField, DatePicker and ComboBox cannot be dragged by the user in Firefox.
DropTarget
Modifier and Type | Method and Description |
---|---|
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.
|
default Registration |
addDragStartListener(ComponentEventListener<DragStartEvent<T>> listener)
Attaches dragstart listener for the current drag source.
|
static <T extends Component> |
configure(T component)
Gives access to the generic drag source API for the given component.
|
static <T extends Component> |
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> |
create(T component)
Makes the given component draggable and gives access to the generic drag
source API for the component.
|
default Object |
getDragData()
Get server side drag data.
|
default Element |
getDraggableElement()
Returns the element where the
draggable attribute is applied,
making it draggable by the user. |
default T |
getDragSourceComponent()
Returns the drag source component.
|
default EffectAllowed |
getEffectAllowed()
Returns the allowed effects for the current drag source element.
|
default Element |
getElement()
Gets the element associated with this instance.
|
default boolean |
isDraggable()
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 |
setEffectAllowed(EffectAllowed effect)
Sets the allowed effects for the current drag source element.
|
static <T extends Component> DragSource<T> create(T component)
The given component will be always set as draggable, if this is not
desired, use either method configure(Component, boolean)
or
setDraggable(boolean)
.
T
- the type of the componentcomponent
- the component to make draggableconfigure(Component)
,
configure(Component, boolean)
static <T extends Component> DragSource<T> configure(T component)
Unlike create(Component)
and
configure(Component, boolean)
, this method does not change the
active drop target status of the given component.
T
- the type of the componentcomponent
- the component to make draggablecreate(Component)
,
configure(Component, boolean)
static <T extends Component> DragSource<T> configure(T component, boolean draggable)
This method is a shorthand for calling configure(Component)
and
setDraggable(boolean)
.
The component draggable state can be changed later on with
setDraggable(boolean)
.
T
- the type of the componentcomponent
- the component to make draggabledraggable
- true
to make draggable, false
to notcreate(Component)
,
configure(Component, boolean)
default T getDragSourceComponent()
The default implementation of this method returns this
. This
method exists for type safe access for the drag source component.
default Element getElement()
HasElement
getElement
in interface HasElement
default Element getDraggableElement()
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.
default void setDraggable(boolean draggable)
draggable
- true
for enable dragging, false
to preventdefault boolean isDraggable()
true
draggable, false
if notdefault void setDragData(Object data)
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)
.
data
- Data to transfer to drop event.DropEvent.getDragData()
,
DragStartEvent.setDragData(Object)
,
DragEndEvent.clearDragData()
default Object getDragData()
default void setEffectAllowed(EffectAllowed effect)
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.
effect
- Effects to allow for this draggable element. Cannot be null
.default EffectAllowed getEffectAllowed()
DataTransfer.effectAllowed
parameter for the drag
event.default Registration addDragStartListener(ComponentEventListener<DragStartEvent<T>> listener)
listener
- Listener to handle dragstart event.default Registration addDragEndListener(ComponentEventListener<DragEndEvent<T>> listener)
listener
- Listener to handle dragend event.Copyright © 2020. All rights reserved.