com.vaadin.ui.dnd.
Class DragSourceExtension<T extends AbstractComponent>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.dnd.DragSourceExtension<T>
-
Type Parameters:
T
- Type of the component to be extended.All Implemented Interfaces:
MethodEventSource
,ClientConnector
,Extension
,Connector
,Serializable
Direct Known Subclasses:
public class DragSourceExtension<T extends AbstractComponent> extends AbstractExtension
Extension to make a component drag source for HTML5 drag and drop functionality.
Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
-
Constructor Summary
Constructors Constructor Description DragSourceExtension(T target)
Extends
target
component and makes it a drag source.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addDragEndListener(DragEndListener<T> listener)
Attaches dragend listener for the current drag source.
Registration
addDragStartListener(DragStartListener<T> listener)
Attaches dragstart listener for the current drag source.
void
attach()
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
void
clearDataTransferData()
Clears all data for this drag source element.
void
clearDataTransferData(String type)
Clears data with the given type for this drag source element when present.
Map<String,String>
getDataTransferData()
Returns the map of data stored in this drag source element.
String
getDataTransferData(String type)
Returns the data stored with type
type
in this drag source element.String
getDataTransferText()
Returns the data stored with type
"text"
in this drag source element.Object
getDragData()
Get server side drag data.
EffectAllowed
getEffectAllowed()
Returns the allowed effects for the current drag source element.
T
getParent()
Returns the component this extension is attached to.
protected DragSourceState
getState()
Returns the shared state for this connector.
protected DragSourceState
getState(boolean markAsDirty)
Returns the shared state for this connector.
protected void
onDragEnd(DropEffect dropEffect)
Method invoked when a
dragend
has been sent from client side.protected void
onDragStart()
Method invoked when a
dragstart
has been sent from client side.protected void
registerDragSourceRpc()
Registers the server side RPC methods invoked from client side on
dragstart
anddragend
events.void
remove()
Remove this extension from its target.
void
setDataTransferData(String type, String data)
Sets data for this drag source element with the given type.
void
setDataTransferText(String data)
Sets data of type
"text"
for this drag source element.void
setDragData(Object data)
Set server side drag data.
void
setDragImage(Resource imageResource)
Set a custom drag image for the current drag source.
void
setEffectAllowed(EffectAllowed effect)
Sets the allowed effects for the current drag source element.
void
setPayload(String key, double value)
Sets payload for this drag source to use with acceptance criterion.
void
setPayload(String key, int value)
Sets payload for this drag source to use with acceptance criterion.
void
setPayload(String key, String value)
Sets payload for this drag source to use with acceptance criterion.
-
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getSupportedParentType, setParent
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
-
-
-
Constructor Detail
-
DragSourceExtension
public DragSourceExtension(T target)
Extends
target
component and makes it a drag source.Parameters:
target
- Component to be extended.
-
-
Method Detail
-
attach
public void attach()
Description copied from interface:
ClientConnector
Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).
The caller of this method is
Component.setParent(HasComponents)
if the parent is itself already attached to the session. If not, the parent will call theClientConnector.attach()
for all its children when it is attached to the session. This method is always called before the connector's data is sent to the client-side for the first time.The attachment logic is implemented in
AbstractClientConnector
.Specified by:
attach
in interfaceClientConnector
Overrides:
attach
in classAbstractClientConnector
-
registerDragSourceRpc
protected void registerDragSourceRpc()
Registers the server side RPC methods invoked from client side on
dragstart
anddragend
events.Override this method if you have custom RPC interface for transmitting those events with more data. If just need to do additional things before firing the events, then you should override
onDragStart()
andonDragEnd(DropEffect)
instead.
-
onDragStart
protected void onDragStart()
Method invoked when a
dragstart
has been sent from client side. Fires theDragStartEvent
.
-
onDragEnd
protected void onDragEnd(DropEffect dropEffect)
Method invoked when a
dragend
has been sent from client side. Fires theDragEndEvent
.Parameters:
dropEffect
- the drop effect on the dragend
-
remove
public void remove()
Description copied from interface:
Extension
Remove this extension from its target. After an extension has been removed, it cannot be attached again.
Specified by:
Overrides:
remove
in classAbstractExtension
-
setEffectAllowed
public void setEffectAllowed(EffectAllowed effect)
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
.Parameters:
effect
- Effects to allow for this draggable element. Cannot benull
.
-
getEffectAllowed
public EffectAllowed getEffectAllowed()
Returns the allowed effects for the current drag source element. Used to set client side
DataTransfer.effectAllowed
parameter for the drag event.You can use different types of data to support dragging to different targets. Accepted types depend on the drop target and those can be platform specific. See https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types for examples on different types.
NOTE: IE11 only supports type ' text', which can be set using
setDataTransferText(String data)
Returns:
Effects that are allowed for this draggable element.
-
setDataTransferData
public void setDataTransferData(String type, String data)
Sets data for this drag source element with the given type. The data is set for the client side draggable element using
DataTransfer.setData(type, data)
method.Note that
"text"
is the only cross browser supported data type. UsesetDataTransferText(String)
method instead if your application supports IE11.Parameters:
type
- Type of the data to be set for the client side draggable element, e.g.text/plain
. Cannot benull
.data
- Data to be set for the client side draggable element. Cannot benull
.
-
getDataTransferData
public String getDataTransferData(String type)
Returns the data stored with type
type
in this drag source element.Parameters:
type
- Type of the requested data, e.g.text/plain
.Returns:
Data of type
type
stored in this drag source element.
-
getDataTransferData
public Map<String,String> getDataTransferData()
Returns the map of data stored in this drag source element. The returned map preserves the order of storage and is unmodifiable.
Returns:
Unmodifiable copy of the map of data in the order the data was stored.
-
setDataTransferText
public void setDataTransferText(String data)
Sets data of type
"text"
for this drag source element. The data is set for the client side draggable element using theDataTransfer.setData("text", data)
method.Note that
"text"
is the only cross browser supported data type. Use this method if your application supports IE11.Parameters:
data
- Data to be set for the client side draggable element.See Also:
-
getDataTransferText
public String getDataTransferText()
Returns the data stored with type
"text"
in this drag source element.Returns:
Data of type
"text"
stored in this drag source element.
-
clearDataTransferData
public void clearDataTransferData(String type)
Clears data with the given type for this drag source element when present.
Parameters:
type
- Type of data to be cleared. Cannot benull
.
-
clearDataTransferData
public void clearDataTransferData()
Clears all data for this drag source element.
-
setPayload
public void setPayload(String key, String value)
Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format:
"v-item:string:key:value"
. The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.
Parameters:
key
- key of the payload to be transferredvalue
- value of the payload to be transferredSee Also:
-
setPayload
public void setPayload(String key, int value)
Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format:
"v-item:integer:key:value"
. The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.
Parameters:
key
- key of the payload to be transferredvalue
- value of the payload to be transferredSee Also:
DropTargetExtension#setDropCriterion(String, ComparisonOperator, int)
-
setPayload
public void setPayload(String key, double value)
Sets payload for this drag source to use with acceptance criterion. The payload is transferred as data type in the data transfer object in the following format:
"v-item:double:key:value"
. The given value is compared to the criterion value when the drag source is dragged on top of a drop target that has the suitable criterion.Note that setting payload in Internet Explorer 11 is not possible due to the browser's limitations.
Parameters:
key
- key of the payload to be transferredvalue
- value of the payload to be transferredSee Also:
DropTargetExtension#setDropCriterion(String, ComparisonOperator, double)
-
setDragData
public 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 and drop target if they are in the same UI.
Parameters:
data
- Data to transfer to drop event.
-
getDragData
public 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.
-
addDragStartListener
public Registration addDragStartListener(DragStartListener<T> listener)
Attaches dragstart listener for the current drag source.
DragStartListener.dragStart(DragStartEvent)
is called 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
public Registration addDragEndListener(DragEndListener<T> listener)
Attaches dragend listener for the current drag source.
DragEndListener.dragEnd(DragEndEvent)
is called when dragend event happens on the client side.Parameters:
listener
- Listener to handle dragend event.Returns:
Handle to be used to remove this listener.
-
setDragImage
public void setDragImage(Resource imageResource)
Set a custom drag image for the current drag source.
Parameters:
imageResource
- Resource of the image to be displayed as drag image.
-
getState
protected DragSourceState getState()
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.
As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use
getState(false)
to avoid marking the connector as dirty.Overrides:
getState
in classAbstractClientConnector
Returns:
The shared state for this connector. Never null.
-
getState
protected DragSourceState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractClientConnector
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
getParent
public T getParent()
Returns the component this extension is attached to.
Specified by:
getParent
in interfaceClientConnector
Specified by:
getParent
in interfaceConnector
Overrides:
getParent
in classAbstractExtension
Returns:
Extended component.
-
-