Class GridRowDragger<T>

  • Type Parameters:
    T - The Grid bean type.
    All Implemented Interfaces:
    java.io.Serializable

    public class GridRowDragger<T>
    extends java.lang.Object
    implements java.io.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() 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.

    Since:
    8.2
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • 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, or null 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, or null 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 for ListDataProvider.

        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 java.util.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