com.vaadin.ui.components.grid.
Class GridDragSource<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.server.AbstractExtension
-
- com.vaadin.ui.dnd.DragSourceExtension<Grid<T>>
-
- com.vaadin.ui.components.grid.GridDragSource<T>
-
Type Parameters:
T
- The Grid bean type.All Implemented Interfaces:
MethodEventSource
,ClientConnector
,Extension
,Connector
,Serializable
Direct Known Subclasses:
public class GridDragSource<T> extends DragSourceExtension<Grid<T>>
Makes a Grid's rows draggable for HTML5 drag and drop functionality.
When dragging a selected row, all the visible selected rows are dragged. Note that ONLY visible rows are taken into account.
Since:
8.1
Author:
Vaadin Ltd.
See Also:
-
-
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 GridDragSource(Grid<T> target)
Extends a Grid and makes it's rows draggable.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addGridDragEndListener(GridDragEndListener<T> listener)
Attaches dragend listener for the current drag source grid.
Registration
addGridDragStartListener(GridDragStartListener<T> listener)
Attaches dragstart listener for the current drag source grid.
void
clearDragDataGenerator(String type)
Remove the generator function set for the given type.
SerializableFunction<T,String>
getDragDataGenerator(String type)
Returns the drag data generator function for the given type.
Grid<T>
getGrid()
Gets the grid this extension has been attached to.
protected GridDragSourceState
getState()
Returns the shared state for this connector.
protected GridDragSourceState
getState(boolean markAsDirty)
Returns the shared state for this connector.
protected void
registerDragSourceRpc()
Registers the server side RPC methods invoked from client side on
dragstart
anddragend
events.void
remove()
Remove this extension from its target.
void
setDragDataGenerator(String type, SerializableFunction<T,String> generator)
Sets a generator function for customizing drag data.
-
Methods inherited from class com.vaadin.ui.dnd.DragSourceExtension
addDragEndListener, addDragStartListener, attach, clearDataTransferData, clearDataTransferData, getDataTransferData, getDataTransferData, getDataTransferText, getDragData, getEffectAllowed, getParent, onDragEnd, onDragStart, setDataTransferData, setDataTransferText, setDragData, setDragImage, setEffectAllowed, setPayload, setPayload, setPayload
-
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
-
-
-
-
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
-
registerDragSourceRpc
protected void registerDragSourceRpc()
Description copied from class:
DragSourceExtension
Registers the server side RPC methods invoked from client side on
dragstart
anddragend
events.Override this method if you have custom RPC interface for transmitting those events with more data. If just need to do additional things before firing the events, then you should override
DragSourceExtension.onDragStart()
andDragSourceExtension.onDragEnd(DropEffect)
instead.Overrides:
registerDragSourceRpc
in classDragSourceExtension<Grid<T>>
-
setDragDataGenerator
public void setDragDataGenerator(String type, SerializableFunction<T,String> generator)
Sets a generator function for customizing drag data. The generated value will be accessible using the same
type
as the generator is set here. The function is executed for each item in the Grid during data generation. Return aString
to be appended to the row astype
data.Example, building a JSON object that contains the item's values:
dragSourceExtension.setDragDataGenerator("application/json", item -> { StringBuilder builder = new StringBuilder(); builder.append("{"); getParent().getColumns().forEach(column -> { builder.append("\"" + column.getCaption() + "\""); builder.append(":"); builder.append("\"" + column.getValueProvider().apply(item) + "\""); builder.append(","); }); builder.setLength(builder.length() - 1); // Remove last comma builder.append("}"); return builder.toString(); }
Parameters:
type
- Type of the generated data. The generated value will be accessible during drop using this type.generator
- Function to be executed on row data generation.
-
clearDragDataGenerator
public void clearDragDataGenerator(String type)
Remove the generator function set for the given type.
Parameters:
type
- Type of the generator to be removed.
-
getDragDataGenerator
public SerializableFunction<T,String> getDragDataGenerator(String type)
Returns the drag data generator function for the given type.
Parameters:
type
- Type of the generated data.Returns:
Drag data generator function for the given type.
-
addGridDragStartListener
public Registration addGridDragStartListener(GridDragStartListener<T> listener)
Attaches dragstart listener for the current drag source grid.
Parameters:
listener
- Listener to handle the dragstart event.Returns:
Handle to be used to remove this listener.
See Also:
-
addGridDragEndListener
public Registration addGridDragEndListener(GridDragEndListener<T> listener)
Attaches dragend listener for the current drag source grid.
Parameters:
listener
- Listener to handle the dragend event.Returns:
Handle to be used to remove this listener.
See Also:
-
remove
public void remove()
Description copied from interface:
Extension
Remove this extension from its target. After an extension has been removed, it cannot be attached again.
-
getState
protected GridDragSourceState getState()
Description copied from class:
AbstractClientConnector
Returns 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:
getState
in classDragSourceExtension<Grid<T>>
Returns:
The shared state for this connector. Never null.
-
getState
protected GridDragSourceState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classDragSourceExtension<Grid<T>>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
-