Search in sources :

Example 1 with ImportState

use of jgnash.convert.imports.ImportState in project jgnash by ccavanaugh.

the class ImportPageTwoController method buildTableView.

private void buildTableView() {
    final TableColumn<ImportTransaction, ImportState> stateColumn = new TableColumn<>();
    stateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getState()));
    stateColumn.setCellFactory(param -> {
        TableCell<ImportTransaction, ImportState> cell = new ImportStateTableCell();
        cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
            if (event.getClickCount() > 1) {
                final ImportTransaction t = tableView.getItems().get(((TableCell<?, ?>) event.getSource()).getTableRow().getIndex());
                if (t.getState() == ImportState.EQUAL) {
                    t.setState(ImportState.NOT_EQUAL);
                } else if (t.getState() == ImportState.NOT_EQUAL) {
                    t.setState(ImportState.EQUAL);
                } else if (t.getState() == ImportState.NEW) {
                    t.setState(ImportState.IGNORE);
                } else if (t.getState() == ImportState.IGNORE) {
                    t.setState(ImportState.NEW);
                }
                Platform.runLater(tableView::refresh);
            }
        });
        return cell;
    });
    tableView.getColumns().add(stateColumn);
    final TableColumn<ImportTransaction, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDatePosted()));
    dateColumn.setCellFactory(param -> new ShortDateTableCell<>());
    tableView.getColumns().add(dateColumn);
    final TableColumn<ImportTransaction, String> numberColumn = new TableColumn<>(resources.getString("Column.Num"));
    numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCheckNumber()));
    tableView.getColumns().add(numberColumn);
    final TableColumn<ImportTransaction, String> payeeColumn = new TableColumn<>(resources.getString("Column.Payee"));
    payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
    tableView.getColumns().add(payeeColumn);
    final TableColumn<ImportTransaction, String> memoColumn = new TableColumn<>(resources.getString("Column.Memo"));
    memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
    tableView.getColumns().add(memoColumn);
    final TableColumn<ImportTransaction, Account> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount());
        }
        return null;
    });
    accountColumn.setCellFactory(param -> new AccountComboBoxTableCell<>());
    accountColumn.setEditable(true);
    accountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setAccount(event.getNewValue());
        lastAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(accountColumn);
    incomeAccountColumn = new TableColumn<>(resources.getString("Column.Income"));
    incomeAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getGainsAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getGainsAccount());
        }
        return null;
    });
    incomeAccountColumn.setCellFactory(param -> new IncomeAccountComboBoxTableCell<>());
    incomeAccountColumn.setEditable(true);
    incomeAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setGainsAccount(event.getNewValue());
        lastGainsAccount = event.getNewValue();
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(incomeAccountColumn);
    expenseAccountColumn = new TableColumn<>(resources.getString("Column.Expense"));
    expenseAccountColumn.setCellValueFactory(param -> {
        if (param.getValue() != null && param.getValue().getFeesAccount() != null) {
            if (param.getValue().getFees().compareTo(BigDecimal.ZERO) != 0) {
                return new SimpleObjectProperty<>(param.getValue().getFeesAccount());
            } else {
                return new SimpleObjectProperty<>(NOP_EXPENSE_ACCOUNT);
            }
        }
        return null;
    });
    expenseAccountColumn.setCellFactory(param -> new ExpenseAccountComboBoxTableCell<>());
    expenseAccountColumn.setEditable(true);
    expenseAccountColumn.setOnEditCommit(event -> {
        event.getTableView().getItems().get(event.getTablePosition().getRow()).setFeesAccount(event.getNewValue());
        Platform.runLater(tableViewManager::packTable);
    });
    tableView.getColumns().add(expenseAccountColumn);
    final TableColumn<ImportTransaction, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getAmount()));
    amountColumn.setCellFactory(param -> new BigDecimalTableCell<>(numberFormat));
    amountColumn.setCellFactory(param -> {
        final TableCell<ImportTransaction, BigDecimal> cell = new BigDecimalTableCell<>(numberFormat);
        cell.indexProperty().addListener((observable, oldValue, newValue) -> {
            final int index = newValue.intValue();
            if (index >= 0 && index < tableView.itemsProperty().get().size()) {
                cell.setTooltip(new Tooltip(tableView.itemsProperty().get().get(index).getToolTip()));
            }
        });
        return cell;
    });
    tableView.getColumns().add(amountColumn);
    typeColumn = new TableColumn<>(resources.getString("Column.Type"));
    typeColumn.setCellValueFactory(param -> {
        TransactionType transactionType = TransactionType.SINGLENTRY;
        if (param.getValue().isInvestmentTransaction()) {
            transactionType = param.getValue().getTransactionType();
        } else if (!param.getValue().getAccount().equals(baseAccount)) {
            transactionType = TransactionType.DOUBLEENTRY;
        }
        return new SimpleStringProperty(transactionType.toString());
    });
    tableView.getColumns().add(typeColumn);
}
Also used : Account(jgnash.engine.Account) TransactionType(jgnash.engine.TransactionType) ImportState(jgnash.convert.imports.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.imports.ImportTransaction) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) Tooltip(javafx.scene.control.Tooltip) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty)

Aggregations

BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 TableCell (javafx.scene.control.TableCell)1 TableColumn (javafx.scene.control.TableColumn)1 Tooltip (javafx.scene.control.Tooltip)1 ImportState (jgnash.convert.imports.ImportState)1 ImportTransaction (jgnash.convert.imports.ImportTransaction)1 Account (jgnash.engine.Account)1 TransactionType (jgnash.engine.TransactionType)1 BigDecimalTableCell (jgnash.uifx.control.BigDecimalTableCell)1 ShortDateTableCell (jgnash.uifx.control.ShortDateTableCell)1