Filtering for TreeTable

Hi @All,

In have a TreeTable which is populated in a Hiearchichal way, via a custom wrapper and I want to perform filtering for my TreeTable.

My custom wrapper “AllocationOrderTreeMapper” :

[code]
public class AllocationOrderTreeMapper {
private AllocationOrder allocationOrder;
private Allocation allocation;
private VerticalLayout progress;
private FormLayout productView;
private AllocationItem allocationItem;
private Date lastModification;

 public AllocationOrderTreeMapper(AllocationOrder allocationOrder, ObjectX x , ObjectY y){
    //init and setting attributes values here ... etc
 }

//other stuff ...

}
[/code]Given a list “AllocationOrder” (my business entity) with which am setting the “AllocationOrderTreeMapper” attributes as follows :

[code]
private void fillHierarchicalContainer(List allocationOrders) {
allocationOrders.forEach(nextAllocationOrder → {

        AllocationOrderTreeMapper parent = new AllocationOrderTreeMapper(nextAllocationOrder, null, null);
        allocationOrderTreeTable.addItem(parent);
        allocationOrderTreeTable.setCollapsed(parent, true);

        if (nextAllocationOrder.getAllocations().isEmpty()) {
            allocationOrderTreeTable.setChildrenAllowed(parent, false);
        } else {
            nextAllocationOrder.getAllocations().forEach(nextAllocation -> {
                AllocationOrderTreeMapper child = new AllocationOrderTreeMapper(null, nextAllocation, null);
                allocationOrderTreeTable.addItem(child);
                allocationOrderTreeTable.setParent(child, parent);
                allocationOrderTreeTable.setCollapsed(child, false);
                allocationOrderTreeTable.setChildrenAllowed(child, true);
                if (nextAllocation.getAllocationItems().isEmpty()) {
                    allocationOrderTreeTable.setChildrenAllowed(child, false);
                } else {
                    nextAllocation.getAllocationItems().forEach(item -> {
                        AllocationOrderTreeMapper childItem = new AllocationOrderTreeMapper(null, null, item);
                        allocationOrderTreeTable.addItem(childItem);
                        allocationOrderTreeTable.setParent(childItem, child);
                        allocationOrderTreeTable.setCollapsed(childItem, false);
                        allocationOrderTreeTable.setChildrenAllowed(childItem, false);
                    });
                }
            });
        }
        allocationOrderTreeTable.setPageLength(determinePageLength(allocationOrders));
    });
}

[/code]A bean item container for the " AllocationOrderTreeMapper" bean :

BeanItemContainer<AllocationOrderTreeMapper> allocationOrderContainer = new BeanItemContainer<AllocationOrderTreeMapper>(
                    AllocationOrderTreeMapper.class);
//add of nested properties ... etc

then a “TreeTable” with the “allocationOrderContainer” as datasource :

TreeTable allocationOrderTreeTable = new TreeTable();
allocationOrderTreeTable.setContainerDataSource(allocationOrderContainer);
//set column headers, visble columns & other ui stuff ...

Well, I have a text field for filtering the table entries :

orderReferenceSearch = new TextField() { { setInputPrompt("Search by Order Reference"); addTextChangeListener(e -> { HierarchicalContainer f = (HierarchicalContainer) allocationOrderTreeTable .getContainerDataSource(); // this ??????? f.removeAllContainerFilters(); f.addContainerFilter( new SimpleStringFilter("allocationOrder.orderReference", e.getText(), true, false)); }); } }; but the following the text chnage listener a “ClassCastException” is thrown :

Caused by: java.lang.ClassCastException: com.vaadin.data.util.HierarchicalContainerOrderedWrapper cannot be cast to com.vaadin.data.util.HierarchicalContainer Am new to Vaadin, so any help would be deeply appreciated