com.vaadin.ui.components.grid.

Class GridDragSource<T>

    • Constructor Detail

      • GridDragSource

        public GridDragSource​(Grid<T> target)

        Extends a Grid and makes it's rows draggable.

        Parameters:

        target - Grid to be extended.

    • 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

      • 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 a String to be appended to the row as type 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:

        GridDragStartEvent

      • 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:

        GridDragEndEvent

      • 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 DragSourceExtension<Grid<T>>

      • 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 class DragSourceExtension<Grid<T>>

        Returns:

        The shared state for this connector. Never null.