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());
}
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);
}
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;
}
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);
}
}
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);
}
});
}
}
Aggregations