title: Callback and extractors for JavaFX ObservableList
body: <p>Here is the code:</p>
  
  <pre><code>package sample;
  
  import javafx.beans.Observable;
  import javafx.beans.property.IntegerProperty;
  import javafx.beans.property.SimpleIntegerProperty;
  import javafx.collections.FXCollections;
  import javafx.collections.ListChangeListener;
  import javafx.collections.ObservableList;
  import javafx.util.Callback;
  
  import java.util.List;
  
  /**
   * Created by IDEA on 28/07/15.
   */
  public class ListUpdateTest {
      public static void main(String[] args) {
          Callback&lt;IntegerProperty, Observable[]&gt; extractor = (IntegerProperty p) -&gt; {
              System.out.println("The extractor is called.");
              Observable[] res = new Observable[]{p};
              System.out.println("Result from extractor: " + res);
              return res;
          };
          ObservableList&lt;IntegerProperty&gt; list = FXCollections.observableArrayList(extractor);
          System.out.printf("Before adding");
          IntegerProperty p1 = new SimpleIntegerProperty(10);
          IntegerProperty p2 = new SimpleIntegerProperty(20);
          list.addAll(p1, p2);
          System.out.println("After adding");
          list.addListener(new ListChangeListener&lt;IntegerProperty&gt;() {
              @Override
              public void onChanged(Change&lt;? extends IntegerProperty&gt; c) {
                  System.out.println("List is " + c.getList());
                  while (c.next()) {
                      if (c.wasUpdated()) {
                          System.out.println("An update is detected.");
                          int start = c.getFrom();
                          int end = c.getTo();
                          System.out.println(
                                  String.format("Updated range: %d to %d",
                                          start, end)
                          );
                          List&lt;? extends IntegerProperty&gt; updatedElementsList;
                          updatedElementsList = c.getList().subList(start, end);
                          System.out.println("Updated elements: " + updatedElementsList);
                      }
                  }
              }
          });
          p1.set(100);
      }
  }
  </code></pre>
  
  <p>What is <code>extractor</code> for and why do we need it here?</p>