T - Type of the component to be extended.public class DropTargetExtension<T extends AbstractComponent> extends AbstractExtension
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener| Constructor and Description |
|---|
DropTargetExtension(T target)
Extends
target component and makes it a drop target. |
| Modifier and Type | Method and Description |
|---|---|
Registration |
addDropListener(DropListener<T> listener)
Attaches drop listener for the current drop target.
|
void |
attach()
Notifies the connector that it is connected to a VaadinSession (and
therefore also to a UI).
|
String |
getDropCriteriaScript()
Gets the criteria script that determines whether a drop is allowed.
|
DropEffect |
getDropEffect()
Returns the drop effect for the current drop target.
|
T |
getParent()
Returns the component this extension is attached to.
|
protected DropTargetState |
getState()
Returns the shared state for this connector.
|
protected DropTargetState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
protected void |
onDrop(List<String> types,
Map<String,String> data,
DropEffect dropEffect,
MouseEventDetails mouseEventDetails)
Invoked when a
drop has been received from client side. |
protected void |
registerDropTargetRpc()
Registers the server side RPC methods invoked from client side on
drop event. |
void |
setDropCriteria(Criterion.Match match,
Criterion... criteria)
Sets multiple drop criteria to allow drop on this drop target.
|
void |
setDropCriteriaScript(String criteriaScript)
Sets a criteria script in JavaScript to allow drop on this drop target.
|
void |
setDropCriterion(String key,
ComparisonOperator operator,
double value)
Set a drop criterion to allow drop on this drop target.
|
void |
setDropCriterion(String key,
ComparisonOperator operator,
int value)
Set a drop criterion to allow drop on this drop target.
|
void |
setDropCriterion(String key,
String value)
Set a drop criterion to allow drop on this drop target.
|
void |
setDropEffect(DropEffect dropEffect)
Sets the drop effect for the current drop target.
|
extend, getSupportedParentType, remove, setParentaddAttachListener, 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, updateDiffstateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitaddAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetConnectorIdpublic DropTargetExtension(T target)
target component and makes it a drop target.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 ClientConnectorattach in class AbstractClientConnectorprotected void registerDropTargetRpc()
drop event.
Override this method if you need to have a custom RPC interface for
transmitting the drop event with more data. If just need to do additional
things before firing the drop event, then you should override
onDrop(List, Map, DropEffect, MouseEventDetails) instead.
protected void onDrop(List<String> types, Map<String,String> data, DropEffect dropEffect, MouseEventDetails mouseEventDetails)
drop has been received from client side.
Fires the DropEvent.types - List of data types from DataTransfer.types object.data - Map containing all types and corresponding data from the
DataTransfer object.dropEffect - the drop effectmouseEventDetails - mouse event details object containing information about the
drop eventpublic void setDropEffect(DropEffect dropEffect)
dragenter and dragover events.
NOTE: If the drop effect that doesn't match the dropEffect / effectAllowed of the drag source, it DOES NOT prevent drop on IE and Safari! For FireFox and Chrome the drop is prevented if there they don't match.
Default value is browser dependent and can depend on e.g. modifier keys.
From Moz Foundation: "You can modify the dropEffect property during the dragenter or dragover events, if for example, a particular drop target only supports certain operations. You can modify the dropEffect property to override the user effect, and enforce a specific drop operation to occur. Note that this effect must be one listed within the effectAllowed property. Otherwise, it will be set to an alternate value that is allowed."
dropEffect - the drop effect to be set or null to not modifypublic DropEffect getDropEffect()
null if none setsetDropEffect(DropEffect)public void setDropCriteriaScript(String criteriaScript)
false.
Drop will be allowed if it passes both this criteria script and the
criteria set via any of setDropCriterion() or setDropCriteria() methods. If no criteria is set, then the drop is
always accepted, if the set dropEffect
matches the drag source.
IMPORTANT: Construct the criteria script carefully and do not include untrusted sources such as user input. Always keep in mind that the script is executed on the client as is.
Example:
target.setDropCriterion(
// If dragged source contains a URL, allow it to be dropped
"if (event.dataTransfer.types.includes('text/uri-list')) {"
+ " return true;" + "}" +
// Otherwise cancel the event
"return false;");
criteriaScript - JavaScript to be executed when drop event happens or
null to clear.public String getDropCriteriaScript()
false, then it is determined the drop is not
allowed.setDropCriteriaScript(String)public void setDropCriterion(String key, String value)
Note that calling this method will overwrite the previously set criteria.
To set multiple criteria, call the
setDropCriteria(Criterion.Match, Criterion...) method.
To handle more complex criteria, define a custom script with
setDropCriteriaScript(String). Drop will be allowed if both this
criterion and the criteria script are passed.
key - key of the payload to be comparedvalue - value to be compared to the payload's valueDragSourceExtension.setPayload(String, String)public void setDropCriterion(String key, ComparisonOperator operator, int value)
Note that calling this method will overwrite the previously set criteria.
To set multiple criteria, call the
setDropCriteria(Criterion.Match, Criterion...) method.
To handle more complex criteria, define a custom script with
setDropCriteriaScript(String). Drop will be allowed if both this
criterion and the criteria script are passed.
key - key of the payload to be comparedoperator - comparison operator to be usedvalue - value to be compared to the payload's valueDragSourceExtension.setPayload(String, int)public void setDropCriterion(String key, ComparisonOperator operator, double value)
Note that calling this method will overwrite the previously set criteria.
To set multiple criteria, call the
setDropCriteria(Criterion.Match, Criterion...) method.
To handle more complex criteria, define a custom script with
setDropCriteriaScript(String). Drop will be allowed if both this
criterion and the criteria script are passed.
key - key of the payload to be comparedoperator - comparison operator to be usedvalue - value to be compared to the payload's valueDragSourceExtension.setPayload(String, double)public void setDropCriteria(Criterion.Match match, Criterion... criteria)
The drag passes these criteria if, depending on match, any or all
of the criteria matches the payload, that is the value of the payload
compared to the value of the criterion using the criterion's operator
holds.
Note that calling this method will overwrite the previously set criteria.
To handle more complex criteria, define a custom script with
setDropCriteriaScript(String). Drop will be allowed if both this
criterion and the criteria script are passed.
match - defines whether any or all of the given criteria should match
to allow drop on this drop targetcriteria - criteria to be compared to the payloadpublic Registration addDropListener(DropListener<T> listener)
DropListener.drop(DropEvent) is called when drop event happens on
the client side.listener - Listener to handle drop event.protected DropTargetState 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 AbstractClientConnectorprotected DropTargetState getState(boolean markAsDirty)
AbstractClientConnectorgetState in class AbstractClientConnectormarkAsDirty - true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()public T getParent()
getParent in interface ClientConnectorgetParent in interface ConnectorgetParent in class AbstractExtensionCopyright © 2018 Vaadin Ltd. All rights reserved.