Class UpdatingTableCell<T,E>

Type Parameters:
T - the type of items in the table
E - the type of value wrapped in the ObservableValue
All Implemented Interfaces:
Cell<T>, MappingTableCell<T,ObservableValue<E>>, TableCell<T>, Styleable, EventTarget

public class UpdatingTableCell<T,E> extends SimpleTableCell<T,ObservableValue<E>>
Extension of SimpleTableCell which is intended to be used with models that make use of JavaFX properties.

The extractor is expected to extract a property of type ObservableValue.

The StringConverter is intended to convert the value of the observable, ObservableValue.getValue(), to a String. By default, this returns "null" if the observable is null, otherwise uses Objects.toString(Object) on the observable's value.

Also note that this cell keeps a reference to the extracted ObservableValue thus avoiding continuous calls to the extractor. The reference is disposed by dispose()

As this works on JavaFX's properties, the cells is capable of automatically updating itself when the property changes.
  • Constructor Details

  • Method Details

    • getProperty

      protected ObservableValue<E> getProperty()
      Returns the ObservableValue extracted by the extractor function. If it is null it first attempts at extracting it, then stores the reference, so that subsequent calls will just return the already extracted one.

      Also, when an observable is extracted a listener is attached to it to automatically call invalidate() when its value changes, using When.onInvalidated(ObservableValue).
    • updateItem

      public void updateItem(T item)
      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.

      When the item is updated the ObservableValue changes too. First listener attached to the old one is disposed with When.disposeFor(ObservableValue), then the local reference to the old one is set to null.

      Afterwards the item is updated and invalidate() called.

      Specified by:
      updateItem in interface Cell<T>
      Overrides:
      updateItem in class SimpleTableCell<T,ObservableValue<E>>
    • invalidate

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

      Gets the ObservableValue with getProperty(), then the converter function converts is to a string and the label's text is updated.
      Specified by:
      invalidate in interface TableCell<T>
      Overrides:
      invalidate in class SimpleTableCell<T,ObservableValue<E>>
    • dispose

      public void dispose()
      Calls When.disposeFor(ObservableValue) on the stored observable, getProperty(), then sets it to null.