Search in sources :

Example 1 with BackgroundTask

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();
    }
}
Also used : StepActionResult(org.openecard.gui.executor.StepActionResult) BackgroundTask(org.openecard.gui.executor.BackgroundTask)

Example 2 with BackgroundTask

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();
}
Also used : ExecutionEngine(org.openecard.gui.executor.ExecutionEngine) UserConsentDescription(org.openecard.gui.definition.UserConsentDescription) Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step) UserConsent(org.openecard.gui.UserConsent) StepActionResult(org.openecard.gui.executor.StepActionResult) BackgroundTask(org.openecard.gui.executor.BackgroundTask) Test(org.testng.annotations.Test)

Aggregations

BackgroundTask (org.openecard.gui.executor.BackgroundTask)2 StepActionResult (org.openecard.gui.executor.StepActionResult)2 UserConsent (org.openecard.gui.UserConsent)1 Step (org.openecard.gui.definition.Step)1 Text (org.openecard.gui.definition.Text)1 UserConsentDescription (org.openecard.gui.definition.UserConsentDescription)1 ExecutionEngine (org.openecard.gui.executor.ExecutionEngine)1 Test (org.testng.annotations.Test)1