Interface DragSource<T extends Component>
-
- Type Parameters:
T
- the type of the drag source component
- All Superinterfaces:
HasElement
,Serializable
@JsModule("./dndConnector-es6.js") public interface DragSource<T extends Component> extends HasElement
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)
orconfigure(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.
- Since:
- 2.0
- Author:
- Vaadin Ltd
- See Also:
DropTarget
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method 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>
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
getDragData()
Get server side drag data.default Element
getDraggableElement()
Returns the element where thedraggable
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.
-
-
-
Method Detail
-
create
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.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 component- Parameters:
component
- the component to make draggable- Returns:
- drag source API mapping to the component
- See Also:
configure(Component)
,configure(Component, boolean)
-
configure
static <T extends Component> DragSource<T> configure(T component)
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 component- Parameters:
component
- the component to make draggable- Returns:
- drag source API mapping to the component
- See Also:
create(Component)
,configure(Component, boolean)
-
configure
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.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 component- Parameters:
component
- the component to make draggabledraggable
-true
to make draggable,false
to not- Returns:
- drag source API mapping to the component
- See Also:
create(Component)
,configure(Component, boolean)
-
getDragSourceComponent
default T 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
default Element 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
default Element getDraggableElement()
Returns the element where thedraggable
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
default void setDragData(Object data)
Set server side drag data. This data is available in the drop event and can be used to transfer data between drag source andDropTarget
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:
DropEvent.getDragData()
,DragStartEvent.setDragData(Object)
,DragEndEvent.clearDragData()
-
getDragData
default Object 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
default void setEffectAllowed(EffectAllowed effect)
Sets the allowed effects for the current drag source element. Used for setting client sideDataTransfer.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.
- Parameters:
effect
- Effects to allow for this draggable element. Cannot benull
.- See Also:
- MDN web docs for more information.
-
getEffectAllowed
default EffectAllowed getEffectAllowed()
Returns the allowed effects for the current drag source element. Used to set client sideDataTransfer.effectAllowed
parameter for the drag event.- Returns:
- effects that are allowed for this draggable element.
-
addDragStartListener
default Registration addDragStartListener(ComponentEventListener<DragStartEvent<T>> listener)
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
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.- Parameters:
listener
- Listener to handle dragend event.- Returns:
- Handle to be used to remove this listener.
-
-