use of org.jabref.gui.externalfiles.FileDownloadTask in project jabref by JabRef.
the class LinkedFilesEditorViewModel method addFromURL.
private void addFromURL(URL url) {
URLDownload urlDownload = new URLDownload(url);
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
Path destination = constructSuggestedPath(suggestedType, fileDirectories);
LinkedFileViewModel temporaryDownloadFile = new LinkedFileViewModel(new LinkedFile("", url, suggestedTypeName));
files.add(temporaryDownloadFile);
FileDownloadTask downloadTask = new FileDownloadTask(url, destination);
temporaryDownloadFile.downloadProgressProperty().bind(downloadTask.progressProperty());
downloadTask.setOnSucceeded(event -> {
files.remove(temporaryDownloadFile);
LinkedFile newLinkedFile = fromFile(destination, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile));
});
downloadTask.setOnFailed(event -> dialogService.showErrorDialogAndWait("", downloadTask.getException()));
taskExecutor.execute(downloadTask);
}
Aggregations