Class GridDropTarget<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.dnd.DropTargetExtension<Grid<T>>
-
- com.vaadin.ui.components.grid.GridDropTarget<T>
-
- Type Parameters:
T- Type of the Grid bean.
- All Implemented Interfaces:
MethodEventSource,ClientConnector,Extension,Connector,Serializable
- Direct Known Subclasses:
TreeGridDropTarget
public class GridDropTarget<T> extends DropTargetExtension<Grid<T>>
Makes the rows of a Grid HTML5 drop targets. This is the server side counterpart of GridDropTargetExtensionConnector.- Since:
- 8.1
- Author:
- Vaadin Ltd
- See Also:
GridRowDragger, 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 GridDropTarget(Grid<T> target, DropMode dropMode)Extends a Grid and makes it's rows drop targets for HTML5 drag and drop.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddGridDropListener(GridDropListener<T> listener)Attaches drop listener for the current drop target.DropModegetDropMode()Gets the drop mode of this drop target.intgetDropThreshold()Gets the threshold between drop locations from the top and the bottom of the row.Grid<T>getGrid()Gets the grid this extension has been attached to.protected GridDropTargetStategetState()Returns the shared state for this connector.protected GridDropTargetStategetState(boolean markAsDirty)Returns the shared state for this connector.booleanisDropAllowedOnRowsWhenSorted()Gets whether drops are allowed on rows as target, when the user has sorted the grid.protected voidregisterDropTargetRpc()Registers the server side RPC methods invoked from client side ondropevent.voidremove()Remove this extension from its target.voidsetDropAllowedOnRowsWhenSorted(boolean dropAllowedOnSortedGridRows)Sets whether the grid accepts drop on rows as target when the grid has been sorted by the user.voidsetDropMode(DropMode dropMode)Sets the drop mode of this drop target.voidsetDropThreshold(int threshold)Sets the threshold between drop locations from the top and the bottom of a row in pixels.-
Methods inherited from class com.vaadin.ui.dnd.DropTargetExtension
addDropListener, attach, getDropCriteriaScript, getDropEffect, getParent, onDrop, setDropCriteria, setDropCriteriaScript, setDropCriterion, setDropCriterion, setDropCriterion, setDropEffect
-
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
-
GridDropTarget
public GridDropTarget(Grid<T> target, DropMode dropMode)
Extends a Grid and makes it's rows drop targets for HTML5 drag and drop.- Parameters:
target- Grid to be extended.dropMode- Drop mode that describes the allowed drop locations within the Grid's row.- See Also:
GridDropEvent.getDropLocation()
-
-
Method Detail
-
getGrid
public Grid<T> getGrid()
Gets the grid this extension has been attached to.- Returns:
- the grid for this extension
- Since:
- 8.2
-
setDropMode
public void setDropMode(DropMode dropMode)
Sets the drop mode of this drop target.When using
DropMode.ON_TOP, and the grid is either empty or has empty space after the last row, the drop can still happen on the empty space, and theGridDropEvent.getDropTargetRow()will return an empty optional.When using
DropMode.BETWEENorDropMode.ON_TOP_OR_BETWEEN, and there is at least one row in the grid, any drop after the last row in the grid will get the last row as theGridDropEvent.getDropTargetRow(). If there are no rows in the grid, then it will return an empty optional.If using
DropMode.ON_GRID, then the drop will not happen on any row, but instead just "on the grid". The target row will not be present in this case.NOTE:
DropMode.ON_GRIDis used automatically when the grid has been sorted andsetDropAllowedOnRowsWhenSorted(boolean)isfalse- since the drop location would not necessarily match the correct row because of the sorting. During the sorting, any calls to this method don't have any effect until the sorting has been removed, orsetDropAllowedOnRowsWhenSorted(boolean)is set back totrue.- Parameters:
dropMode- Drop mode that describes the allowed drop locations within the Grid's row.- See Also:
GridDropEvent.getDropLocation(),setDropAllowedOnRowsWhenSorted(boolean)
-
getDropMode
public DropMode getDropMode()
Gets the drop mode of this drop target.- Returns:
- Drop mode that describes the allowed drop locations within the Grid's row.
-
setDropAllowedOnRowsWhenSorted
public void setDropAllowedOnRowsWhenSorted(boolean dropAllowedOnSortedGridRows)
Sets whether the grid accepts drop on rows as target when the grid has been sorted by the user.Default value is
truefor backwards compatibility with 8.1. Whentrueis used or the grid is not sorted, the mode used insetDropMode(DropMode)is always used.falsevalue means that when the grid has been sorted, the drop mode is alwaysDropMode.ON_GRID, regardless of what was set withsetDropMode(DropMode). Once the grid is not sorted anymore, the sort mode is reverted back to what was set withsetDropMode(DropMode).- Parameters:
dropAllowedOnSortedGridRows-truefor allowing,falsefor not allowing drops on sorted grid rows- Since:
- 8.2
-
isDropAllowedOnRowsWhenSorted
public boolean isDropAllowedOnRowsWhenSorted()
Gets whether drops are allowed on rows as target, when the user has sorted the grid.- Returns:
- whether drop are allowed for the grid's rows when user has sorted the grid
- Since:
- 8.2
-
addGridDropListener
public Registration addGridDropListener(GridDropListener<T> listener)
Attaches drop listener for the current drop target.GridDropListener.drop(GridDropEvent)is called when drop event happens on the client side.- Parameters:
listener- Listener to handle drop event.- Returns:
- Handle to be used to remove this listener.
-
setDropThreshold
public void setDropThreshold(int threshold)
Sets the threshold between drop locations from the top and the bottom of a row in pixels.Dropping an element
- within
thresholdpixels from the top of a row results in a drop event withDropLocation.ABOVE - within
thresholdpixels from the bottom of a row results in a drop event withDropLocation.BELOW - anywhere else within the row results in a drop event with
DropLocation.ON_TOP
DropMode.ON_TOP_OR_BETWEEN.Default is 5 pixels.
- Parameters:
threshold- The threshold from the top and bottom of the row in pixels.
- within
-
getDropThreshold
public int getDropThreshold()
Gets the threshold between drop locations from the top and the bottom of the row.- Returns:
- The threshold in pixels.
-
registerDropTargetRpc
protected void registerDropTargetRpc()
Description copied from class:DropTargetExtensionRegisters the server side RPC methods invoked from client side ondropevent.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
DropTargetExtension.onDrop(List, Map, DropEffect, MouseEventDetails)instead.- Overrides:
registerDropTargetRpcin classDropTargetExtension<Grid<T>>
-
getState
protected GridDropTargetState 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 classDropTargetExtension<Grid<T>>- Returns:
- The shared state for this connector. Never null.
-
getState
protected GridDropTargetState getState(boolean markAsDirty)
Description copied from class:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classDropTargetExtension<Grid<T>>- 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()
-
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
-
-