0

I have a TreeTableView subclass. I want to use a SelectionModel for this in which certain methods throw exceptions if an attempt to use them is made (see this question for reason why).

Rather unfortunately, class TreeTableView.TreeTableViewSelectionModel is abstract. My "start" at trying to deliver such a concrete class is this:

class MyTreeTableSelectionModel extends TreeTableView.TreeTableViewSelectionModel {
    final static String PROHIBITED_METHOD_MSG = 'Method is prohibited due to problems with internal JavaFX NPEs. Use select( row, column ) instead.'
    TreeTableView.TreeTableViewSelectionModel suppliedConcreteModel

    MyTreeTableSelectionModel(TreeTableView treeTableView) {
        super( treeTableView )
        assert treeTableView.selectionModel != null
        suppliedConcreteModel = treeTableView.selectionModel
    }

    @Override
    ObservableList<TreeTablePosition> getSelectedCells() {
        suppliedConcreteModel.getSelectedCells()
    }

    @Override
    boolean isSelected(int row, TableColumnBase column) {
        suppliedConcreteModel.isSelected( row, column )
    }

    @Override
    void select(int row, TableColumnBase column) {
        suppliedConcreteModel.select( row, column )
    }

    @Override
    void clearAndSelect(int row, TableColumnBase column) {
        suppliedConcreteModel.clearAndSelect( row, column )
    }

    @Override
    void clearSelection(int row, TableColumnBase column) {
        suppliedConcreteModel.clearSelection( row, column )
    }

    @Override
    void selectLeftCell() {
        suppliedConcreteModel.selectLeftCell()
    }

    @Override
    void selectRightCell() {
        suppliedConcreteModel.selectRightCell()
    }

    @Override
    void selectAboveCell() {
        suppliedConcreteModel.selectAboveCell()
    }

    @Override
    void selectBelowCell() {
        suppliedConcreteModel.selectBelowCell()
    }

    @Override
    void select( int row ){
        throw new Exception( PROHIBITED_METHOD_MSG )
    }

    @Override
    void selectFirst(){
        throw new Exception( PROHIBITED_METHOD_MSG )
    }

    @Override
    void selectLast(){
        throw new Exception( PROHIBITED_METHOD_MSG )
    }
}

... this (obviously) doesn't work as implemented: the implemented overridden abstract methods forward calls to the encapsulated object suppliedConcreteModel, but the other methods (of which there are maybe 50 or so), and all properties and fields, are forwarded to the concrete object of class MyTreeTableSelectionModel.

Is there any Groovy way of forwarding all methods, fields and properties to the encapsulated object? I had a look at this question, but I don't fully understand it, or whether it is actually relevant, and I suspect there is a more "orthodox" Groovy way of doing what I want.

mike rodent
  • 14,126
  • 11
  • 103
  • 157

0 Answers0