public BlockingExecutor() { overallProgressBinding = Bindings.createDoubleBinding( () -> { if (scheduledTasks.isEmpty()) return 1d; double progress = 0d; for (TimeTask<?> task : scheduledTasks) { if (task.isDone()) progress += 1d; else if (task.getProgress() > 0) progress += task.getProgress(); } return progress / (double) scheduledTasks.size(); }, scheduledTasks, currentTaskProperty); isIdleBinding = Bindings.createBooleanBinding( () -> overallProgressBinding.get() == 1d, overallProgressBinding); currentTaskProperty.addListener( (__, ___, task) -> { if (task.isDone()) next(); else { task.exceptionProperty() .addListener( (____, _____, exception) -> new ErrorDialog(ConExpFX.instance.primaryStage, exception).showAndWait()); task.setOnCancelled(____ -> next()); task.setOnFailed(____ -> next()); task.setOnSucceeded(____ -> next()); tpe.submit(task); } }); }
public final void execute(final TimeTask<?> task) { Platform2.runOnFXThread( () -> { synchronized (scheduledTasks) { if (isIdleBinding.get()) currentTaskProperty.setValue(task); scheduledTasks.add(task); task.progressProperty() .addListener( (__, ___, ____) -> { overallProgressBinding.invalidate(); datasetProgressBindings.values().forEach(DoubleBinding::invalidate); }); task.stateProperty() .addListener( (__, ___, ____) -> { overallProgressBinding.invalidate(); datasetProgressBindings.values().forEach(DoubleBinding::invalidate); }); } }); }
public final DoubleBinding datasetProgressBinding(final Dataset dataset) { if (datasetProgressBindings.containsKey(dataset)) return datasetProgressBindings.get(dataset); final DoubleBinding datasetProgressBinding = Bindings.createDoubleBinding( () -> { if (scheduledTasks.isEmpty()) return 1d; double progress = 0d; double tasks = 0d; for (TimeTask<?> task : scheduledTasks) if (task.getDataset() != null && task.getDataset().equals(dataset)) { if (task.isDone()) progress += 1d; else if (task.getProgress() > 0) progress += task.getProgress(); tasks++; } if (tasks > 0) return progress / tasks; return 1d; }, scheduledTasks, currentTaskProperty); datasetProgressBindings.put(dataset, datasetProgressBinding); return datasetProgressBinding; }