I have an interface method which is supposed to return a Future object.
Future<Result> doSomething()
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.
How do I achieve this? Is there a better solution?
Here an example action I need to wait for:
// this is some framework method I cannot change
@Override
public Data execute(Data data) {
Future<Data> dataFuture = handler.doSomething(data);
// this should basically wait until the user clicked a button
return dataFuture.get();
}
// handler implementation
public Future<Data> 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;
}
This is what I want to achieve:
- my method doSomething shows a new scene(ui) with a button on it
- and returns immedeately the future object
- future.get() waits until the user pressed the button
limitations: it has to be done with no extra library and on >=Java7