com.vaadin.client.extensions.
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:
public class DropTargetExtensionConnector extends AbstractExtensionConnector
Extension to add drop target functionality to a widget for using HTML5 drag and drop. Client side counterpart of
DropTargetExtension
.Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
STYLE_SUFFIX_DRAG_BOTTOM
Style name suffix for dragging data over the bottom part of the drop target.
protected static String
STYLE_SUFFIX_DRAG_CENTER
Style name suffix for dragging data over the center of the drop target.
protected static String
STYLE_SUFFIX_DRAG_TOP
Style name suffix for dragging data over the top part of the drop target.
protected static String
STYLE_SUFFIX_DROPTARGET
Style name suffix for indicating that the element is drop target.
-
Constructor Summary
Constructors Constructor Description DropTargetExtensionConnector()
-
Method Summary
All Methods Modifier and Type Method Description 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.
protected void
addDropTargetStyle()
Add class name for the drop target element indicating that data can be dropped onto it.
protected void
extend(ServerConnector target)
Called when the extension is attached to its parent.
protected com.google.gwt.dom.client.Element
getDropTargetElement()
Finds the drop target element within the widget.
DropTargetState
getState()
Returns the shared state object for this connector.
protected boolean
isDropAllowedByCriteriaScript(com.google.gwt.dom.client.NativeEvent event)
Checks if a criteria script exists and, if yes, executes it.
protected void
onDragEnter(elemental.events.Event event)
Event handler for the
dragenter
event.protected void
onDragLeave(elemental.events.Event event)
Event handler for the
dragleave
event.protected void
onDragOver(elemental.events.Event event)
Event handler for the
dragover
event.protected void
onDrop(elemental.events.Event event)
Event handler for the
drop
event.void
onUnregister()
Event called when connector has been unregistered.
protected void
removeDragOverStyle(com.google.gwt.dom.client.NativeEvent event)
Remove the drag over indicator class name from the target element.
protected void
removeDropTargetStyle()
Remove class name from the drop target element indication that data can be dropped onto it.
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.
-
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:
-
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:
-
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:
-
STYLE_SUFFIX_DROPTARGET
protected static final String STYLE_SUFFIX_DROPTARGET
Style name suffix for indicating that the element is drop target.
See Also:
-
-
Method Detail
-
extend
protected void extend(ServerConnector target)
Description copied from class:
AbstractExtensionConnector
Called 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:
extend
in classAbstractExtensionConnector
Parameters:
target
- The connector this extension extends
-
onUnregister
public void onUnregister()
Description copied from interface:
ServerConnector
Event called when connector has been unregistered.
Specified by:
onUnregister
in interfaceServerConnector
Overrides:
onUnregister
in 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 the
dragenter
event.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 the
dragover
event.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 the
dragleave
event.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 the
drop
event.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 scriptReturns:
true
if no script was given or if the script returned true,false
otherwise.
-
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.types
object.data
- Map containing all types and corresponding data from theDataTransfer
object.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:
The added class name is update automatically by the framework when the primary style name changes.[primaryStyleName]-droptarget
-
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
dragenter
anddragover
events 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
,dragleave
anddragover
events 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:
AbstractConnector
Returns the shared state object for this connector. Override this method to define the shared state type for your connector.
Specified by:
getState
in interfaceServerConnector
Overrides:
getState
in classAbstractConnector
Returns:
the current shared state (never null)
-
-