com.vaadin.ui.components.grid.
Class GridRowDragger<T>
- java.lang.Object
-
- com.vaadin.ui.components.grid.GridRowDragger<T>
-
Type Parameters:
T
- The Grid bean type.All Implemented Interfaces:
public class GridRowDragger<T> extends Object implements Serializable
Allows dragging rows for reordering within a Grid and between two separate Grids when the item type is the same.
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()
andgetGridDropTarget()
.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 withsetSourceDataProviderUpdater(SourceDataProviderUpdater)
&setTargetDataProviderUpdater(TargetDataProviderUpdater)
and add a custom drop index calculator withsetDropIndexCalculator(DropIndexCalculator)
.In case you are not using a
ListDataProvider
and don't have custom handlers,UnsupportedOperationException
is thrown on drop event.Since:
8.2
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
GridRowDragger
public GridRowDragger(Grid<T> grid)
Enables DnD reordering for the rows in the given grid.
DropMode.BETWEEN
is used.NOTE: this only works when the grid has a
ListDataProvider
. Use the custom handlerssetSourceDataProviderUpdater(SourceDataProviderUpdater)
andsetTargetDataProviderUpdater(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()
andGrid.Column.setSortable(boolean)
.Parameters:
grid
- Grid to be extended.
-
GridRowDragger
public GridRowDragger(Grid<T> grid, DropMode dropMode)
Enables DnD reordering the rows in the given grid with the given drop mode.
NOTE: this only works when the grid has a
ListDataProvider
. Use the custom handlerssetSourceDataProviderUpdater(SourceDataProviderUpdater)
andsetTargetDataProviderUpdater(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()
andGrid.Column.setSortable(boolean)
.Parameters:
grid
- the grid to enable row DnD reordering ondropMode
- DropMode to be used.
-
GridRowDragger
public GridRowDragger(Grid<T> source, Grid<T> target)
Enables DnD moving of rows from the source grid to the target grid.
DropMode.BETWEEN
is used.NOTE: this only works when the grids have a
ListDataProvider
. Use the custom handlerssetSourceDataProviderUpdater(SourceDataProviderUpdater)
andsetTargetDataProviderUpdater(TargetDataProviderUpdater)
for other data providers.Parameters:
source
- the source grid dragged from.target
- the target grid dropped to.
-
GridRowDragger
public 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.
DropMode.BETWEEN
is used.Parameters:
source
- grid dragged fromtarget
- grid dragged totargetDataProviderUpdater
- handler for updating target grid data providersourceDataProviderUpdater
- handler for updating source grid data provider
-
GridRowDragger
public 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.
NOTE: this only works when the grids have a
ListDataProvider
. Use the other constructors or custom handlerssetSourceDataProviderUpdater(SourceDataProviderUpdater)
andsetTargetDataProviderUpdater(TargetDataProviderUpdater)
for other data providers.Parameters:
source
- the drag source gridtarget
- the drop target griddropMode
- the drop mode to use
-
-
Method Detail
-
setTargetDataProviderUpdater
public void setTargetDataProviderUpdater(TargetDataProviderUpdater<T> targetDataProviderUpdater)
Sets the target data provider updater, which handles adding the dropped items to the target grid.
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.Parameters:
targetDataProviderUpdater
- the target drop handler to set, ornull
to remove
-
getTargetDataProviderUpdater
public TargetDataProviderUpdater<T> getTargetDataProviderUpdater()
Returns the target grid data provider updater.
Returns:
target grid drop handler
-
setSourceDataProviderUpdater
public void setSourceDataProviderUpdater(SourceDataProviderUpdater<T> sourceDataProviderUpdater)
Sets the source data provider updater, which handles removing items from the drag source grid.
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
.Parameters:
sourceDataProviderUpdater
- the drag source data provider updater to set, ornull
to remove
-
getSourceDataProviderUpdater
public SourceDataProviderUpdater<T> getSourceDataProviderUpdater()
Returns the source grid data provider updater.
Default is
null
and the items are just removed from the source grid, which only works forListDataProvider
.Returns:
the source grid drop handler
-
setDropIndexCalculator
public void setDropIndexCalculator(DropIndexCalculator<T> dropIndexCalculator)
Sets the drop index calculator for the target grid. With this callback you can have a custom drop location instead of the actual one.
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.alwaysDropToEnd()
.Parameters:
dropIndexCalculator
- the drop index calculator
-
getDropIndexCalculator
public DropIndexCalculator<T> getDropIndexCalculator()
Gets the drop index calculator.
Default is
null
and the dropped items are placed on the drop location.Returns:
the drop index calculator
-
getGridDropTarget
public GridDropTarget<T> getGridDropTarget()
Returns the drop target grid to allow performing customizations such as altering
DropEffect
.Returns:
the drop target grid
-
getGridDragSource
public GridDragSource<T> getGridDragSource()
Returns the drag source grid, exposing it for customizations.
Returns:
the drag source grid
-
getDraggedItems
protected List<T> getDraggedItems()
Returns the currently dragged items captured from the source grid no drag start event, or
null
if no drag active.Returns:
the currently dragged items or
null
-
handleDrop
protected void handleDrop(GridDropEvent<T> event)
This method is triggered when there has been a drop on the target grid.
This method is protected only for testing reasons, you should not override this but instead use
setSourceDataProviderUpdater(SourceDataProviderUpdater)
,setTargetDataProviderUpdater(TargetDataProviderUpdater)
andsetDropIndexCalculator(DropIndexCalculator)
to customize how to handle the drops.Parameters:
event
- the drop event on the target grid
-
-