title: How to use FutureTask<V>, waiting for ui event?
body: <p>I have an interface method which is supposed to return a Future object.</p>
  
  <pre><code>Future&lt;Result&gt; doSomething()
  </code></pre>
  
  <p>The implementation of this method shows some ui (javafx).
  One of the ui elements has a listener, that needs to be called in order to receive the actual result, I need.</p>
  
  <p>How do I achieve this?
  Is there a better solution?</p>
  
  <p>Here an example action I need to wait for:</p>
  
  <pre><code>// this is some framework method I cannot change
  @Override
  public Data execute(Data data) {
      Future&lt;Data&gt; dataFuture = handler.doSomething(data);
      // this should basically wait until the user clicked a button
      return dataFuture.get();
  }
  
  // handler implementation
  public Future&lt;Data&gt; doSomething(Data data) {
      // the question is how to implement this part, to be able to
      // return a future object
      Button button = new Button("Wait until click");
      // create thread that waits for the button click ?!????
      // modify incoming data object when the button was clicked
      // somehow create the Future object that's bound to the button click
      return future;
  }
  </code></pre>
  
  <p>This is what I want to achieve:</p>
  
  <ol>
  <li>my method doSomething shows a new scene(ui) with a button on it</li>
  <li>and returns immedeately the future object</li>
  <li>future.get() waits until the user pressed the button</li>
  </ol>
  
  <p>limitations: it has to be done with no extra library and on >=Java7</p>