Search in sources :

Example 1 with ShortDateTableCell

use of jgnash.uifx.control.ShortDateTableCell 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());
                switch(t.getState()) {
                    case EQUAL:
                        t.setState(ImportState.NOT_EQUAL);
                        break;
                    case NOT_EQUAL:
                        t.setState(ImportState.EQUAL);
                        break;
                    case NEW:
                        t.setState(ImportState.IGNORE);
                        break;
                    case IGNORE:
                        t.setState(ImportState.NEW);
                        break;
                }
                JavaFXUtils.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();
        JavaFXUtils.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();
        JavaFXUtils.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());
            }
            // nop account
            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());
        JavaFXUtils.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);
        // add tool tip
        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.importat.ImportState) LocalDate(java.time.LocalDate) ImportTransaction(jgnash.convert.importat.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)

Example 2 with ShortDateTableCell

use of jgnash.uifx.control.ShortDateTableCell in project jgnash by ccavanaugh.

the class EditExchangeRatesController method initialize.

@FXML
void initialize() {
    exchangeRateField.scaleProperty().set(MathConstants.EXCHANGE_RATE_ACCURACY);
    exchangeRateTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    exchangeRateTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    final TableColumn<ExchangeRateHistoryNode, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
    dateColumn.setCellFactory(cell -> new ShortDateTableCell<>());
    exchangeRateTable.getColumns().add(dateColumn);
    final NumberFormat decimalFormat = NumberFormat.getInstance();
    if (decimalFormat instanceof DecimalFormat) {
        decimalFormat.setMinimumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
        decimalFormat.setMaximumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
    }
    final TableColumn<ExchangeRateHistoryNode, BigDecimal> rateColumn = new TableColumn<>(resources.getString("Column.ExchangeRate"));
    rateColumn.setCellValueFactory(param -> {
        if (param == null || selectedExchangeRate.get() == null) {
            return null;
        }
        if (selectedExchangeRate.get().getRateId().startsWith(baseCurrencyComboBox.getValue().getSymbol())) {
            return new SimpleObjectProperty<>(param.getValue().getRate());
        }
        return new SimpleObjectProperty<>(BigDecimal.ONE.divide(param.getValue().getRate(), MathConstants.mathContext));
    });
    rateColumn.setCellFactory(cell -> new BigDecimalTableCell<>(decimalFormat));
    exchangeRateTable.getColumns().add(rateColumn);
    baseCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    targetCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    selectedHistoryNode.bind(exchangeRateTable.getSelectionModel().selectedItemProperty());
    deleteButton.disableProperty().bind(selectedHistoryNode.isNull());
    clearButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty());
    addButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty().or(Bindings.equal(baseCurrencyComboBox.getSelectionModel().selectedItemProperty(), targetCurrencyComboBox.getSelectionModel().selectedItemProperty())));
    selectedExchangeRate.addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(EditExchangeRatesController.this::loadExchangeRateHistory));
    selectedHistoryNode.addListener((observable, oldValue, newValue) -> JavaFXUtils.runLater(EditExchangeRatesController.this::updateForm));
    MessageBus.getInstance().registerListener(this, MessageChannel.COMMODITY);
    // Install a listener to unregister from the message bus when the window closes
    parent.addListener((observable, oldValue, scene) -> {
        if (scene != null) {
            scene.windowProperty().addListener((observable1, oldValue1, window) -> window.addEventHandler(WindowEvent.WINDOW_HIDING, event -> {
                handleStopAction();
                Logger.getLogger(EditExchangeRatesController.class.getName()).info("Unregistered from the message bus");
                MessageBus.getInstance().unregisterListener(EditExchangeRatesController.this, MessageChannel.COMMODITY);
            }));
        }
    });
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) CurrencyUpdateFactory(jgnash.net.currency.CurrencyUpdateFactory) EngineFactory(jgnash.engine.EngineFactory) FXCollections(javafx.collections.FXCollections) MathConstants(jgnash.engine.MathConstants) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) MessageBus(jgnash.engine.message.MessageBus) Bindings(javafx.beans.binding.Bindings) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) ExchangeRate(jgnash.engine.ExchangeRate) BigDecimal(java.math.BigDecimal) Task(javafx.concurrent.Task) MessageProperty(jgnash.engine.message.MessageProperty) ProgressBar(javafx.scene.control.ProgressBar) ResourceBundle(java.util.ResourceBundle) MessageChannel(jgnash.engine.message.MessageChannel) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) CurrencyNode(jgnash.engine.CurrencyNode) MessageListener(jgnash.engine.message.MessageListener) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) FXMLUtils(jgnash.uifx.util.FXMLUtils) DecimalFormat(java.text.DecimalFormat) Logger(java.util.logging.Logger) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) FXML(javafx.fxml.FXML) ResourceUtils(jgnash.resource.util.ResourceUtils) CurrencyComboBox(jgnash.uifx.control.CurrencyComboBox) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Optional(java.util.Optional) DecimalTextField(jgnash.uifx.control.DecimalTextField) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) DatePickerEx(jgnash.uifx.control.DatePickerEx) Message(jgnash.engine.message.Message) DecimalFormat(java.text.DecimalFormat) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) LocalDate(java.time.LocalDate) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) NumberFormat(java.text.NumberFormat) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 TableColumn (javafx.scene.control.TableColumn)2 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 ExecutionException (java.util.concurrent.ExecutionException)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Bindings (javafx.beans.binding.Bindings)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 FXCollections (javafx.collections.FXCollections)1 Task (javafx.concurrent.Task)1 WorkerStateEvent (javafx.concurrent.WorkerStateEvent)1