use of jgnash.engine.RootAccount in project jgnash by ccavanaugh.
the class ImportAccountsAction method importAccounts.
private static void importAccounts() {
final Preferences pref = Preferences.userNodeForPackage(ImportAccountsAction.class);
final JFileChooser chooser = new JFileChooser(pref.get(ACCOUNTS_IMPORT_DIR, null));
chooser.addChoosableFileFilter(new FileNameExtensionFilter(ResourceUtils.getString("Label.XMLFiles") + " (*.xml)", "xml"));
chooser.setMultiSelectionEnabled(false);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
final File file = chooser.getSelectedFile();
pref.put(ACCOUNTS_IMPORT_DIR, chooser.getCurrentDirectory().getAbsolutePath());
final class Import extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
UIApplication.getFrame().displayWaitMessage(ResourceUtils.getString("Message.ImportWait"));
RootAccount root = AccountTreeXMLFactory.loadAccountTree(file.toPath());
if (root != null) {
AccountTreeXMLFactory.mergeAccountTree(EngineFactory.getEngine(EngineFactory.DEFAULT), root);
}
return null;
}
@Override
protected void done() {
UIApplication.getFrame().stopWaitMessage();
// Close and reopen, otherwise UI may link to some stale currency information
EngineFactory.closeEngine(EngineFactory.DEFAULT);
OpenAction.openLastAction();
}
}
new Import().execute();
}
}
use of jgnash.engine.RootAccount in project jgnash by ccavanaugh.
the class AccountListTreePane method scrollToTop.
private void scrollToTop() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
RootAccount rootAccount = engine.getRootAccount();
if (rootAccount != null) {
// scroll to the top
tree.scrollPathToVisible(new TreePath(rootAccount));
}
}
Aggregations