Class GridDropTarget<T>

    • Constructor Detail

      • GridDropTarget

        public GridDropTarget​(Grid<T> target,
                              com.vaadin.shared.ui.grid.DropMode dropMode)
        Extends a Grid and makes it's rows drop targets for HTML5 drag and drop.
        Parameters:
        target - Grid to be extended.
        dropMode - Drop mode that describes the allowed drop locations within the Grid's row.
        See Also:
        GridDropEvent.getDropLocation()
    • 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
      • setDropMode

        public void setDropMode​(com.vaadin.shared.ui.grid.DropMode dropMode)
        Sets the drop mode of this drop target.

        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.

        Parameters:
        dropMode - Drop mode that describes the allowed drop locations within the Grid's row.
        See Also:
        GridDropEvent.getDropLocation(), setDropAllowedOnRowsWhenSorted(boolean)
      • getDropMode

        public com.vaadin.shared.ui.grid.DropMode getDropMode()
        Gets the drop mode of this drop target.
        Returns:
        Drop mode that describes the allowed drop locations within the Grid's row.
      • setDropAllowedOnRowsWhenSorted

        public void setDropAllowedOnRowsWhenSorted​(boolean dropAllowedOnSortedGridRows)
        Sets whether the grid accepts drop on rows as target when the grid has been sorted by the user.

        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).

        Parameters:
        dropAllowedOnSortedGridRows - true for allowing, false for not allowing drops on sorted grid rows
        Since:
        8.2
      • isDropAllowedOnRowsWhenSorted

        public boolean isDropAllowedOnRowsWhenSorted()
        Gets whether drops are allowed on rows as target, when the user has sorted the grid.
        Returns:
        whether drop are allowed for the grid's rows when user has sorted the grid
        Since:
        8.2
      • addGridDropListener

        public com.vaadin.shared.Registration addGridDropListener​(GridDropListener<T> listener)
        Attaches drop listener for the current drop target. GridDropListener.drop(GridDropEvent) is called when drop event happens on the client side.
        Parameters:
        listener - Listener to handle drop event.
        Returns:
        Handle to be used to remove this listener.
      • setDropThreshold

        public void setDropThreshold​(int threshold)
        Sets the threshold between drop locations from the top and the bottom of a row in pixels.

        Dropping an element

        • within threshold pixels from the top of a row results in a drop event with DropLocation.ABOVE
        • within threshold pixels from the bottom of a row results in a drop event with DropLocation.BELOW
        • anywhere else within the row results in a drop event with DropLocation.ON_TOP
        The value only has an effect when drop mode is set to DropMode.ON_TOP_OR_BETWEEN.

        Default is 5 pixels.

        Parameters:
        threshold - The threshold from the top and bottom of the row in pixels.
      • getDropThreshold

        public int getDropThreshold()
        Gets the threshold between drop locations from the top and the bottom of the row.
        Returns:
        The threshold in pixels.
      • getState

        protected com.vaadin.shared.ui.grid.GridDropTargetState 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 class DropTargetExtension<Grid<T>>
        Returns:
        The shared state for this connector. Never null.
      • getState

        protected com.vaadin.shared.ui.grid.GridDropTargetState getState​(boolean markAsDirty)
        Description copied from class: AbstractClientConnector
        Returns the shared state for this connector.
        Overrides:
        getState in class DropTargetExtension<Grid<T>>
        Parameters:
        markAsDirty - true if the connector should automatically be marked dirty, false otherwise
        Returns:
        The shared state for this connector. Never null.
        See Also:
        AbstractClientConnector.getState()
      • 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.
        Specified by:
        remove in interface Extension
        Overrides:
        remove in class AbstractExtension