T - The Grid bean type.public class GridRowDragger<T> extends Object implements Serializable
When dragging a selected row, all the visible selected rows are dragged. Note
that ONLY currently visible rows are taken into account. The drop mode for
the target grid is by default DropMode.BETWEEN.
To customize the settings for either the source or the target grid, use
getGridDragSource() and getGridDropTarget().The drop target
grid has been set to not allow drops for a target row when the grid has been
sorted, since the visual drop target location would not match where the item
would actually be dropped into. Additionally, a grid MUST NOT be the target
of more than one GridRowDragger.
NOTE: this helper works only with ListDataProvider on both grids.
If you have another data provider, you should customize data provider
updating on drop with
setSourceDataProviderUpdater(SourceDataProviderUpdater) &
setTargetDataProviderUpdater(TargetDataProviderUpdater) and add a
custom drop index calculator with
setDropIndexCalculator(DropIndexCalculator).
In case you are not using a ListDataProvider and don't have custom
handlers, UnsupportedOperationException is thrown on drop event.
| Constructor and Description |
|---|
GridRowDragger(Grid<T> grid)
Enables DnD reordering for the rows in the given grid.
|
GridRowDragger(Grid<T> grid,
DropMode dropMode)
Enables DnD reordering the rows in the given grid with the given drop
mode.
|
GridRowDragger(Grid<T> source,
Grid<T> target)
Enables DnD moving of rows from the source grid to the target grid.
|
GridRowDragger(Grid<T> source,
Grid<T> target,
DropMode dropMode)
Enables DnD moving of rows from the source grid to the target grid with
the given drop mode.
|
GridRowDragger(Grid<T> source,
Grid<T> target,
TargetDataProviderUpdater<T> targetDataProviderUpdater,
SourceDataProviderUpdater<T> sourceDataProviderUpdater)
Enables DnD moving of rows from the source grid to the target grid with
the custom data provider updaters.
|
| Modifier and Type | Method and Description |
|---|---|
protected List<T> |
getDraggedItems()
Returns the currently dragged items captured from the source grid no drag
start event, or
null if no drag active. |
DropIndexCalculator<T> |
getDropIndexCalculator()
Gets the drop index calculator.
|
GridDragSource<T> |
getGridDragSource()
Returns the drag source grid, exposing it for customizations.
|
GridDropTarget<T> |
getGridDropTarget()
Returns the drop target grid to allow performing customizations such as
altering
DropEffect. |
SourceDataProviderUpdater<T> |
getSourceDataProviderUpdater()
Returns the source grid data provider updater.
|
TargetDataProviderUpdater<T> |
getTargetDataProviderUpdater()
Returns the target grid data provider updater.
|
protected void |
handleDrop(GridDropEvent<T> event)
This method is triggered when there has been a drop on the target grid.
|
void |
setDropIndexCalculator(DropIndexCalculator<T> dropIndexCalculator)
Sets the drop index calculator for the target grid.
|
void |
setSourceDataProviderUpdater(SourceDataProviderUpdater<T> sourceDataProviderUpdater)
Sets the source data provider updater, which handles removing items from
the drag source grid.
|
void |
setTargetDataProviderUpdater(TargetDataProviderUpdater<T> targetDataProviderUpdater)
Sets the target data provider updater, which handles adding the dropped
items to the target grid.
|
public GridRowDragger(Grid<T> grid)
DropMode.BETWEEN is used.
NOTE: this only works when the grid has a
ListDataProvider. Use the custom handlers
setSourceDataProviderUpdater(SourceDataProviderUpdater) and
setTargetDataProviderUpdater(TargetDataProviderUpdater) for
other data providers.
NOTE: When allowing the user to DnD reorder a grid's rows, you
should not allow the user to sort the grid since when the grid is sorted,
as the reordering doens't make any sense since the drop target cannot be
shown for the correct place due to the sorting. Sorting columns is
enabled by default for in-memory data provider grids. Sorting can be
disabled for columns with Grid.getColumns() and
Grid.Column.setSortable(boolean).
grid - Grid to be extended.public GridRowDragger(Grid<T> grid, DropMode dropMode)
NOTE: this only works when the grid has a
ListDataProvider. Use the custom handlers
setSourceDataProviderUpdater(SourceDataProviderUpdater) and
setTargetDataProviderUpdater(TargetDataProviderUpdater) for
other data providers.
NOTE: When allowing the user to DnD reorder a grid's rows, you
should not allow the user to sort the grid since when the grid is sorted,
as the reordering doens't make any sense since the drop target cannot be
shown for the correct place due to the sorting. Sorting columns is
enabled by default for in-memory data provider grids. Sorting can be
disabled for columns with Grid.getColumns() and
Grid.Column.setSortable(boolean).
grid - the grid to enable row DnD reordering ondropMode - DropMode to be used.public GridRowDragger(Grid<T> source, Grid<T> target)
DropMode.BETWEEN is used.
NOTE: this only works when the grids have a
ListDataProvider. Use the custom handlers
setSourceDataProviderUpdater(SourceDataProviderUpdater) and
setTargetDataProviderUpdater(TargetDataProviderUpdater) for
other data providers.
source - the source grid dragged from.target - the target grid dropped to.public GridRowDragger(Grid<T> source, Grid<T> target, TargetDataProviderUpdater<T> targetDataProviderUpdater, SourceDataProviderUpdater<T> sourceDataProviderUpdater)
DropMode.BETWEEN is used.
source - grid dragged fromtarget - grid dragged totargetDataProviderUpdater - handler for updating target grid data providersourceDataProviderUpdater - handler for updating source grid data providerpublic GridRowDragger(Grid<T> source, Grid<T> target, DropMode dropMode)
NOTE: this only works when the grids have a
ListDataProvider. Use the other constructors or custom
handlers setSourceDataProviderUpdater(SourceDataProviderUpdater)
and setTargetDataProviderUpdater(TargetDataProviderUpdater) for
other data providers.
source - the drag source gridtarget - the drop target griddropMode - the drop mode to usepublic void setTargetDataProviderUpdater(TargetDataProviderUpdater<T> targetDataProviderUpdater)
By default, items are added to the index where they were dropped on for
any ListDataProvider. If another type of data provider is used,
this updater should be set to handle updating instead.
targetDataProviderUpdater - the target drop handler to set, or null to removepublic TargetDataProviderUpdater<T> getTargetDataProviderUpdater()
public void setSourceDataProviderUpdater(SourceDataProviderUpdater<T> sourceDataProviderUpdater)
By default the items are removed from any ListDataProvider. If
another type of data provider is used, this updater should be set to
handle updating instead.
If you want to skip removing items from the source, you can use
SourceDataProviderUpdater.NOOP.
sourceDataProviderUpdater - the drag source data provider updater to set, or null
to removepublic SourceDataProviderUpdater<T> getSourceDataProviderUpdater()
Default is null and the items are just removed from the source
grid, which only works for ListDataProvider.
public void setDropIndexCalculator(DropIndexCalculator<T> dropIndexCalculator)
By default, items are placed on the index they are dropped into in the target grid.
If you want to always drop items to the end of the target grid, you can
use DropIndexCalculator#ALWAYS_DROP_TO_END.
dropIndexCalculator - the drop index calculatorpublic DropIndexCalculator<T> getDropIndexCalculator()
Default is null and the dropped items are placed on the drop
location.
public GridDropTarget<T> getGridDropTarget()
DropEffect.public GridDragSource<T> getGridDragSource()
protected List<T> getDraggedItems()
null if no drag active.nullprotected void handleDrop(GridDropEvent<T> event)
This method is protected only for testing reasons, you should not
override this but instead use
setSourceDataProviderUpdater(SourceDataProviderUpdater),
setTargetDataProviderUpdater(TargetDataProviderUpdater) and
setDropIndexCalculator(DropIndexCalculator) to customize how to
handle the drops.
event - the drop event on the target gridCopyright © 2022 Vaadin Ltd. All rights reserved.