1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
private void moveFiles(File[] files, String newPath) {
ProgressForm pForm = new ProgressForm();
i18n = I18nFactory.getI18n(logfly.Logfly.class.getClass());
Task<Boolean> task = new Task<Boolean>() {
@Override
public Boolean call() throws InterruptedException {
int lengthFiles = files.length;
int idx = 0;
boolean res = false;
for (File f : files) {
try {
File dest = new File(newPath+myConfig.getOsSeparator()+f.getName());
Files.move(f.toPath(), dest.toPath(),StandardCopyOption.REPLACE_EXISTING);
idx++;
updateProgress(idx, lengthFiles);
} catch (IOException e) {
updateProgress(lengthFiles, lengthFiles);
}
}
res = true;
updateProgress(lengthFiles, lengthFiles);
return res ;
}
};
pForm.activateProgressBar(task);
task.setOnSucceeded(event -> {
pForm.getDialogStage().close();
alertbox aInfo = new alertbox();
aInfo.alertInfo(i18n.tr(Integer.toString(files.length)+" fichiers transférés"));
if (task.getValue()) {
// On change pathdb
myConfig.setPathDb(newPath+myConfig.getOsSeparator());
myConfig.setFullPathDb(newPath+myConfig.getOsSeparator()+myConfig.getDbName());
// On relance l'affichage
rootController.changeCarnetView();
}
});
task.setOnFailed(event -> {
pForm.getDialogStage().close();
alertbox aError = new alertbox();
aError.alertError(i18n.tr("Erreur pendant le transfert de fichiers"));
});
pForm.getDialogStage().show();
Thread thread = new Thread(task);
thread.start();
} |
Partager