Class TwinColGrid<T>

All Implemented Interfaces:
AttachNotifier, ClickNotifier<VerticalLayout>, DetachNotifier, HasComponents, HasElement, HasEnabled, HasOrderedComponents<VerticalLayout>, HasSize, HasStyle, HasValidation, HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>, HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>, FlexComponent<VerticalLayout>, ThemableLayout, Serializable
Direct Known Subclasses:
LegacyTwinColGrid

@JsModule("./src/fc-twin-col-grid-auto-resize.js") @CssImport("./styles/twin-col-grid-button.css") @CssImport("./styles/twincol-grid.css") public class TwinColGrid<T> extends VerticalLayout implements HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>, HasComponents, HasSize, HasValidation
See Also:
  • Constructor Details

    • TwinColGrid

      public TwinColGrid()
      Constructs a new TwinColGrid with an empty ListDataProvider.
    • TwinColGrid

      public TwinColGrid(Supplier<Grid<T>> gridSupplier)
      Constructs a new empty TwinColGrid, using the specified supplier for instantiating both grids.
      Parameters:
      gridSupplier - a supplier for instantiating both grids
    • TwinColGrid

      public TwinColGrid(@NonNull @NonNull Grid<T> availableGrid, @NonNull @NonNull Grid<T> selectionGrid)
      Constructs a new empty TwinColGrid, using the specified grids for each side.
      Parameters:
      availableGrid - the grid that contains the available items
      selectionGrid - the grid that contains the selected items
    • TwinColGrid

      public TwinColGrid(Collection<T> options)
      Constructs a new TwinColGrid with the given options.
      Parameters:
      options - the options, cannot be null
  • Method Details

    • setCaption

      public void setCaption(String captionText)
      Sets the component caption.
      Parameters:
      captionText - the component caption.
    • getCaption

      public String getCaption()
      Returns the component caption.
      Returns:
      the component caption.
    • withOrientation

      public TwinColGrid<T> withOrientation(TwinColGrid.Orientation orientation)
      Sets orientation for TwinColGridComponent
      Parameters:
      orientation -
      Returns:
      this instance for method chaining.
    • getOrientation

      public TwinColGrid.Orientation getOrientation()
    • getAvailableGrid

      public Grid<T> getAvailableGrid()
      Return the grid that contains the available items.
    • getSelectionGrid

      public Grid<T> getSelectionGrid()
      Return the grid that contains the selected items.
    • forEachGrid

      public final void forEachGrid(Consumer<Grid<T>> consumer)
    • setItems

      public void setItems(Collection<T> items)
    • setItems

      public void setItems(Stream<T> items)
    • clearAll

      public void clearAll()
    • setDataProvider

      protected void setDataProvider(ListDataProvider<T> dataProvider)
    • withAvailableGridCaption

      public TwinColGrid<T> withAvailableGridCaption(String caption)
      Sets the text shown above the grid with the available items. null clears the caption.
      Parameters:
      caption - The text to show, null to clear
      Returns:
      this instance
    • withSelectionGridCaption

      public TwinColGrid<T> withSelectionGridCaption(String caption)
      Sets the text shown above the grid with the selected items. null clears the caption.
      Parameters:
      caption - The text to show, null to clear
      Returns:
      this instance
    • createFirstHeaderRow

      public TwinColGrid<T> createFirstHeaderRow(boolean value)
      Configure this component to create the first header row (for column header labels). If no column will have a header, this property must be set to false.

      When this property is true (default), the first column added through this component will append a header row, which will be the "default header row" (used by Column.setHeader). If no headers are set, then the default header row will be empty.

      When this property is false, then Column.setHeader will allocate a header row when called (which prevents an empty row if no headers are set, but also replaces the filter componentes).

      Parameters:
      value - whether the first header row will be created when a column is added.
      Returns:
      this instance
    • addColumn

      public TwinColumn<T> addColumn(ItemLabelGenerator<T> itemLabelGenerator)
      Adds a column to each grids. Both columns will use a TextRenderer and the value will be converted to a String by using the provided itemLabelGenerator.
      Parameters:
      itemLabelGenerator - the value provider
      Returns:
      the pair of columns
    • withoutAddAllButton

      public TwinColGrid<T> withoutAddAllButton()
    • withoutRemoveAllButton

      public TwinColGrid<T> withoutRemoveAllButton()
    • withoutAddButton

      public TwinColGrid<T> withoutAddButton()
    • withoutRemoveButton

      public TwinColGrid<T> withoutRemoveButton()
    • withSizeFull

      public TwinColGrid<T> withSizeFull()
    • withDragAndDropSupport

      public TwinColGrid<T> withDragAndDropSupport()
      Adds drag n drop support between grids.
      Returns:
      this instance
    • getAvailableGridCaption

      public String getAvailableGridCaption()
      Returns the text shown above the grid with the available items.
      Returns:
      The text shown or null if not set.
    • getSelectionGridCaption

      public String getSelectionGridCaption()
      Returns the text shown above the grid with the selected items.
      Returns:
      The text shown or null if not set.
    • setValue

      public void setValue(Set<T> value)
      Set value to grid
      Specified by:
      setValue in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Parameters:
      value - the value, cannot be null
    • getValue

      public Set<T> getValue()
      Returns the current value of this object which is an immutable set of the currently selected items.
      Specified by:
      getValue in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Returns:
      the current selection
    • addValueChangeListener

      public Registration addValueChangeListener(HasValue.ValueChangeListener<? super HasValue.ValueChangeEvent<Set<T>>> listener)
      Specified by:
      addValueChangeListener in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • isReadOnly

      public boolean isReadOnly()
      Specified by:
      isReadOnly in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Specified by:
      isReadOnly in interface HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Specified by:
      isRequiredIndicatorVisible in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Specified by:
      isRequiredIndicatorVisible in interface HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
      Specified by:
      setErrorMessage in interface HasValidation
    • getErrorMessage

      public String getErrorMessage()
      Specified by:
      getErrorMessage in interface HasValidation
    • setInvalid

      public void setInvalid(boolean invalid)
      Specified by:
      setInvalid in interface HasValidation
    • isInvalid

      public boolean isInvalid()
      Specified by:
      isInvalid in interface HasValidation
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Specified by:
      setReadOnly in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Specified by:
      setReadOnly in interface HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
      Specified by:
      setRequiredIndicatorVisible in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
      Specified by:
      setRequiredIndicatorVisible in interface HasValueAndElement<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • withSelectionGridReordering

      public TwinColGrid<T> withSelectionGridReordering()
      Allow drag-and-drop within the selection grid.
    • setSelectionGridReorderingAllowed

      public void setSelectionGridReorderingAllowed(boolean value)
      Configure whether drag-and-drop within the selection grid is allowed.
    • isSelectionGridReorderingAllowed

      public boolean isSelectionGridReorderingAllowed()
      Return whether drag-and-drop within the selection grid is allowed.
    • addFilterableColumn

      public FilterableTwinColumn<T> addFilterableColumn(ItemLabelGenerator<T> itemLabelGenerator)
    • addFilterableColumn

      public FilterableTwinColumn<T> addFilterableColumn(ItemLabelGenerator<T> itemLabelGenerator, SerializableFunction<T,String> filterableValue)
    • selectRowOnClick

      public TwinColGrid<T> selectRowOnClick()
    • asList

      public HasValue<? extends HasValue.ValueChangeEvent<List<T>>,List<T>> asList()
    • getEmptyValue

      public Set<T> getEmptyValue()
      Specified by:
      getEmptyValue in interface HasValue<HasValue.ValueChangeEvent<Set<T>>,Set<T>>
    • isAutoResize

      public boolean isAutoResize()
      Return whether autoResize is set or not.
    • setAutoResize

      public void setAutoResize(boolean autoResize)
      Sets whether component should update orientation on resize.
      Parameters:
      autoResize - if true, component will update orientation on resize
    • setMoveItemsByDoubleClick

      public void setMoveItemsByDoubleClick(boolean value)
      Sets whether a doubleclick event immediately moves an item to the other grid
      Parameters:
      value - if true, a a doubleclick event will immediately move an item to the other grid