use of jgnash.uifx.control.SecurityNodeAreaChart in project jgnash by ccavanaugh.
the class SecurityHistoryController method initialize.
@FXML
void initialize() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
numberFormat.set(CommodityFormat.getShortNumberFormat(engine.getDefaultCurrency()));
selectedSecurityHistoryNode.bind(priceTableView.getSelectionModel().selectedItemProperty());
selectedSecurityNode.bind(securityComboBox.getSelectionModel().selectedItemProperty());
deletePriceButton.disableProperty().bind(Bindings.isNull(selectedSecurityHistoryNode));
selectedSecurityHistoryEvent.bind(eventTableView.getSelectionModel().selectedItemProperty());
deleteEventButton.disableProperty().bind(Bindings.isNull(selectedSecurityHistoryEvent));
// Disabled the update button if a security is not selected, or it does not have a quote source
updatePriceButton.disableProperty().bind(Bindings.or(Bindings.isNull(selectedSecurityNode), Bindings.equal(QuoteSource.NONE, quoteSource)));
// Disabled the update button if a security is not selected, or it does not have a quote source
updateEventButton.disableProperty().bind(Bindings.or(Bindings.isNull(selectedSecurityNode), Bindings.equal(QuoteSource.NONE, quoteSource)));
// Can't add if a security is not selected
addPriceButton.disableProperty().bind(Bindings.isNull(selectedSecurityNode));
// Can't add if a security is not selected and a value is not set
addEventButton.disableProperty().bind(Bindings.isNull(selectedSecurityNode).or(Bindings.isEmpty(eventValueTextField.textProperty())));
priceTableView.setTableMenuButtonVisible(false);
priceTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
final TableColumn<SecurityHistoryNode, LocalDate> priceDateColumn = new TableColumn<>(resources.getString("Column.Date"));
priceDateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
priceDateColumn.setCellFactory(cell -> new ShortDateTableCell<>());
priceTableView.getColumns().add(priceDateColumn);
final TableColumn<SecurityHistoryNode, BigDecimal> priceCloseColumn = new TableColumn<>(resources.getString("Column.Close"));
priceCloseColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getPrice()));
priceCloseColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
priceTableView.getColumns().add(priceCloseColumn);
final TableColumn<SecurityHistoryNode, BigDecimal> priceLowColumn = new TableColumn<>(resources.getString("Column.Low"));
priceLowColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLow()));
priceLowColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
priceTableView.getColumns().add(priceLowColumn);
final TableColumn<SecurityHistoryNode, BigDecimal> priceHighColumn = new TableColumn<>(resources.getString("Column.High"));
priceHighColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getHigh()));
priceHighColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
priceTableView.getColumns().add(priceHighColumn);
final TableColumn<SecurityHistoryNode, Long> priceVolumeColumn = new TableColumn<>(resources.getString("Column.Volume"));
priceVolumeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getVolume()));
priceVolumeColumn.setCellFactory(cell -> new LongFormatTableCell());
priceTableView.getColumns().add(priceVolumeColumn);
priceTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
sortedHistoryList.comparatorProperty().bind(priceTableView.comparatorProperty());
priceTableView.setItems(sortedHistoryList);
final TableColumn<SecurityHistoryEvent, LocalDate> eventDateColumn = new TableColumn<>(resources.getString("Column.Date"));
eventDateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDate()));
eventDateColumn.setCellFactory(cell -> new ShortDateTableCell<>());
eventTableView.getColumns().add(eventDateColumn);
final TableColumn<SecurityHistoryEvent, String> eventActionColumn = new TableColumn<>(resources.getString("Column.Event"));
eventActionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getType().toString()));
eventTableView.getColumns().add(eventActionColumn);
final NumberFormat decimalFormat = NumberFormat.getInstance();
if (decimalFormat instanceof DecimalFormat) {
decimalFormat.setMinimumFractionDigits(MathConstants.SECURITY_PRICE_ACCURACY);
decimalFormat.setMaximumFractionDigits(MathConstants.SECURITY_PRICE_ACCURACY);
}
final TableColumn<SecurityHistoryEvent, BigDecimal> eventValueColumn = new TableColumn<>(resources.getString("Column.Value"));
eventValueColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getValue()));
eventValueColumn.setCellFactory(cell -> new BigDecimalTableCell<>(decimalFormat));
eventTableView.getColumns().add(eventValueColumn);
eventTableView.setTableMenuButtonVisible(false);
eventTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
eventTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
sortedHistoryEventList.comparatorProperty().bind(eventTableView.comparatorProperty());
eventTableView.setItems(sortedHistoryEventList);
eventValueTextField.scaleProperty().set(MathConstants.SECURITY_PRICE_ACCURACY);
chart = new SecurityNodeAreaChart();
chart.securityNodeProperty().bind(selectedSecurityNode);
chartPane.getChildren().addAll(chart);
securityComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
numberFormat.set(CommodityFormat.getShortNumberFormat(newValue.getReportedCurrencyNode()));
closeTextField.scaleProperty().set(newValue.getScale());
lowTextField.scaleProperty().set(newValue.getScale());
highTextField.scaleProperty().set(newValue.getScale());
quoteSource.set(newValue.getQuoteSource());
Platform.runLater(this::loadTables);
}
});
selectedSecurityHistoryNode.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
loadPriceForm();
} else {
clearPriceForm();
}
});
selectedSecurityHistoryEvent.addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
loadEventForm();
} else {
clearEventForm();
}
});
// Install a listener to unregister from the message bus when the window closes
parent.addListener((observable, oldValue, scene) -> {
if (scene != null) {
scene.windowProperty().get().addEventHandler(WindowEvent.WINDOW_HIDING, event -> {
Logger.getLogger(SecurityHistoryController.class.getName()).info("Unregistered from the message bus");
MessageBus.getInstance().unregisterListener(SecurityHistoryController.this, MessageChannel.COMMODITY);
});
}
});
Platform.runLater(() -> MessageBus.getInstance().registerListener(SecurityHistoryController.this, MessageChannel.COMMODITY));
}
Aggregations