Search in sources :

Example 6 with RecTransaction

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

the class ReconcileDialogController method configureTableView.

private void configureTableView(final TableView<RecTransaction> tableView, final TableViewManager<RecTransaction> tableViewManager) {
    tableView.setTableMenuButtonVisible(false);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    final TableColumn<RecTransaction, String> reconciledColumn = new TableColumn<>(resources.getString("Column.Clr"));
    reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciledState().toString()));
    tableView.getColumns().add(reconciledColumn);
    final TableColumn<RecTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDate()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<RecTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<RecTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<RecTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), param.getValue().getAmount(account))));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(CommodityFormat.getShortNumberFormat(account.getCurrencyNode())));
    tableView.getColumns().add(amountColumn);
    // hide the horizontal scrollbar
    tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
    tableViewManager.setColumnFormatFactory(param -> {
        if (param == amountColumn && account != null) {
            return CommodityFormat.getShortNumberFormat(account.getCurrencyNode());
        }
        return null;
    });
    final ChangeListener<Number> widthListener = new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            if (newValue != null && newValue.doubleValue() > 0) {
                JavaFXUtils.runLater(tableViewManager::restoreLayout);
                JavaFXUtils.runLater(tableViewManager::packTable);
                tableView.widthProperty().removeListener(this);
            }
        }
    };
    tableView.widthProperty().addListener(widthListener);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) RecTransaction(jgnash.engine.RecTransaction) ChangeListener(javafx.beans.value.ChangeListener)

Example 7 with RecTransaction

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

the class AbstractReconcileTableModel method messagePosted.

@Override
public void messagePosted(final Message event) {
    if (event.getObject(MessageProperty.ACCOUNT).equals(account)) {
        rwl.writeLock().lock();
        try {
            final Transaction transaction = event.getObject(MessageProperty.TRANSACTION);
            EventQueue.invokeLater(() -> {
                switch(event.getEvent()) {
                    case TRANSACTION_REMOVE:
                        RecTransaction trans = findTransaction(transaction);
                        if (trans != null) {
                            int index = list.indexOf(trans);
                            list.remove(index);
                            fireTableRowsDeleted(index, index);
                        }
                        break;
                    case TRANSACTION_ADD:
                        if (isVisible(transaction)) {
                            RecTransaction newTran = new RecTransaction(transaction, transaction.getReconciled(account));
                            int index = Collections.binarySearch(list, newTran);
                            if (index < 0) {
                                index = -index - 1;
                                list.add(index, newTran);
                                fireTableRowsInserted(index, index);
                            }
                        }
                        break;
                    default:
                        break;
                }
            });
        } finally {
            rwl.writeLock().unlock();
        }
    }
}
Also used : Transaction(jgnash.engine.Transaction) RecTransaction(jgnash.engine.RecTransaction) RecTransaction(jgnash.engine.RecTransaction)

Example 8 with RecTransaction

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

the class AbstractReconcileTableModel method getReconciledTotal.

public BigDecimal getReconciledTotal() {
    BigDecimal sum = BigDecimal.ZERO;
    rwl.readLock().lock();
    try {
        for (final RecTransaction t : list) {
            if (t.getReconciledState() == ReconciledState.RECONCILED) {
                sum = sum.add(t.getAmount(account));
            }
        }
    } finally {
        rwl.readLock().unlock();
    }
    return AccountBalanceDisplayManager.convertToSelectedBalanceMode(account.getAccountType(), sum);
}
Also used : RecTransaction(jgnash.engine.RecTransaction) BigDecimal(java.math.BigDecimal)

Aggregations

RecTransaction (jgnash.engine.RecTransaction)8 BigDecimal (java.math.BigDecimal)3 Transaction (jgnash.engine.Transaction)2 LocalDate (java.time.LocalDate)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 TableColumn (javafx.scene.control.TableColumn)1 TableViewManager (jgnash.uifx.util.TableViewManager)1