Beispiel #1
0
 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);
         }
       });
 }
Beispiel #2
0
 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;
 }