Hello Tatu Thanks for all your help so far. I have few questions for you w

Hello Tatu

Thanks for all your help so far. I have few questions for you which will really help us to launch a global solution

Firstly this is the code we have got to list all the drives in our computers in tree format. I have also used Multi selection mode so that user can select the folders and files which needs to be backed up. The problem is sometime when a folder has large number of items , the UI gets really struck when i select the parent folder. Is there a solution for the same. I just need the file paths from the tree to process by backend job of backup. But why the selection of folders with so many files take this much time.

This is my code

List<File> rootFiles = new ArrayList<>();
File[] drives = File.listRoots();
if (drives != null && drives.length > 0) {
	for (File aDrive : drives) {
		rootFiles.add(aDrive);
	}
}

if(rootFiles == null || rootFiles.size() == 0){
	return null;
}

File rootBase = rootFiles.get(0);
FilesystemData root = new FilesystemData(rootBase, false);
rootFiles.remove(0);
FilesystemDataProvider fileSystem = new FilesystemDataProvider(root);
for(File aRoot: rootFiles) {
	fileSystem.getTreeData().addRootItems(aRoot);
}

fileSystem.refreshAll();
TreeGrid<File> tree = new RecursiveSelectTreeGrid<>();
tree.setDataProvider(fileSystem);
tree.addHierarchyColumn(file -> file.getName()).setHeader("Name");
tree.setSelectionMode(Grid.SelectionMode.MULTI);
tree.setWidth("750px");
tree.setHeight("500px");
setSizeFull();
return tree;

Secondly i want colorful icons for my tree elements or items. How can i acheive it?

Thirdly, the code above does not display the root folders names i.e. C:. D:. Just a arrow to expand it. Below is a screenshot


Hello. Filesystemdataprovider.Tree has an addHierarchyColumn method that takes an icon provider, and there is a filetype icon helper class in the add-on:

tree.addHierarchyColumn(File::getName,file -> FileTypeResolver.getIcon(file),file -> getFileDescription(file));

If you are using other kind of grid, you may follow the approach at https://cookbook.vaadin.com/tree-grid-with-icons (which is similar to the implementation in the addon)

As for the empty labels, note that getName returns an empty string when file is a Windows drive (new File("C:").getName()) so you’ll need to use getPath in that case (but getPath returns the absolute path, so you’ll want to call it only for root files)

 f -> f.getParent()==null?f.getPath():f.getName()