Class DropTargetExtensionConnector
- java.lang.Object
-
- com.vaadin.client.ui.AbstractConnector
-
- com.vaadin.client.extensions.AbstractExtensionConnector
-
- com.vaadin.client.extensions.DropTargetExtensionConnector
-
- All Implemented Interfaces:
com.google.gwt.event.shared.EventHandler,StateChangeEvent.StateChangeHandler,ServerConnector,Connector,Serializable
- Direct Known Subclasses:
FileDropTargetConnector,GridDropTargetConnector
public class DropTargetExtensionConnector extends AbstractExtensionConnector
Extension to add drop target functionality to a widget for using HTML5 drag and drop. Client side counterpart ofDropTargetExtension.- Since:
- 8.1
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringSTYLE_SUFFIX_DRAG_BOTTOMStyle name suffix for dragging data over the bottom part of the drop target.protected static StringSTYLE_SUFFIX_DRAG_CENTERStyle name suffix for dragging data over the center of the drop target.protected static StringSTYLE_SUFFIX_DRAG_TOPStyle name suffix for dragging data over the top part of the drop target.protected static StringSTYLE_SUFFIX_DROPTARGETStyle name suffix for indicating that the element is drop target.
-
Constructor Summary
Constructors Constructor Description DropTargetExtensionConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddDragOverStyle(com.google.gwt.dom.client.NativeEvent event)Add class that indicates that the component is a target while data is being dragged over it.protected voidaddDropTargetStyle()Add class name for the drop target element indicating that data can be dropped onto it.protected voidextend(ServerConnector target)Called when the extension is attached to its parent.protected com.google.gwt.dom.client.ElementgetDropTargetElement()Finds the drop target element within the widget.DropTargetStategetState()Returns the shared state object for this connector.protected booleanisDropAllowedByCriteriaScript(com.google.gwt.dom.client.NativeEvent event)Checks if a criteria script exists and, if yes, executes it.protected voidonDragEnter(elemental.events.Event event)Event handler for thedragenterevent.protected voidonDragLeave(elemental.events.Event event)Event handler for thedragleaveevent.protected voidonDragOver(elemental.events.Event event)Event handler for thedragoverevent.protected voidonDrop(elemental.events.Event event)Event handler for thedropevent.voidonUnregister()Event called when connector has been unregistered.protected voidremoveDragOverStyle(com.google.gwt.dom.client.NativeEvent event)Remove the drag over indicator class name from the target element.protected voidremoveDropTargetStyle()Remove class name from the drop target element indication that data can be dropped onto it.protected voidsendDropEventToServer(List<String> types, Map<String,String> data, String dropEffect, com.google.gwt.dom.client.NativeEvent dropEvent)Initiates a server RPC for the drop event.-
Methods inherited from class com.vaadin.client.extensions.AbstractExtensionConnector
setParent
-
Methods inherited from class com.vaadin.client.ui.AbstractConnector
addStateChangeHandler, addStateChangeHandler, createState, doInit, ensureHandlerManager, fireEvent, forceStateChange, getChildren, getConnection, getConnectorId, getParent, getResourceUrl, getRpcImplementations, getRpcProxy, getStateType, getTag, hasEventListener, init, isEnabled, onStateChanged, registerRpc, removeStateChangeHandler, removeStateChangeHandler, setChildren, setTag, unregisterRpc, updateEnabledState
-
-
-
-
Field Detail
-
STYLE_SUFFIX_DRAG_CENTER
protected static final String STYLE_SUFFIX_DRAG_CENTER
Style name suffix for dragging data over the center of the drop target.- See Also:
- Constant Field Values
-
STYLE_SUFFIX_DRAG_TOP
protected static final String STYLE_SUFFIX_DRAG_TOP
Style name suffix for dragging data over the top part of the drop target.- See Also:
- Constant Field Values
-
STYLE_SUFFIX_DRAG_BOTTOM
protected static final String STYLE_SUFFIX_DRAG_BOTTOM
Style name suffix for dragging data over the bottom part of the drop target.- See Also:
- Constant Field Values
-
STYLE_SUFFIX_DROPTARGET
protected static final String STYLE_SUFFIX_DROPTARGET
Style name suffix for indicating that the element is drop target.- See Also:
- Constant Field Values
-
-
Method Detail
-
extend
protected void extend(ServerConnector target)
Description copied from class:AbstractExtensionConnectorCalled when the extension is attached to its parent. This method is only called once as an extension cannot be moved from one parent to another.- Specified by:
extendin classAbstractExtensionConnector- Parameters:
target- The connector this extension extends
-
onUnregister
public void onUnregister()
Description copied from interface:ServerConnectorEvent called when connector has been unregistered.- Specified by:
onUnregisterin interfaceServerConnector- Overrides:
onUnregisterin classAbstractConnector
-
getDropTargetElement
protected com.google.gwt.dom.client.Element getDropTargetElement()
Finds the drop target element within the widget. By default, returns the topmost element.- Returns:
- the drop target element in the parent widget.
-
onDragEnter
protected void onDragEnter(elemental.events.Event event)
Event handler for thedragenterevent.Override this method in case custom handling for the dragstart event is required. If the drop is allowed, the event should prevent default.
- Parameters:
event- browser event to be handled
-
onDragOver
protected void onDragOver(elemental.events.Event event)
Event handler for thedragoverevent.Override this method in case custom handling for the dragover event is required. If the drop is allowed, the event should prevent default.
- Parameters:
event- browser event to be handled
-
onDragLeave
protected void onDragLeave(elemental.events.Event event)
Event handler for thedragleaveevent.Override this method in case custom handling for the dragleave event is required.
- Parameters:
event- browser event to be handled
-
onDrop
protected void onDrop(elemental.events.Event event)
Event handler for thedropevent.Override this method in case custom handling for the drop event is required. If the drop is allowed, the event should prevent default.
- Parameters:
event- browser event to be handled
-
isDropAllowedByCriteriaScript
protected boolean isDropAllowedByCriteriaScript(com.google.gwt.dom.client.NativeEvent event)
Checks if a criteria script exists and, if yes, executes it. This method is protected, so subclasses as e.g. GridDropTargetConnector can override it to add additional script parameters.- Parameters:
event- browser event (dragEnter, dragOver, drop) that should be evaluated by the criteria script- Returns:
trueif no script was given or if the script returned true,falseotherwise.
-
sendDropEventToServer
protected void sendDropEventToServer(List<String> types, Map<String,String> data, String dropEffect, com.google.gwt.dom.client.NativeEvent dropEvent)
Initiates a server RPC for the drop event.- Parameters:
types- List of data types fromDataTransfer.typesobject.data- Map containing all types and corresponding data from theDataTransferobject.dropEffect- The desired drop effect.
-
addDropTargetStyle
protected void addDropTargetStyle()
Add class name for the drop target element indicating that data can be dropped onto it. The class name has the following format:[primaryStyleName]-droptargetThe added class name is update automatically by the framework when the primary style name changes.
-
removeDropTargetStyle
protected void removeDropTargetStyle()
Remove class name from the drop target element indication that data can be dropped onto it.
-
addDragOverStyle
protected void addDragOverStyle(com.google.gwt.dom.client.NativeEvent event)
Add class that indicates that the component is a target while data is being dragged over it.This is triggered on
dragenteranddragoverevents pending if the drop is possible. The drop is possible if the drop effect for the target and source do match and the drop criteria script evaluates to true or is not set.- Parameters:
event- the dragenter or dragover event that triggered the indication.
-
removeDragOverStyle
protected void removeDragOverStyle(com.google.gwt.dom.client.NativeEvent event)
Remove the drag over indicator class name from the target element.This is triggered on
drop,dragleaveanddragoverevents pending on whether the drop has happened or if it is not possible. The drop is not possible if the drop effect for the source and target don't match or if there is a drop criteria script that evaluates to false.- Parameters:
event- the event that triggered the removal of the indicator
-
getState
public DropTargetState getState()
Description copied from class:AbstractConnectorReturns the shared state object for this connector. Override this method to define the shared state type for your connector.- Specified by:
getStatein interfaceServerConnector- Overrides:
getStatein classAbstractConnector- Returns:
- the current shared state (never null)
-
-