use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class ProfitLossTextReport method getBalances.
private List<BigDecimal> getBalances(final Account a, final AccountType type) {
final List<BigDecimal> balances = new ArrayList<>();
for (final Account child : a.getChildren(Comparators.getAccountByCode())) {
if ((child.getTransactionCount() > 0) && type == child.getAccountType()) {
final BigDecimal acctBal = balanceConverter.apply(child.getAccountType(), child.getBalance(startDate, endDate, baseCommodity));
// output account name and balance
reportText.add(formatAccountName(child.getName()) + " " + formatDecimal(acctBal));
balances.add(acctBal);
}
if (child.isParent()) {
balances.addAll(getBalances(child, type));
}
}
return balances;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountsViewController method getTreeTableRow.
private TreeTableRow<Account> getTreeTableRow() {
final TreeTableRow<Account> treeTableRow = new TreeTableRow<>();
treeTableRow.setOnMouseClicked(event -> {
if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) {
if (selectedAccount.get() != null && !selectedAccount.get().isPlaceHolder()) {
Platform.runLater(AccountsViewController.this::handleZoomAccountAction);
}
}
});
final ContextMenu rowMenu = new ContextMenu();
final MenuItem newItem = new MenuItem(resources.getString("Menu.New.Name"));
newItem.setOnAction(event -> handleNewAccountAction());
final MenuItem modifyItem = new MenuItem(resources.getString("Menu.Modify.Name"));
modifyItem.setOnAction(event -> handleModifyAccountAction());
final MenuItem deleteItem = new MenuItem(resources.getString("Menu.Delete.Name"));
deleteItem.setOnAction(event -> handleDeleteAccountAction());
deleteItem.disableProperty().bind(deleteButton.disabledProperty());
final MenuItem visibilityMenuItem = new MenuItem(resources.getString("Menu.Hide.Name"));
visibilityMenuItem.setOnAction(event -> handleModifyAccountAction());
visibilityMenuItem.setOnAction(event -> new Thread(() -> {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
engine.toggleAccountVisibility(selectedAccount.get());
}
}).start());
final MenuItem reconcileItem = new MenuItem(resources.getString("Menu.Reconcile.Name"));
reconcileItem.setOnAction(event -> handleReconcileAction());
rowMenu.getItems().addAll(newItem, modifyItem, deleteItem, new SeparatorMenuItem(), visibilityMenuItem, new SeparatorMenuItem(), reconcileItem);
rowMenu.setOnShowing(event -> visibilityMenuItem.setText(selectedAccount.get().isVisible() ? resources.getString("Menu.Hide.Name") : resources.getString("Menu.Show.Name")));
treeTableRow.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(treeTableRow.itemProperty())).then(rowMenu).otherwise((ContextMenu) null));
return treeTableRow;
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountsViewController method loadAccountTree.
private void loadAccountTree() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
final RootAccount r = engine.getRootAccount();
final TreeItem<Account> root = new TreeItem<>(r);
root.setExpanded(true);
treeTableView.setRoot(root);
loadChildren(root);
} else {
treeTableView.setRoot(null);
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountsViewController method updateButtonStates.
private void updateButtonStates() {
JavaFXUtils.runLater(() -> {
final Account account = selectedAccount.get();
if (account != null) {
final int count = account.getTransactionCount();
deleteButton.setDisable(count > 0 || account.getChildCount() > 0);
reconcileButton.setDisable(count <= 0);
zoomButton.setDisable(account.isPlaceHolder());
} else {
deleteButton.setDisable(true);
reconcileButton.setDisable(true);
zoomButton.setDisable(true);
}
});
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountsViewController method initializeTreeTableView.
@SuppressWarnings("unchecked")
private void initializeTreeTableView() {
// don't show the root
treeTableView.setShowRoot(false);
// required for editable columns
treeTableView.setEditable(true);
treeTableView.setTableMenuButtonVisible(true);
treeTableView.setRowFactory(ttv -> getTreeTableRow());
// force resize policy for better default appearance
treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
// hide the horizontal scrollbar and prevent ghosting
treeTableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
final TreeTableColumn<Account, String> nameColumn = new TreeTableColumn<>(resources.getString("Column.Account"));
nameColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getName()));
final TreeTableColumn<Account, Integer> entriesColumn = new TreeTableColumn<>(resources.getString("Column.Entries"));
entriesColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getTransactionCount()).asObject());
final TreeTableColumn<Account, BigDecimal> balanceColumn = new TreeTableColumn<>(resources.getString("Column.Balance"));
balanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getTreeBalance())));
balanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
final TreeTableColumn<Account, BigDecimal> reconciledBalanceColumn = new TreeTableColumn<>(resources.getString("Column.ReconciledBalance"));
reconciledBalanceColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(param.getValue().getValue().getAccountType(), param.getValue().getValue().getReconciledTreeBalance())));
reconciledBalanceColumn.setCellFactory(cell -> new AccountCommodityFormatTreeTableCell());
final TreeTableColumn<Account, String> currencyColumn = new TreeTableColumn<>(resources.getString("Column.Currency"));
currencyColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getCurrencyNode().getSymbol()));
final TreeTableColumn<Account, String> typeColumn = new TreeTableColumn<>(resources.getString("Column.Type"));
typeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue().getAccountType().toString()));
final TreeTableColumn<Account, Integer> codeColumn = new TreeTableColumn<>(resources.getString("Column.Code"));
codeColumn.setEditable(true);
codeColumn.setCellValueFactory(param -> new SimpleIntegerProperty(param.getValue().getValue().getAccountCode()).asObject());
codeColumn.setCellFactory(param -> new IntegerTreeTableCell<>());
codeColumn.setOnEditCommit(event -> updateAccountCode(event.getRowValue().getValue(), event.getNewValue()));
treeTableView.getColumns().addAll(nameColumn, codeColumn, entriesColumn, balanceColumn, reconciledBalanceColumn, currencyColumn, typeColumn);
restoreColumnVisibility();
installListeners();
}
Aggregations