TreeGrid: Dynamic Image according to expansion state, Selection of nodes wi

I am currently evaluating the Vaadin Tree Grid.
I would like it to behave as a file explorer of an OS like windows:

  • All nodes should be selectable
  • Images of the Folders should change when they are opened

My Code so far:

	private TreeGrid<TreeItem> createTree() {
		TreeGrid<TreeItem> grid = new TreeGrid<>();
		grid.addComponentHierarchyColumn((ValueProvider<TreeItem, Component>)
				treeItem -> createNameComponent(grid, treeItem));
		grid.addSelectionListener(event -> showDetails(new SqlSelectAction()));
				// GridVariant.LUMO_ROW_STRIPES; alternate rows

		HierarchicalDataProvider<TreeItem, Void> dataProvider =
				new AbstractBackEndHierarchicalDataProvider<TreeItem, Void>() {

					public int getChildCount(HierarchicalQuery<TreeItem, Void> query) {
						return treeService.getChildCount(query.getParent());

					public boolean hasChildren(TreeItem item) {
						return treeService.hasChildren(item);

					protected Stream<TreeItem> fetchChildrenFromBackEnd(
							HierarchicalQuery<TreeItem, Void> query) {
						return treeService.fetchChildren(query.getParent()).stream();
		return grid;

	private Component createNameComponent(TreeGrid<TreeItem> grid, TreeItem treeItem) {
		ListItem item = new ListItem(treeItem.getName());
		return item;

This gives me the tree grid with icons.
Unfortunately, the Method createNameComponent is called only on item creation, therefore the expanded property is always false.
Is there any way to force the grid to refresh? This would also be a requirement if the name of an item would change.

Another problem is the selection of items with children.
Leaf items can be selected without any problems, others just toggle expand/collapse state on click, but do no set a selection.
Is it possible to change this behaviour?

If have studied the same use case and build an add-on for typical case of selecting a single file. This add-on contains FileSelect and FtpSelect components, that are based on TreeGrid

The source code is here:

Thanks for your hints.

What helped me in the end was:

  • Listeners on expand and collapse that also set the selection on the expanded/collapsed item
  • grid.getDataProvider().refreshAll() / grid.getDataProvider().refresh([item]