T
- Type of the component to be extended.public class DragSourceExtension<T extends AbstractComponent> extends AbstractExtension
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Constructor and Description |
---|
DragSourceExtension(T target)
Extends
target component and makes it a drag source. |
Modifier and Type | Method and 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 and dragend 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.
|
extend, getSupportedParentType, setParent
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
public DragSourceExtension(T target)
target
component and makes it a drag source.target
- Component to be extended.public void attach()
ClientConnector
The caller of this method is Connector#setParent(ClientConnector)
if the parent is itself already attached to the session. If not, the
parent will call the ClientConnector.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
.
attach
in interface ClientConnector
attach
in class AbstractClientConnector
protected void registerDragSourceRpc()
dragstart
and dragend
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()
and
onDragEnd(DropEffect)
instead.
protected void onDragStart()
dragstart
has been sent from client
side. Fires the DragStartEvent
.protected void onDragEnd(DropEffect dropEffect)
dragend
has been sent from client
side. Fires the DragEndEvent
.dropEffect
- the drop effect on the dragendpublic void remove()
Extension
remove
in interface Extension
remove
in class AbstractExtension
public void setEffectAllowed(EffectAllowed effect)
DataTransfer.effectAllowed
parameter for the
drag event.
By default the value is EffectAllowed.UNINITIALIZED
which is
equivalent to EffectAllowed.ALL
.
effect
- Effects to allow for this draggable element. Cannot be null
.public EffectAllowed getEffectAllowed()
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)
public void setDataTransferData(String type, String data)
DataTransfer.setData(type, data)
method.
Note that "text"
is the only cross browser supported data type.
Use setDataTransferText(String)
method instead if your
application supports IE11.
type
- Type of the data to be set for the client side draggable
element, e.g. text/plain
. Cannot be null
.data
- Data to be set for the client side draggable element. Cannot
be null
.public String getDataTransferData(String type)
type
in this drag source
element.type
- Type of the requested data, e.g. text/plain
.type
stored in this drag source element.public Map<String,String> getDataTransferData()
public void setDataTransferText(String data)
"text"
for this drag source element. The data
is set for the client side draggable element using the DataTransfer.setData("text", data)
method.
Note that "text"
is the only cross browser supported data type.
Use this method if your application supports IE11.
data
- Data to be set for the client side draggable element.setDataTransferData(String, String)
public String getDataTransferText()
"text"
in this drag source
element."text"
stored in this drag source element.public void clearDataTransferData(String type)
type
- Type of data to be cleared. Cannot be null
.public void clearDataTransferData()
public void setPayload(String key, String value)
"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.
key
- key of the payload to be transferredvalue
- value of the payload to be transferredDropTargetExtension.setDropCriterion(String, String)
public void setPayload(String key, int value)
"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.
key
- key of the payload to be transferredvalue
- value of the payload to be transferredDropTargetExtension#setDropCriterion(String, ComparisonOperator,
int)
public void setPayload(String key, double value)
"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.
key
- key of the payload to be transferredvalue
- value of the payload to be transferredDropTargetExtension#setDropCriterion(String, ComparisonOperator,
double)
public void setDragData(Object data)
data
- Data to transfer to drop event.public Object getDragData()
public Registration addDragStartListener(DragStartListener<T> listener)
DragStartListener.dragStart(DragStartEvent)
is called when
dragstart event happens on the client side.listener
- Listener to handle dragstart event.public Registration addDragEndListener(DragEndListener<T> listener)
DragEndListener.dragEnd(DragEndEvent)
is called when dragend
event happens on the client side.listener
- Listener to handle dragend event.public void setDragImage(Resource imageResource)
imageResource
- Resource of the image to be displayed as drag image.protected DragSourceState getState()
AbstractClientConnector
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.
getState
in class AbstractClientConnector
protected DragSourceState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractClientConnector
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public T getParent()
getParent
in interface ClientConnector
getParent
in interface Connector
getParent
in class AbstractExtension
Copyright © 2018 Vaadin Ltd. All rights reserved.