@Inject
@WithAttributes(label = "Select Files")
private UIInputMany<FileResource<?>> files;
@Inject
@WithAttributes(label = "Select dir")
private UIInput<DirectoryResource> dir;
UIOutput out;
@Override
public void initializeUI(UIBuilder uiBuilder) throws Exception {
dir.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChanged(ValueChangeEvent event) {
List<FileResource<?>> fileList = (List<FileResource<?>>) files.getValue();
DirectoryResource selectedDir = (DirectoryResource) event.getNewValue();
for (Resource<?> resource : selectedDir.listResources()) {
FileResource<?> fileToAdd = resource.reify(FileResource.class);
if(fileToAdd != null && fileToAdd.exists() && !fileList.contains(fileToAdd)){
fileList.add(fileToAdd);
}
}
for (FileResource<?> fileResource : ((List<FileResource<?>>) files.getValue())) {
out.out().println(fileResource.getName());
}
}
});
uiBuilder.add(dir).add(files);
}