Search in sources :

Example 11 with Account

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

the class BudgetTableController method buildAccountTreeTable.

/**
     * Constructs the tree table.
     *
     * @see Stage#showAndWait() for need to push {@code handleEditAccountGoals(account)} to the platform thread
     */
private void buildAccountTreeTable() {
    // empty column header is needed to match other table columns
    final TreeTableColumn<Account, String> headerColumn = new TreeTableColumn<>("");
    final TreeTableColumn<Account, Account> nameColumn = new TreeTableColumn<>(resources.getString("Column.Account"));
    nameColumn.setCellFactory(param -> new AccountTreeTableCell());
    nameColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getValue()));
    nameColumn.setOnEditStart(event -> {
        final Account account = event.getRowValue().getValue();
        if (account != null && !account.isPlaceHolder()) {
            if (Platform.isFxApplicationThread()) {
                handleEditAccountGoals(account);
            } else {
                Platform.runLater(() -> handleEditAccountGoals(account));
            }
        }
    });
    nameColumn.setEditable(true);
    headerColumn.getColumns().add(nameColumn);
    accountTreeView.getColumns().add(headerColumn);
    headerColumn.minWidthProperty().bind(accountTreeView.widthProperty());
    headerColumn.maxWidthProperty().bind(accountTreeView.widthProperty());
}
Also used : Account(jgnash.engine.Account) TreeTableColumn(javafx.scene.control.TreeTableColumn)

Example 12 with Account

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

the class BudgetTableController method calculateMinPeriodColumnWidth.

private double calculateMinPeriodColumnWidth() {
    double max = 0;
    for (final BudgetPeriodDescriptor descriptor : budgetResultsModel.getDescriptorList()) {
        for (final Account account : expandedAccountList) {
            max = Math.max(max, calculateMinColumnWidth(descriptor, account));
        }
    }
    max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Budgeted") + BORDER_MARGIN, null));
    max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Actual") + BORDER_MARGIN, null));
    max = Math.max(max, JavaFXUtils.getDisplayedTextWidth(resources.getString("Column.Remaining") + BORDER_MARGIN, null));
    return Math.ceil(max);
}
Also used : Account(jgnash.engine.Account) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor)

Example 13 with Account

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

the class AbstractTransactionEntryDialog method getBalanceAt.

private BigDecimal getBalanceAt(final TransactionEntry transactionEntry) {
    BigDecimal balance = BigDecimal.ZERO;
    final Account account = this.account.get();
    if (account != null) {
        final int index = sortedList.indexOf(transactionEntry);
        for (int i = 0; i <= index; i++) {
            balance = balance.add(sortedList.get(i).getAmount(account));
        }
    }
    return balance;
}
Also used : Account(jgnash.engine.Account) BigDecimal(java.math.BigDecimal)

Example 14 with Account

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

the class AccountTools method createAccount.

static void createAccount(final Account account) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Account parentAccount = account;
    final ResourceBundle rb = ResourceUtils.getBundle();
    if (parentAccount == null) {
        parentAccount = engine.getRootAccount();
        if (parentAccount == null) {
            // no root account at all, file was closed
            return;
        }
    }
    AccountDialog dlg = new AccountDialog();
    dlg.setParentAccount(parentAccount);
    dlg.setAccountType(parentAccount.getAccountType());
    dlg.setTitle(rb.getString("Title.NewAccount"));
    dlg.setVisible(true);
    if (dlg.returnStatus()) {
        CurrencyNode currency = dlg.getCurrency();
        AccountType accType = dlg.getAccountType();
        if (currency == null) {
            currency = engine.getRootAccount().getCurrencyNode();
            Logger.getLogger(AccountTools.class.getName()).warning("Forcing use of the default currency");
        }
        Account newAccount = new Account(accType, currency);
        if (accType.getAccountGroup() == AccountGroup.INVEST) {
            Collection<SecurityNode> collection = dlg.getAccountSecurities();
            collection.forEach(newAccount::addSecurity);
        }
        newAccount.setName(dlg.getAccountName());
        newAccount.setAccountCode(dlg.getAccountCode());
        newAccount.setAccountNumber(dlg.getAccountNumber());
        newAccount.setBankId(dlg.getBankId());
        newAccount.setDescription(dlg.getAccountDescription());
        newAccount.setNotes(dlg.getAccountNotes());
        newAccount.setLocked(dlg.isAccountLocked());
        newAccount.setPlaceHolder(dlg.isAccountPlaceholder());
        newAccount.setVisible(dlg.isAccountVisible());
        newAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
        engine.addAccount(dlg.getParentAccount(), newAccount);
    }
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) ResourceBundle(java.util.ResourceBundle) AccountType(jgnash.engine.AccountType) Engine(jgnash.engine.Engine)

Example 15 with Account

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

the class AccountTreeModel method loadChildren.

private synchronized void loadChildren(final DefaultMutableTreeNode parentNode) {
    synchronized (lock) {
        final Account parent = (Account) parentNode.getUserObject();
        parent.getChildren(Comparators.getAccountByCode()).stream().filter(this::isAccountVisible).forEach(child -> {
            final DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
            insertNodeInto(childNode, parentNode, parentNode.getChildCount());
            if (child.getChildCount() > 0) {
                loadChildren(childNode);
            }
        });
    }
}
Also used : RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

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