0

I have to create my own implementation of CellFactory for TreeTableView. My cell can contain two types of values - String and Enums. Based on this type I want to have another implementation of displaying this item.

The easy way is verifying the type in Cell#updateItem and split in this method.

But how to separate this on the CellFactory level? Pseudocode to better describe.

public class EditableDataObjectValueCellFactory implements Callback<TreeTableColumn<ITableEntry, ?>,
    TreeTableCell<ITableEntry, ?>> {

  @Override
  public TreeTableCell<ITableEntry, ?> call( TreeTableColumn<ITableEntry, ?> aColumn ) {
     if(aColumn.getRenderedRow().getValue() instanceOf Enum) 
        return new EnumTreeCell();
     return new BasicTreeCell();
  }
}
Adrian Klimczak
  • 133
  • 1
  • 10
  • 1
    not possible (and that's good :) - a cell is created once and re-used: at that time none of the collaborators has any knowlegde of future content – kleopatra Feb 25 '21 at 13:00
  • 1
    You can create two view classes, e.g. `EnumView` and `BasicView`, then choose which one to set as the `graphic` of the cell in `updateItem`. This should help keep the code clean, which I assume is what you're worried about. – Slaw Feb 25 '21 at 22:57
  • @Slaw - thx for this suggestion. :) – Adrian Klimczak Mar 01 '21 at 11:03

0 Answers0