Hello
i am not able to make this to work. i include the following dependency in the project but it shows blank screen
Hello
i am not able to make this to work. i include the following dependency in the project but it shows blank screen
Are you using correct version, 3-series is for Vaadin 18 or newer, 2-series for Vaadin 14 and 1-series for Vaadin 8?
Hello Tatu
Thank you so much for replying. Let me tell you in detail. I am using Version 3.0.0 only.
<dependency>
<groupId>org.vaadin.filesystemdataprovider</groupId>
<artifactId>filesystemdataprovider</artifactId>
<version>3.0.0</version>
</dependency>
Also i used exactly same example you have given in the code snippt. See below
String path = System.getProperty("user.home");
File rootFile = new File(path);
FilesystemData root = new FilesystemData(rootFile, false);
FilesystemDataProvider fileSystem = new FilesystemDataProvider(root);
TreeGrid<File> tree = new TreeGrid<>();
tree.setDataProvider(fileSystem);
When i add the Tree into a Panel, it shows blank screen. I am not able to use the Tree Class from the systemprovider as its protected i guess so i used TreeGrid
My vaadin version is 21.0.0
The version is correct.
You need to add columns to your TreeGrid
public GridView() {
File rootFile = new File("C:/Users/Tatu/Documents");
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.addColumn(file -> {
String perms = "";
if (file.canExecute()) perms+="E";
if (file.canRead()) perms+="R";
if (file.canWrite()) perms+="W";
return perms;
}).setHeader("Permissions");
tree.addSelectionListener(event -> {
File file = event.getFirstSelectedItem().get();
Date date = new Date(file.lastModified());
if (!file.isDirectory()) {
Notification.show(file.getPath()+", "+date+", "+file.length());
} else {
Notification.show(file.getPath()+", "+date);
}
});
tree.setWidth("750px");
tree.setHeight("500px");
setSizeFull();
this.setAlignItems(Alignment.CENTER);
this.setJustifyContentMode(JustifyContentMode.CENTER);
add(tree);
}
Thank you so much Tatu. For your help. Really appreciate it. Its now displaying the tree. My question is, the tree grid item select listener is not getting invoked for all selections. Its allowing to choose some while for others the event itself is not getting triggered. For files it works almost all the time. But for some directories , even though i try to select it, selection is not working
I want that the event is triggered each time use selects anything in the tree including all files and directories
So ideally the notification should come each time i select something but why i am not able to select some and not others
File rootFile = new File(System.getProperty("user.home"));
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.addSelectionListener(event -> {
File file = event.getFirstSelectedItem().get();
Notification.show(file.getPath());
});
tree.setWidth("750px");
tree.setHeight("500px");
setSizeFull();