示例#1
0
    public void setTask(Task<?> task) {
      if (_task != null) {
        _task.cancel();
        _animation.stop();
        visibleProperty().unbind();
        log.info("Task Canceled");
      }

      _task = task;
      if (_task != null) {
        visibleProperty().bind(task.runningProperty());
        _task
            .runningProperty()
            .addListener(
                o -> {
                  SimpleBooleanProperty running = (SimpleBooleanProperty) o;
                  if (running.get()) {
                    _animation.play();
                  } else {
                    _animation.stop();
                  }
                });

        task.setOnFailed(
            e -> {
              log.error(_task.getMessage());
              setTask(null);
            });
      }
    }
示例#2
0
  /**
   * Do import for the specified type and file name.
   *
   * @param modelType the model type
   * @param fileName the file name
   */
  public void doImport(InformationModelType modelType, final String fileName) {
    Preconditions.checkNotNull(modelType);
    Preconditions.checkNotNull(fileName);

    // Make sure in application thread.
    FxUtils.checkFxUserThread();

    // Update UI.
    modelTypeLabel.setText(modelType.getDisplayName());
    fileNameLabel.setText(fileName);

    // Instantiate appropriate importer class.
    ImportHandler importHandler = null;
    switch (modelType) {
      case CEM:
        importHandler = new CEMImporter();
        break;
      case HeD:
        importHandler = new HeDImporter();
        break;
      case FHIM:
        importHandler = new FHIMImporter();
        break;
      default:
        throw new UnsupportedOperationException(
            modelType.getDisplayName() + " import not yet supported in ISAAC.");
    }

    // Do work in background.
    Task<InformationModel> task = new ImporterTask(fileName, importHandler);

    // Bind cursor to task state.
    ObjectBinding<Cursor> cursorBinding =
        Bindings.when(task.runningProperty()).then(Cursor.WAIT).otherwise(Cursor.DEFAULT);
    this.getScene().cursorProperty().bind(cursorBinding);

    Thread t = new Thread(task, "Importer_" + modelType);
    t.setDaemon(true);
    t.start();
  }