use of jgnash.engine.message.Message 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) -> Platform.runLater(EditExchangeRatesController.this::loadExchangeRateHistory));
selectedHistoryNode.addListener((observable, oldValue, newValue) -> Platform.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);
}));
}
});
}
Aggregations