Search in sources :

Example 16 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class AccountListComboBox method messagePosted.

@Override
public void messagePosted(final Message event) {
    EventQueue.invokeLater(() -> {
        if (event.getEvent() == ChannelEvent.FILE_CLOSING) {
            MessageBus.getInstance().unregisterListener(AccountListComboBox.this, MessageChannel.ACCOUNT, MessageChannel.SYSTEM);
            ((AbstractModel) getModel()).messagePosted(event);
        } else {
            Account account = getSelectedAccount();
            ((AbstractModel) getModel()).messagePosted(event);
            if (account != null && event.getEvent() != ChannelEvent.ACCOUNT_REMOVE && !account.equals(event.getObject(MessageProperty.ACCOUNT))) {
                setSelectedAccount(account);
            } else {
                if (getModel().getSize() > 0) {
                    setSelectedIndex(0);
                }
            }
        }
    });
}
Also used : Account(jgnash.engine.Account)

Example 17 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class AccountSecurityComboBox method messagePosted.

@Override
public void messagePosted(final Message event) {
    final Account a = event.getObject(MessageProperty.ACCOUNT);
    if (account.equals(a)) {
        final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
        EventQueue.invokeLater(() -> {
            switch(event.getEvent()) {
                case ACCOUNT_REMOVE:
                    MessageBus.getInstance().unregisterListener(AccountSecurityComboBox.this, MessageChannel.ACCOUNT, MessageChannel.COMMODITY);
                    model.removeAllElements();
                    account = null;
                    break;
                case ACCOUNT_SECURITY_ADD:
                    model.addElement(node);
                    break;
                case SECURITY_REMOVE:
                case ACCOUNT_SECURITY_REMOVE:
                    final CommodityNode commodityNode = getSelectedNode();
                    model.removeElement(node);
                    if (commodityNode != null && node != null) {
                        if (commodityNode.equals(node)) {
                            setSelectedItem(null);
                        }
                    }
                    break;
                case SECURITY_MODIFY:
                    updateNode(node);
                    break;
                default:
            }
        });
    }
}
Also used : Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) CommodityNode(jgnash.engine.CommodityNode)

Example 18 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class ImportTwo method getSettings.

@Override
@SuppressWarnings("unchecked")
public void getSettings(final Map<Enum<?>, Object> map) {
    ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportDialog.Settings.BANK);
    if (bank != null) {
        List<ImportTransaction> list = bank.getTransactions();
        Account account = (Account) map.get(ImportDialog.Settings.ACCOUNT);
        // set to sane account assuming it's going to be a single entry
        for (ImportTransaction t : list) {
            t.setAccount(account);
            t.setState(ImportState.NEW);
        }
        // match up any pre-existing transactions
        GenericImport.matchTransactions(list, account);
        // classify the transactions
        BayesImportClassifier.classifyTransactions(list, account.getSortedTransactionList(), account);
        table.setTransactions(list);
        refreshInfo();
    }
}
Also used : Account(jgnash.engine.Account) ImportBank(jgnash.convert.imports.ImportBank) ImportTransaction(jgnash.convert.imports.ImportTransaction)

Example 19 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class NewFileUtility method buildNewFile.

public static void buildNewFile(final String fileName, final DataStoreType dataStoreType, final char[] password, final CurrencyNode currencyNode, final Collection<CurrencyNode> currencyNodes, final Collection<RootAccount> rootAccountCollection) throws IOException {
    final ResourceBundle resources = ResourceUtils.getBundle();
    // have to close the engine first
    EngineFactory.closeEngine(EngineFactory.DEFAULT);
    // try to delete any existing database
    if (Files.exists(Paths.get(fileName))) {
        if (!EngineFactory.deleteDatabase(fileName)) {
            throw new IOException(ResourceUtils.getString("Message.Error.DeleteExistingFile", fileName));
        }
    }
    // create the directory if needed
    Files.createDirectories(Paths.get(fileName).getParent());
    final Engine e = EngineFactory.bootLocalEngine(fileName, EngineFactory.DEFAULT, password, dataStoreType);
    CurrencyNode defaultCurrency = currencyNode;
    // creation of a duplicate currency
    if (e.getDefaultCurrency().matches(defaultCurrency)) {
        defaultCurrency = e.getDefaultCurrency();
    }
    // make sure a duplicate default is not added
    for (final CurrencyNode node : currencyNodes) {
        if (!node.matches(defaultCurrency)) {
            e.addCurrency(node);
        }
    }
    if (!defaultCurrency.equals(e.getDefaultCurrency())) {
        e.setDefaultCurrency(defaultCurrency);
    }
    if (!rootAccountCollection.isEmpty()) {
        // import account sets
        for (final RootAccount root : rootAccountCollection) {
            AccountTreeXMLFactory.importAccountTree(e, root);
        }
    } else {
        // none selected, create a very basic account set
        final RootAccount root = e.getRootAccount();
        final Account bank = new Account(AccountType.BANK, defaultCurrency);
        bank.setDescription(resources.getString("Name.BankAccounts"));
        bank.setName(resources.getString("Name.BankAccounts"));
        e.addAccount(root, bank);
        final Account income = new Account(AccountType.INCOME, defaultCurrency);
        income.setDescription(resources.getString("Name.IncomeAccounts"));
        income.setName(resources.getString("Name.IncomeAccounts"));
        e.addAccount(root, income);
        final Account expense = new Account(AccountType.EXPENSE, defaultCurrency);
        expense.setDescription(resources.getString("Name.ExpenseAccounts"));
        expense.setName(resources.getString("Name.ExpenseAccounts"));
        e.addAccount(root, expense);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) RootAccount(jgnash.engine.RootAccount) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) Engine(jgnash.engine.Engine)

Example 20 with Account

use of jgnash.engine.Account in project jgnash by ccavanaugh.

the class ApiTest method testMove.

@Test
public void testMove() {
    Account test = new Account(AccountType.ASSET, e.getDefaultCurrency());
    test.setName("Test");
    assertTrue(e.addAccount(e.getRootAccount(), test));
    assertTrue(e.getRootAccount().contains(test));
    assertTrue(e.moveAccount(test, usdBankAccount));
    assertFalse(e.getRootAccount().contains(test));
    assertTrue(usdBankAccount.contains(test));
}
Also used : Account(jgnash.engine.Account) AbstractEngineTest(jgnash.engine.AbstractEngineTest) Test(org.junit.Test)

Aggregations

Account (jgnash.engine.Account)132 Engine (jgnash.engine.Engine)44 BigDecimal (java.math.BigDecimal)40 CurrencyNode (jgnash.engine.CurrencyNode)28 Transaction (jgnash.engine.Transaction)27 ArrayList (java.util.ArrayList)22 LocalDate (java.time.LocalDate)21 ResourceBundle (java.util.ResourceBundle)19 RootAccount (jgnash.engine.RootAccount)18 List (java.util.List)15 AccountType (jgnash.engine.AccountType)15 NumberFormat (java.text.NumberFormat)14 FXML (javafx.fxml.FXML)13 EngineFactory (jgnash.engine.EngineFactory)13 Objects (java.util.Objects)12 Collections (java.util.Collections)11 InvestmentTransaction (jgnash.engine.InvestmentTransaction)11 Tooltip (javafx.scene.control.Tooltip)10 Preferences (java.util.prefs.Preferences)9 Platform (javafx.application.Platform)9