Search in sources :

Example 11 with RootAccount

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();
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) JFileChooser(javax.swing.JFileChooser) SwingWorker(javax.swing.SwingWorker) Preferences(java.util.prefs.Preferences) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File)

Example 12 with RootAccount

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));
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) TreePath(javax.swing.tree.TreePath) Engine(jgnash.engine.Engine)

Aggregations

RootAccount (jgnash.engine.RootAccount)12 Account (jgnash.engine.Account)5 Engine (jgnash.engine.Engine)5 IOException (java.io.IOException)2 ResourceBundle (java.util.ResourceBundle)2 ExecutionException (java.util.concurrent.ExecutionException)2 SwingWorker (javax.swing.SwingWorker)2 CurrencyNode (jgnash.engine.CurrencyNode)2 ChartEntity (org.jfree.chart.entity.ChartEntity)2 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)2 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Set (java.util.Set)1 Preferences (java.util.prefs.Preferences)1 TreeItem (javafx.scene.control.TreeItem)1 JButton (javax.swing.JButton)1