T
- Type of the Grid bean.public class GridDropTarget<T> extends DropTargetExtension<Grid<T>>
GridRowDragger
,
Serialized FormClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Constructor and Description |
---|
GridDropTarget(Grid<T> target,
DropMode dropMode)
Extends a Grid and makes it's rows drop targets for HTML5 drag and drop.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addGridDropListener(GridDropListener<T> listener)
Attaches drop listener for the current drop target.
|
DropMode |
getDropMode()
Gets the drop mode of this drop target.
|
int |
getDropThreshold()
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 GridDropTargetState |
getState()
Returns the shared state for this connector.
|
protected GridDropTargetState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
boolean |
isDropAllowedOnRowsWhenSorted()
Gets whether drops are allowed on rows as target, when the user has
sorted the grid.
|
protected void |
registerDropTargetRpc()
Registers the server side RPC methods invoked from client side on
drop event. |
void |
remove()
Remove this extension from its target.
|
void |
setDropAllowedOnRowsWhenSorted(boolean dropAllowedOnSortedGridRows)
Sets whether the grid accepts drop on rows as target when the grid has
been sorted by the user.
|
void |
setDropMode(DropMode dropMode)
Sets the drop mode of this drop target.
|
void |
setDropThreshold(int threshold)
Sets the threshold between drop locations from the top and the bottom of
a row in pixels.
|
addDropListener, attach, getDropCriteriaScript, getDropEffect, getParent, onDrop, setDropCriteria, setDropCriteriaScript, setDropCriterion, setDropCriterion, setDropCriterion, setDropEffect
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 GridDropTarget(Grid<T> target, DropMode dropMode)
target
- Grid to be extended.dropMode
- Drop mode that describes the allowed drop locations within the
Grid's row.GridDropEvent.getDropLocation()
public Grid<T> getGrid()
public void setDropMode(DropMode dropMode)
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 the GridDropEvent.getDropTargetRow()
will return an
empty optional.
When using DropMode.BETWEEN
or
DropMode.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
the GridDropEvent.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_GRID
is used automatically when the grid
has been sorted and setDropAllowedOnRowsWhenSorted(boolean)
is
false
- 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, or
setDropAllowedOnRowsWhenSorted(boolean)
is set back to
true
.
dropMode
- Drop mode that describes the allowed drop locations within the
Grid's row.GridDropEvent.getDropLocation()
,
setDropAllowedOnRowsWhenSorted(boolean)
public DropMode getDropMode()
public void setDropAllowedOnRowsWhenSorted(boolean dropAllowedOnSortedGridRows)
Default value is true
for backwards compatibility with 8.1. When
true
is used or the grid is not sorted, the mode used in
setDropMode(DropMode)
is always used.
false
value means that when the grid has been sorted, the drop
mode is always DropMode.ON_GRID
, regardless of what was set with
setDropMode(DropMode)
. Once the grid is not sorted anymore, the
sort mode is reverted back to what was set with
setDropMode(DropMode)
.
dropAllowedOnSortedGridRows
- true
for allowing, false
for not allowing
drops on sorted grid rowspublic boolean isDropAllowedOnRowsWhenSorted()
public Registration addGridDropListener(GridDropListener<T> listener)
GridDropListener.drop(GridDropEvent)
is called when drop event
happens on the client side.listener
- Listener to handle drop event.public void setDropThreshold(int threshold)
Dropping an element
threshold
pixels from the top of a row results in a
drop event with DropLocation.ABOVE
threshold
pixels from the bottom of a row results in a
drop event with DropLocation.BELOW
DropLocation.ON_TOP
DropMode.ON_TOP_OR_BETWEEN
.
Default is 5 pixels.
threshold
- The threshold from the top and bottom of the row in pixels.public int getDropThreshold()
protected void registerDropTargetRpc()
DropTargetExtension
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
DropTargetExtension.onDrop(List, Map, DropEffect, MouseEventDetails)
instead.
registerDropTargetRpc
in class DropTargetExtension<Grid<T>>
protected GridDropTargetState 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 DropTargetExtension<Grid<T>>
protected GridDropTargetState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class DropTargetExtension<Grid<T>>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void remove()
Extension
remove
in interface Extension
remove
in class AbstractExtension
Copyright © 2020 Vaadin Ltd. All rights reserved.