use of jgnash.ui.components.OpenDatabaseDialog in project jgnash by ccavanaugh.
the class OpenAction method openAction.
public static void openAction() {
final class BootEngine extends SwingWorker<Void, Void> {
private final OpenDatabaseDialog dialog;
private BootEngine(final OpenDatabaseDialog dialog) {
this.dialog = dialog;
}
@Override
protected Void doInBackground() throws Exception {
final ResourceBundle rb = ResourceUtils.getBundle();
UIApplication.getFrame().displayWaitMessage(rb.getString("Message.PleaseWait"));
EngineFactory.closeEngine(EngineFactory.DEFAULT);
Engine engine = null;
final char[] password = dialog.getPassword();
if (dialog.isRemote()) {
final String host = dialog.getHost();
final int port = dialog.getPort();
engine = EngineFactory.bootClientEngine(host, port, password, EngineFactory.DEFAULT);
if (engine == null) {
remoteConnectionFailed = true;
}
} else {
try {
if (FileUtils.isFileLocked(dialog.getDatabasePath())) {
StaticUIMethods.displayError(ResourceUtils.getString("Message.FileIsLocked"));
} else if (checkAndBackupOldVersion(dialog.getDatabasePath(), password)) {
engine = EngineFactory.bootLocalEngine(dialog.getDatabasePath(), EngineFactory.DEFAULT, password);
}
} catch (final Exception e) {
StaticUIMethods.displayError(e.getLocalizedMessage());
}
}
if (engine != null) {
// prime the engine
engine.getRootAccount();
}
return null;
}
@Override
protected void done() {
logger.info("openAction() done");
UIApplication.getFrame().stopWaitMessage();
if (remoteConnectionFailed) {
StaticUIMethods.displayError(ResourceUtils.getString("Message.Error.ServerConnection"));
}
}
}
EventQueue.invokeLater(() -> {
final OpenDatabaseDialog d = new OpenDatabaseDialog(UIApplication.getFrame());
d.setDatabasePath(EngineFactory.getLastDatabase());
d.setPort(EngineFactory.getLastPort());
d.setHost(EngineFactory.getLastHost());
d.setRemote(EngineFactory.getLastRemote());
d.setVisible(true);
if (d.getResult()) {
pool.execute(new BootEngine(d));
}
});
}
Aggregations