I am creating the UI for my application which shares a core module with versions for other platforms. In JavaFX, I'm trying to use Task
s to do things in the background, but I can't figure out how to update the Task state.
This is what I'm trying to do. The user
variable holds an instance of a class which performs xmlrpc requests:
public Task<Integer> doLogin()
{
return new Task<Integer>() {
@Override
protected Integer call()
{
user.login();
if (!user.getIsAuthorized())
{
// set the state to FAILED
}
else
{
// set the state to SUCCEDED
}
user.remember();
}
};
}
In my UI Thread I want to be able to do something like this to update my graph UI:
loginTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent t) {
// perform an UI update here depending on the state t
}
});
How am I supposed to set the state? There is nothing that does that in the Task API.