Allow selection of only leaf node of tree[table]

Since tree hierarchy is not available for Lookup, I am trying to use Tree as lookup field but I only want to allow selection of leaf nodes. How can I achieve this. I believe similar solution should work for TreeTable also.


I think the only way to select only leaf nodes is to check whether the entity contains children or not. For instance, subscribe to SelectionEvent and check selected entities. If an entity has children remove it and reselect items:

private TreeTable<Directory> directoriesTable;

private TreeTableItems<Directory> tableItems;

public void onAfterShow(AfterShowEvent event) {
    tableItems = (TreeTableItems<Directory>) directoriesTable.getItems();

public void onDirectoriesTableSelection(Table.SelectionEvent<Directory> event) {
    Set<Directory> reselect = null;
    for (Directory directory : event.getSelected()) {
        if (tableItems.hasChildren(directory.getId())) {
            if (reselect == null) {
                reselect = new HashSet<>(event.getSelected());
    if (reselect != null) {