use of org.vaadin.filesystemdataprovider.FileSelect in project ArchCNL by Mari-Wie.
the class FileSelectionComponent method createFileSelect.
@SuppressWarnings("unchecked")
private FileSelect createFileSelect(File rootFile) {
FileSelect newFileSelect = new FileSelect(rootFile, "adoc");
newFileSelect.getChildren().filter(TreeGrid.class::isInstance).map(TreeGrid.class::cast).forEach(treeGrid -> treeGrid.expand(treeGrid.getTreeData().getRootItems()));
newFileSelect.addValueChangeListener(event -> {
Optional<File> file = newFileSelect.getOptionalValue();
if (selectDirectory) {
handleDirectoryChange(file);
} else {
if (file.isPresent() && file.get().isFile()) {
selectedFile = file;
dialog.setConfirmButtonEnabled(true);
fileSelectErrorLabel.setVisible(false);
} else {
selectedFile = Optional.empty();
showErrorMessage("Please select a file.");
}
}
});
// or an empty directory is selected
if (selectDirectory) {
for (Component child : newFileSelect.getChildren().collect(Collectors.toList())) {
if (child instanceof TreeGrid) {
TreeGrid<File> grid = (TreeGrid<File>) child;
grid.addExpandListener(event -> {
File file = event.getItems().iterator().next();
handleDirectoryChange(Optional.of(file));
});
}
}
}
newFileSelect.setWidth("500px");
newFileSelect.setHeight("500px");
return newFileSelect;
}
Aggregations