2
votes

Could anyone explain me one thing? Is it possible to use Vaadin TreeTable with LazyQueryContainer? I've alredy tried but it doesn't work. Actually, there is no any lazy loading. The method loadItems of org.vaadin.addons.lazyquerycontainer.Query is called until all data are loaded. For instanse, if batch size for the container = 100 and I have 500 rows then this method will be called 5 times. Here is my code:

public class LazyHierarchicalQueryContainer extends LazyQueryContainer implements Container.Hierarchical {

    private String parentProperty = "parent";

    public LazyHierarchicalQueryContainer(QueryFactory queryFactory, Object idPropertyId, int batchSize,
        boolean compositeItems) {
        super(queryFactory, idPropertyId, batchSize, compositeItems);
    }

    public LazyHierarchicalQueryContainer(QueryDefinition queryDefinition, QueryFactory queryFactory) {
        super(queryDefinition, queryFactory);
    }

    public LazyHierarchicalQueryContainer(QueryView queryView) {
        super(queryView);
    }

    public String getParentProperty() {
        return parentProperty;
    }

    public void setParentProperty(String parentProperty) {
        this.parentProperty = parentProperty;
    }

    @Override
    public Collection<?> getChildren(Object itemId) {
        return Collections.emptyList();
    }

    @Override
    public Object getParent(Object itemId) {
        return null;
    }

    @Override
    public Collection<?> rootItemIds() {
        ArrayList arrayList = new ArrayList();
        for (Object workItem : getItemIds()) {
            if (isRoot(workItem)) {
                arrayList.add(workItem);
            }
        }
        return arrayList;
    }

    @Override
    public boolean setParent(Object itemId, Object newParentId) throws UnsupportedOperationException {
        if (getItem(newParentId) != null) {
            getItem(itemId).getItemProperty(getParentProperty()).setValue(newParentId);
        } else {
            getItem(itemId).getItemProperty(getParentProperty()).setValue(null);
        }
        return true;
    }

    @Override
    public boolean areChildrenAllowed(Object itemId) {
        return true;
    }

    @Override
    public boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed) throws UnsupportedOperationException {
        return false;
    }

    @Override
    public boolean isRoot(Object itemId) {
        return getItem(itemId).getItemProperty(parentProperty).getValue() == null;
    }

    @Override
    public boolean hasChildren(Object itemId) {
        return false;
    }
}

Thanks in advance.

1
the exact problem is that the query isnt working OR because it´s loading ALL the data instead of lazy loading it?Marcelo Bezerra bovino

1 Answers

0
votes

It seems your implementation of rootItemIds() loads all items to filter out the root items. This may cause the whole container to be read in the first go.