title: JavaFX: Load data task to combine with progress bar
body: <p>For my JavaFX application I'd like to implement a load Task, to combine it with a progress bar.</p>
  
  <p>I have a Presentation Model which looks like this:</p>
  
  <pre><code>public class PresentationModel {
  
      private final ObservableList&lt;Country&gt; countries = FXCollections.observableArrayList();
      // Wrap the ObservableList in a FilteredList (initially display all data)
      private final FilteredList&lt;Country&gt; filteredCountries = new FilteredList&lt;&gt;(countries, c -&gt; true);
      // Wrap the FilteredList in a SortedList (because FilteredList is unmodifiable)
      private final SortedList&lt;Country&gt; sortedCountries = new SortedList&lt;&gt;(filteredCountries);
  
      private Task&lt;ObservableList&lt;Country&gt;&gt; task = new LoadTask();
  
      public PresentationModel() {
          new Thread(task).start();
      }
  }
  </code></pre>
  
  <p>And a Task which loads the data:</p>
  
  <pre><code>public class LoadTask extends Task&lt;ObservableList&lt;Country&gt;&gt; {
  
      @Override
      protected ObservableList&lt;Country&gt; call() throws Exception {
          for (int i = 0; i &lt; 1000; i++) {
              updateProgress(i, 1000);
              Thread.sleep(5);
          }
  
          ObservableList&lt;Country&gt; countries = FXCollections.observableArrayList();
          countries.addAll(readFromFile());
  
          return countries;
      }
  }
  </code></pre>
  
  <p>This allows me to bind the <code>ProgressIndicator pi</code> to the progress property of the task:</p>
  
  <pre><code>pi.progressProperty().bind(model.getTask().progressProperty());
  </code></pre>
  
  <p>Now I need to have the loaded data from the task in the presentation model so that I can add the elements to a table: <code>table = new TableView&lt;&gt;(model.getSortedCountries());</code></p>
  
  <p>How can I access the data in the presentation model from the load task?</p>