use of org.openecard.gui.executor.BackgroundTask in project open-ecard by ecsec.
the class StepFrame method runBackgroundTask.
private void runBackgroundTask() {
final BackgroundTask task = step.getBackgroundTask();
if (task != null) {
bgThread = new Thread(new Runnable() {
@Override
public void run() {
try {
StepActionResult result = task.call();
LOG.debug("Background thread terminated before the GUI.");
forceResult(result);
} catch (InterruptedException ex) {
LOG.debug("Background task has been terminated from the Swing GUI.", ex);
} catch (Exception ex) {
LOG.error("Background task terminated with an exception.", ex);
}
}
}, "Swing-GUI-BG-Task");
bgThread.setDaemon(true);
bgThread.start();
}
}
use of org.openecard.gui.executor.BackgroundTask in project open-ecard by ecsec.
the class BackgroundTaskTest method testWait.
@Test()
public void testWait() {
UserConsent uc = new SwingUserConsent(new SwingDialogWrapper());
UserConsentDescription ucd = new UserConsentDescription("Test background wait");
Step s = new Step("Wait Step");
s.getInputInfoUnits().add(new Text("Please wait for the background task to complete ..."));
s.setBackgroundTask(new BackgroundTask() {
@Override
public StepActionResult call() throws Exception {
// first wait
Thread.sleep(1000);
// then repeat ;-)
Step replacement = new Step("Replacement Step");
replacement.getInputInfoUnits().add(new Text("Super cool it works."));
replacement.setInstantReturn(true);
return new StepActionResult(StepActionResultStatus.REPEAT, replacement);
}
});
ucd.getSteps().add(s);
ExecutionEngine e = new ExecutionEngine(uc.obtainNavigator(ucd));
e.process();
}
Aggregations