Class SimpleTableCell<T,E>

Type Parameters:
T - the type of items in the table
E - the type of property extracted from the T objects
All Implemented Interfaces:
Cell<T>, MappingTableCell<T,E>, TableCell<T>, Styleable, EventTarget
Direct Known Subclasses:
UpdatingTableCell

public class SimpleTableCell<T,E> extends HBox implements MappingTableCell<T,E>
Basic implementation of MappingTableCell. This is intended to be used with models that do not use JavaFX's properties.

Extends HBox and has a Label to represent the item as text.

If the item change, the cell cannot automatically detect it, but you can use VirtualTable.updateTable(boolean) to programmatically update it.

This implementation has the following properties:

- Holds the column this cell is relative to, columnProperty()

- Holds the row containing this cell, rowProperty()

- Holds the item visualized by the cell, itemProperty()

- Holds the column index this cell is relative to, indexProperty()

Since the control will visualize tabular data we generally want to extract a certain property from a certain object of the model. The cell specifies a Function called "extractor" that does exactly this.

 
 // Lets suppose this cell will represent the name of a User
 // The extractor function will look like this...
 user -> user.getName();
 
 

This also specifies a way to convert the extracted value to a String that will be used as the cell's text, StringConverter. By default, this is set to use Objects.toString(Object).

The cells text is updated by the invalidate() method.

Last but not least. Note that this cell implementation makes use of the TableColumn.inViewportProperty() when the VirtualTable.columnsLayoutModeProperty() is set to ColumnsLayoutMode.VARIABLE. If the column is not visible (therefore this cell is not visible either) it hides itself automatically.
  • Property Details

  • Field Details

    • label

      protected final Label label
  • Constructor Details

  • Method Details

    • init

      protected void init()
    • getNode

      public Node getNode()
      Description copied from interface: Cell
      Returns the cell's node. The ideal way to implement a cell would be to extend a JavaFX's pane/region and override this method to return "this".
      Specified by:
      getNode in interface Cell<T>
    • updateItem

      public void updateItem(T item)
      Description copied from interface: Cell
      Automatically called by the virtualized control.

      This method must be implemented to correctly update the Cell's content on scroll.

      Note: if the Cell's content is a Node this method should also re-set the Cell's children because (quoting from JavaFX doc) 'A node may occur at most once anywhere in the scene graph' and it's possible that a Node may be removed from a Cell to be the content of another Cell.

      Specified by:
      updateItem in interface Cell<T>
    • updateIndex

      public void updateIndex(int index)
      Description copied from interface: Cell
      Automatically called by the virtualized control.

      Cells are dumb, they have no logic, no state. This method allow cells implementations to keep track of a cell's index.

      Default implementation is empty.

      Specified by:
      updateIndex in interface Cell<T>
    • updateColumn

      public void updateColumn(TableColumn<T,? extends TableCell<T>> column)
      Description copied from interface: TableCell
      This is a way for cells to obtain and perhaps hold the reference of the column it is associated to.
      Specified by:
      updateColumn in interface TableCell<T>
    • updateRow

      public void updateRow(int rIndex, DefaultTableRow<T> row)
      Description copied from interface: TableCell
      This is a way for cells to obtain and perhaps hold the reference of the row which contains the cell. The given rIndex is the index of the given row.

      Note that the row may be the same for different calls, but the rIndex may differ.
      Specified by:
      updateRow in interface TableCell<T>
    • invalidate

      public void invalidate()
      This is a way for cells to specify the behavior for when any of its properties are updated.

      By default this is only invoked after updateItem(Object) has also been called. This is responsible for extracting the value E from the current itemProperty(), converting it to a String with the specified StringConverter and then updating the label's text
      Specified by:
      invalidate in interface TableCell<T>
    • getColumn

      public TableColumn<T,? extends TableCell<T>> getColumn()
      Gets the value of the column property.
      Property description:
      Holds the reference to the TableColumn this cells is associated to.
      Returns:
      the value of the column property
      See Also:
    • columnProperty

      public ReadOnlyObjectProperty<TableColumn<T,? extends TableCell<T>>> columnProperty()
      Holds the reference to the TableColumn this cells is associated to.
      Returns:
      the column property
      See Also:
    • setColumn

      protected void setColumn(TableColumn<T,? extends TableCell<T>> column)
      Sets the value of the column property.
      Property description:
      Holds the reference to the TableColumn this cells is associated to.
      Parameters:
      column - the value for the column property
      See Also:
    • getRow

      public TableRow<T> getRow()
      Gets the value of the row property.
      Property description:
      Specifies the TableRow which contains this cell.
      Returns:
      the value of the row property
      See Also:
    • rowProperty

      public ReadOnlyObjectProperty<TableRow<T>> rowProperty()
      Specifies the TableRow which contains this cell.
      Returns:
      the row property
      See Also:
    • setRow

      protected void setRow(DefaultTableRow<T> row)
      Sets the value of the row property.
      Property description:
      Specifies the TableRow which contains this cell.
      Parameters:
      row - the value for the row property
      See Also:
    • getItem

      public T getItem()
      Gets the value of the item property.
      Property description:
      Specifies the item represented by this cell.
      Returns:
      the value of the item property
      See Also:
    • itemProperty

      public ObjectProperty<T> itemProperty()
      Specifies the item represented by this cell.
      Returns:
      the item property
      See Also:
    • setItem

      public void setItem(T item)
      Sets the value of the item property.
      Property description:
      Specifies the item represented by this cell.
      Parameters:
      item - the value for the item property
      See Also:
    • getIndex

      public int getIndex()
      Gets the value of the index property.
      Property description:
      Specifies the index of the column this cell is associated to.
      Returns:
      the value of the index property
      See Also:
    • indexProperty

      public IntegerProperty indexProperty()
      Specifies the index of the column this cell is associated to.
      Returns:
      the index property
      See Also:
    • setIndex

      public void setIndex(int index)
      Sets the value of the index property.
      Property description:
      Specifies the index of the column this cell is associated to.
      Parameters:
      index - the value for the index property
      See Also:
    • getExtractor

      public Function<T,E> getExtractor()
      Specified by:
      getExtractor in interface MappingTableCell<T,E>
      Returns:
      the function used to extract a property E from an item T
    • setExtractor

      public void setExtractor(Function<T,E> extractor)
      Description copied from interface: MappingTableCell
      Sets the function used to extract a property E from an item T
      Specified by:
      setExtractor in interface MappingTableCell<T,E>
    • getConverter

      public StringConverter<E> getConverter()
      Specified by:
      getConverter in interface MappingTableCell<T,E>
      Returns:
      the StringConverter used to convert an extracted value E to a string
    • setConverter

      public void setConverter(StringConverter<E> converter)
      Description copied from interface: MappingTableCell
      Sets the StringConverter used to convert an extracted value E to a string
      Specified by:
      setConverter in interface MappingTableCell<T,E>