0

I have a requirement wherein i need to display a tree containing users home folder hierarchy including files and folders. I have been trying to use Vaadin TreeGrid and FileSystemDataProvider for this purpose

I am using Vaadin 21.0.0 and using this dependency

<dependency>
    <groupId>org.vaadin.filesystemdataprovider</groupId>
    <artifactId>filesystemdataprovider</artifactId>
    <version>3.0.0</version>
</dependency>

The Code for the same is as follows

String path = System.getProperty("user.home");
File rootFile = new File(path);
FilesystemData root = new FilesystemData(rootFile, false);
FilesystemDataProvider fileSystem = new FilesystemDataProvider(root);
tree.setDataProvider(fileSystem);
add(tree)

However the treegrid is displaying blank(Not displaying the tree structure) on running the program. Need your help guys on this what i might be doing wrong

Anna Koskinen
  • 1,362
  • 3
  • 22

2 Answers2

3

You need to configure your TreeGrid to have columns, for example:

public GridView() {
    File rootFile = new File(path);
    FilesystemData root = new FilesystemData(rootFile, false);
    FilesystemDataProvider fileSystem = new FilesystemDataProvider(root);
    TreeGrid<File> tree = new TreeGrid<>();
    tree.setDataProvider(fileSystem);     
    tree.addHierarchyColumn(file -> file.getName()).setHeader("Name");
    tree.addColumn(file -> file.length()).setHeader("Size");
    tree.setWidth("750px");
    tree.setHeight("500px");
    setSizeFull();
    setAlignItems(Alignment.CENTER);
    setJustifyContentMode(JustifyContentMode.CENTER);
    add(tree);
}
Tatu Lund
  • 9,949
  • 1
  • 12
  • 26
0

If you didn't give a bean class to the Grid/TreeGrid's constructor, you have to add a column explicitly through one of the addColumn or addHierarchyColumn methods. When a columns are not added this way, the Grid would be rendered as blank on the page.