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:
GridDragSource
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:
- Serialized Form
-
-
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)Extendstargetcomponent and makes it a drag source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddDragEndListener(DragEndListener<T> listener)Attaches dragend listener for the current drag source.RegistrationaddDragStartListener(DragStartListener<T> listener)Attaches dragstart listener for the current drag source.voidattach()Notifies the connector that it is connected to a VaadinSession (and therefore also to a UI).voidclearDataTransferData()Clears all data for this drag source element.voidclearDataTransferData(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.StringgetDataTransferData(String type)Returns the data stored with typetypein this drag source element.StringgetDataTransferText()Returns the data stored with type"text"in this drag source element.ObjectgetDragData()Get server side drag data.EffectAllowedgetEffectAllowed()Returns the allowed effects for the current drag source element.TgetParent()Returns the component this extension is attached to.protected DragSourceStategetState()Returns the shared state for this connector.protected DragSourceStategetState(boolean markAsDirty)Returns the shared state for this connector.protected voidonDragEnd(DropEffect dropEffect)Method invoked when adragendhas been sent from client side.protected voidonDragStart()Method invoked when adragstarthas been sent from client side.protected voidregisterDragSourceRpc()Registers the server side RPC methods invoked from client side ondragstartanddragendevents.voidremove()Remove this extension from its target.voidsetDataTransferData(String type, String data)Sets data for this drag source element with the given type.voidsetDataTransferText(String data)Sets data of type"text"for this drag source element.voidsetDragData(Object data)Set server side drag data.voidsetDragImage(Resource imageResource)Set a custom drag image for the current drag source.voidsetEffectAllowed(EffectAllowed effect)Sets the allowed effects for the current drag source element.voidsetPayload(String key, double value)Sets payload for this drag source to use with acceptance criterion.voidsetPayload(String key, int value)Sets payload for this drag source to use with acceptance criterion.voidsetPayload(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)
Extendstargetcomponent and makes it a drag source.- Parameters:
target- Component to be extended.
-
-
Method Detail
-
attach
public void attach()
Description copied from interface:ClientConnectorNotifies 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:
attachin interfaceClientConnector- Overrides:
attachin classAbstractClientConnector
-
registerDragSourceRpc
protected void registerDragSourceRpc()
Registers the server side RPC methods invoked from client side ondragstartanddragendevents.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 adragstarthas been sent from client side. Fires theDragStartEvent.
-
onDragEnd
protected void onDragEnd(DropEffect dropEffect)
Method invoked when adragendhas been sent from client side. Fires theDragEndEvent.- Parameters:
dropEffect- the drop effect on the dragend
-
remove
public void remove()
Description copied from interface:ExtensionRemove this extension from its target. After an extension has been removed, it cannot be attached again.- Specified by:
removein interfaceExtension- Overrides:
removein classAbstractExtension
-
setEffectAllowed
public void setEffectAllowed(EffectAllowed effect)
Sets the allowed effects for the current drag source element. Used for setting client sideDataTransfer.effectAllowedparameter for the drag event.By default the value is
EffectAllowed.UNINITIALIZEDwhich 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 sideDataTransfer.effectAllowedparameter 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 usingDataTransfer.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 typetypein this drag source element.- Parameters:
type- Type of the requested data, e.g.text/plain.- Returns:
- Data of type
typestored 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:
setDataTransferData(String, String)
-
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 transferred- See Also:
DropTargetExtension.setDropCriterion(String, String)
-
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 transferred- See 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 transferred- See 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:AbstractClientConnectorReturns 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:
getStatein classAbstractClientConnector- Returns:
- The shared state for this connector. Never null.
-
getState
protected DragSourceState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classAbstractClientConnector- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
getParent
public T getParent()
Returns the component this extension is attached to.- Specified by:
getParentin interfaceClientConnector- Specified by:
getParentin interfaceConnector- Overrides:
getParentin classAbstractExtension- Returns:
- Extended component.
-
-