Search in sources :

Example 6 with MessageDialog

use of org.openecard.gui.MessageDialog in project open-ecard by ecsec.

the class CardRecognitionImpl method waitForExclusiveCardAccess.

/**
 * This method tries to get exclusive card access until it is granted.
 * The waiting delay between the attempts is determined by the fibonacci numbers.
 *
 * @param slotHandle slot handle specifying the card to get exclusive access for
 * @param ifdName Name of the IFD in which the card is inserted
 */
private void waitForExclusiveCardAccess(byte[] slotHandle, String ifdName) throws RecognitionException {
    String resultMajor;
    int i = 2;
    do {
        // try to get exclusive card access for the recognition run
        BeginTransaction trans = new BeginTransaction();
        trans.setSlotHandle(slotHandle);
        BeginTransactionResponse resp = (BeginTransactionResponse) env.getDispatcher().safeDeliver(trans);
        resultMajor = resp.getResult().getResultMajor();
        if (!resultMajor.equals(ECardConstants.Major.OK)) {
            String resultMinor = resp.getResult().getResultMinor();
            if (ECardConstants.Minor.IFD.INVALID_SLOT_HANDLE.equals(resultMinor)) {
                throw new RecognitionException("Card is not available anymore.");
            }
            // could not get exclusive card access, wait in increasingly longer intervals and retry
            try {
                long waitInSeconds = fibonacci(i);
                i++;
                LOG.debug("Could not get exclusive card access. Trying again in {} seconds.", waitInSeconds);
                if (i == 6 && gui != null) {
                    MessageDialog dialog = gui.obtainMessageDialog();
                    String message = LANG.translationForKey("message", AppVersion.getName(), ifdName);
                    String title = LANG.translationForKey("error", ifdName);
                    dialog.showMessageDialog(message, title, DialogType.WARNING_MESSAGE);
                }
                Thread.sleep(1000 * waitInSeconds);
            } catch (InterruptedException e) {
            // ignore
            }
        }
    } while (!resultMajor.equals(ECardConstants.Major.OK));
}
Also used : BeginTransaction(iso.std.iso_iec._24727.tech.schema.BeginTransaction) MessageDialog(org.openecard.gui.MessageDialog) RecognitionException(org.openecard.common.interfaces.RecognitionException) BeginTransactionResponse(iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)

Example 7 with MessageDialog

use of org.openecard.gui.MessageDialog in project open-ecard by ecsec.

the class RunMessageBox method showMessage2.

@Test(enabled = !true)
public void showMessage2() {
    MessageDialog messageBox = uc.obtainMessageDialog();
    messageBox.showMessageDialog(MSG, TITLE, DialogType.ERROR_MESSAGE);
}
Also used : MessageDialog(org.openecard.gui.MessageDialog) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 8 with MessageDialog

use of org.openecard.gui.MessageDialog in project open-ecard by ecsec.

the class RunMessageBox method showConfirmDialog3.

@Test(enabled = !true)
public void showConfirmDialog3() {
    MessageDialog messageBox = uc.obtainMessageDialog();
    MessageDialogResult result = messageBox.showConfirmDialog("Press ok!", TITLE, OptionType.OK_CANCEL_OPTION, DialogType.ERROR_MESSAGE);
    Assert.assertEquals(result.getReturnValue(), ReturnType.OK);
}
Also used : MessageDialogResult(org.openecard.gui.message.MessageDialogResult) MessageDialog(org.openecard.gui.MessageDialog) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with MessageDialog

use of org.openecard.gui.MessageDialog in project open-ecard by ecsec.

the class RunMessageBox method showMessage.

@Test(enabled = !true)
public void showMessage() {
    MessageDialog messageBox = uc.obtainMessageDialog();
    messageBox.showMessageDialog(MSG, TITLE);
}
Also used : MessageDialog(org.openecard.gui.MessageDialog) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with MessageDialog

use of org.openecard.gui.MessageDialog in project open-ecard by ecsec.

the class RunMessageBox method showInputDialog.

@Test(enabled = !true)
public void showInputDialog() {
    MessageDialog messageBox = uc.obtainMessageDialog();
    MessageDialogResult result = messageBox.showInputDialog("Enter the text \"test\"!", TITLE);
    Assert.assertEquals(result.getReturnValue(), ReturnType.OK);
    Assert.assertEquals(result.getUserInput(), "test");
}
Also used : MessageDialogResult(org.openecard.gui.message.MessageDialogResult) MessageDialog(org.openecard.gui.MessageDialog) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

MessageDialog (org.openecard.gui.MessageDialog)13 BeforeTest (org.testng.annotations.BeforeTest)12 Test (org.testng.annotations.Test)12 MessageDialogResult (org.openecard.gui.message.MessageDialogResult)9 BeginTransaction (iso.std.iso_iec._24727.tech.schema.BeginTransaction)1 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)1 RecognitionException (org.openecard.common.interfaces.RecognitionException)1