ImportPrivateKeysSubmitAction extends MultiBitSubmitAction implements WalletBusyListener { @Override public void actionPerformed(ActionEvent event) { privateKeysBackupFile = null; if (abort()) { return; } String importFilename = importPrivateKeysPanel.getOutputFilename(); if (importFilename == null || importFilename.equals("")) { importPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "importPrivateKeysSubmitAction.privateKeysNothingToDo")); importPrivateKeysPanel.setMessageText2(" "); return; } if (super.bitcoinController.getModel().getActiveWallet() != null) { KeyCrypter keyCrypter = super.bitcoinController.getModel().getActiveWallet().getKeyCrypter(); if (keyCrypter != null && keyCrypter.getUnderstoodEncryptionType() == EncryptionType.ENCRYPTED_SCRYPT_AES) { if (walletPasswordField.getPassword() == null || walletPasswordField.getPassword().length == 0) { importPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "showExportPrivateKeysAction.youMustEnterTheWalletPassword")); importPrivateKeysPanel.setMessageText2(" "); return; } try { if (!super.bitcoinController.getModel().getActiveWallet() .checkPassword(CharBuffer.wrap(walletPasswordField.getPassword()))) { importPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "createNewReceivingAddressSubmitAction.passwordIsIncorrect")); importPrivateKeysPanel.setMessageText2(" "); return; } } catch (KeyCrypterException ede) { log.debug(ede.getClass().getCanonicalName() + " " + ede.getMessage()); importPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "createNewReceivingAddressSubmitAction.passwordIsIncorrect")); importPrivateKeysPanel.setMessageText2(" "); return; } } } setEnabled(false); log.debug("Importing from file '" + importFilename + "'."); File importFile = new File(importFilename); CharSequence passwordCharSequence = CharBuffer.wrap(passwordField.getPassword()); try { if (importPrivateKeysPanel.multiBitFileChooser.accept(importFile)) { log.debug("Regular MultiBit import."); PrivateKeysHandler privateKeysHandler = new PrivateKeysHandler(super.bitcoinController.getModel().getNetworkParameters()); importPrivateKeysPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Collection<PrivateKeyAndDate> privateKeyAndDateArray = privateKeysHandler.readInPrivateKeys(importFile, passwordCharSequence); changeWalletBusyAndImportInBackground(privateKeyAndDateArray, CharBuffer.wrap(walletPasswordField.getPassword())); importPrivateKeysPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { log.error("The wallet import file was not a recognised type."); } } catch (Exception e) { log.error(e.getClass().getName() + " " + e.getMessage()); setEnabled(true); importPrivateKeysPanel.setMessageText1(controller.getLocaliser().getString( "importPrivateKeysSubmitAction.privateKeysUnlockFailure", new Object[] { e.getMessage() })); importPrivateKeysPanel.setMessageText2(" "); } finally { importPrivateKeysPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } ImportPrivateKeysSubmitAction(BitcoinController bitcoinController, MultiBitFrame mainFrame, ImportPrivateKeysPanel importPrivateKeysPanel,
            ImageIcon icon, JPasswordField walletPasswordField, JPasswordField passwordField1, JPasswordField passwordField2); @Override void actionPerformed(ActionEvent event); void setPerformReplay(boolean performReplay); @Override void walletBusyChange(boolean newWalletIsBusy);  }
@Test public void testNoWalletSelected() throws Exception { final CreateControllers.Controllers controllers = CreateControllers.createControllers(); BitcoinController controller = controllers.bitcoinController; assertTrue("There was an active wallet when there should not be", controller.getModel().thereIsNoActiveWallet()); FontSizer.INSTANCE.initialise(controller); ImportPrivateKeysPanel importPrivateKeysPanel = new ImportPrivateKeysPanel(controller, null); ImportPrivateKeysSubmitAction importPrivateKeysSubmitAction = importPrivateKeysPanel.getImportPrivateKeysSubmitAction(); assertNotNull("importPrivateKeysSubmitAction was not created successfully", importPrivateKeysSubmitAction); importPrivateKeysSubmitAction.actionPerformed(null); Object[] messages = MessageManager.INSTANCE.getMessages().toArray(); assertTrue("There were no messages but there should have been", messages != null && messages.length > 0); assertEquals("Wrong message after receive bitcoin confirm with no active wallet", ResetTransactionsSubmitActionTest.EXPECTED_NO_WALLET_IS_SELECTED, ((Message)messages[messages.length - 1]).getText()); }