use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class BudgetTableController method buildAccountPeriodSummaryColumn.
private TableColumn<AccountGroup, BigDecimal> buildAccountPeriodSummaryColumn(final int index) {
final BudgetPeriodDescriptor descriptor = budgetResultsModel.getDescriptorList().get(index);
// determine if the column is to be highlighted if the period is not yearly
final Boolean highlight = (descriptor.isBetween(LocalDate.now()) ? Boolean.TRUE : Boolean.FALSE) && budget.get().getBudgetPeriod() != Period.YEARLY;
final TableColumn<AccountGroup, BigDecimal> headerColumn = new TableColumn<>(descriptor.getPeriodDescription());
final TableColumn<AccountGroup, BigDecimal> budgetedColumn = new TableColumn<>(resources.getString("Column.Budgeted"));
budgetedColumn.getProperties().put(NOW, highlight);
budgetedColumn.setCellValueFactory(param -> {
if (param.getValue() != null) {
return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getBudgeted());
}
return new SimpleObjectProperty<>(BigDecimal.ZERO);
});
budgetedColumn.setCellFactory(param -> new AccountGroupTableCell());
lockColumnBehavior(budgetedColumn, columnWidth);
headerColumn.getColumns().add(budgetedColumn);
final TableColumn<AccountGroup, BigDecimal> actualColumn = new TableColumn<>(resources.getString("Column.Actual"));
actualColumn.getProperties().put(NOW, highlight);
actualColumn.setCellValueFactory(param -> {
if (param.getValue() != null) {
return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getChange());
}
return new SimpleObjectProperty<>(BigDecimal.ZERO);
});
actualColumn.setCellFactory(param -> new AccountGroupTableCell());
lockColumnBehavior(actualColumn, columnWidth);
headerColumn.getColumns().add(actualColumn);
final TableColumn<AccountGroup, BigDecimal> remainingColumn = new TableColumn<>(resources.getString("Column.Remaining"));
remainingColumn.getProperties().put(NOW, highlight);
remainingColumn.setCellValueFactory(param -> {
if (param.getValue() != null) {
return new SimpleObjectProperty<>(budgetResultsModel.getResults(descriptor, param.getValue()).getRemaining());
}
return new SimpleObjectProperty<>(BigDecimal.ZERO);
});
remainingColumn.setCellFactory(param -> new AccountGroupTableCell());
// the max width is not bound to allow last column to grow and fill any voids
lockColumnBehavior(remainingColumn, remainingColumnWidth);
headerColumn.getColumns().add(remainingColumn);
return headerColumn;
}
use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class NotificationDialog method initialize.
@FXML
private void initialize() {
final TableColumn<PendingReminder, Boolean> enabledColumn = new TableColumn<>(resources.getString("Column.Approve"));
enabledColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isApproved()));
enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn));
tableView.getColumns().add(enabledColumn);
final TableColumn<PendingReminder, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getCommitDate()));
dateColumn.setCellFactory(cell -> new DateTableCell());
tableView.getColumns().add(dateColumn);
final TableColumn<PendingReminder, String> descriptionColumn = new TableColumn<>(resources.getString("Column.Description"));
descriptionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getReminder().getDescription()));
tableView.getColumns().add(descriptionColumn);
tableView.setItems(observableReminderList);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
// Toggle the selection
tableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
newValue.setApproved(!newValue.isApproved());
tableView.refresh();
JavaFXUtils.runLater(() -> tableView.getSelectionModel().clearSelection());
}
});
okButton.onActionProperty().set(event -> handleOkayAction());
cancelButton.onActionProperty().set(event -> handleCancelAction());
selectAllButton.onActionProperty().set(event -> handleSelectAllAction());
clearAllButton.onActionProperty().set(event -> handleClearAllAction());
invertButton.onActionProperty().set(event -> handleInvertSelectionAction());
// configure the combo box and bind the property
snoozeComboBox.setSelectedPeriod(Options.reminderSnoozePeriodProperty().get());
Options.reminderSnoozePeriodProperty().bind(snoozeComboBox.periodProperty());
MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM);
// unregister the listener when closing
setOnHiding(event -> MessageBus.getInstance().unregisterListener(NotificationDialog.this, MessageChannel.SYSTEM));
}
use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class BasicRegisterTableController method buildTable.
@Override
protected void buildTable() {
final String[] columnNames = RegisterFactory.getColumnNames(accountProperty().get().getAccountType());
final TableColumn<Transaction, LocalDate> dateColumn = new TableColumn<>(columnNames[0]);
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
dateColumn.setCellFactory(cell -> new TransactionDateTableCell());
tableView.getColumns().add(dateColumn);
final TableColumn<Transaction, LocalDateTime> dateTimeColumn = new TableColumn<>(columnNames[1]);
dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getTimestamp()));
dateTimeColumn.setCellFactory(cell -> new TransactionDateTimeTableCell());
tableView.getColumns().add(dateTimeColumn);
final TableColumn<Transaction, String> numberColumn = new TableColumn<>(columnNames[2]);
numberColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getNumber()));
numberColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(numberColumn);
final TableColumn<Transaction, String> payeeColumn = new TableColumn<>(columnNames[3]);
payeeColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getPayee()));
payeeColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(payeeColumn);
final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
memoColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getMemo()));
memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(memoColumn);
final TableColumn<Transaction, String> accountColumn = new TableColumn<>(columnNames[5]);
accountColumn.setCellValueFactory(param -> new AccountNameWrapper(param.getValue()));
accountColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(accountColumn);
final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[6]);
reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.get()).toString()));
reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(reconciledColumn);
final Callback<TableColumn<Transaction, BigDecimal>, TableCell<Transaction, BigDecimal>> shortDecimalCellFactory = cell -> new TransactionCommodityFormatTableCell(NumericFormats.getShortCommodityFormat(account.get().getCurrencyNode()));
final TableColumn<Transaction, BigDecimal> increaseColumn = new TableColumn<>(columnNames[7]);
increaseColumn.setCellValueFactory(param -> new IncreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
increaseColumn.setCellFactory(shortDecimalCellFactory);
tableView.getColumns().add(increaseColumn);
final TableColumn<Transaction, BigDecimal> decreaseColumn = new TableColumn<>(columnNames[8]);
decreaseColumn.setCellValueFactory(param -> new DecreaseAmountProperty(param.getValue().getAmount(accountProperty().getValue())));
decreaseColumn.setCellFactory(shortDecimalCellFactory);
tableView.getColumns().add(decreaseColumn);
final TableColumn<Transaction, BigDecimal> balanceColumn = new TableColumn<>(columnNames[9]);
balanceColumn.setCellValueFactory(param -> {
final AccountType accountType = accountProperty().getValue().getAccountType();
return new SimpleObjectProperty<>(AccountBalanceDisplayManager.convertToSelectedBalanceMode(accountType, getBalanceAt(param.getValue())));
});
balanceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(NumericFormats.getFullCommodityFormat(account.get().getCurrencyNode())));
// do not allow a sort on the balance
balanceColumn.setSortable(false);
tableView.getColumns().add(balanceColumn);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableViewManager.setColumnFormatFactory(param -> {
if (param == balanceColumn) {
return NumericFormats.getFullCommodityFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == increaseColumn || param == decreaseColumn) {
return NumericFormats.getShortCommodityFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == dateColumn) {
return DateUtils.getShortDateFormatter().toFormat();
} else if (param == dateTimeColumn) {
return DateUtils.getShortDateTimeFormatter().toFormat();
}
return null;
});
}
use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.
the class InvestmentRegisterTableController method buildTable.
@Override
protected void buildTable() {
final String[] columnNames = RegisterFactory.getColumnNames(accountProperty().get().getAccountType());
final TableColumn<Transaction, LocalDate> dateColumn = new TableColumn<>(columnNames[0]);
dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
dateColumn.setCellFactory(cell -> new TransactionDateTableCell());
tableView.getColumns().add(dateColumn);
final TableColumn<Transaction, LocalDateTime> dateTimeColumn = new TableColumn<>(columnNames[1]);
dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getTimestamp()));
dateTimeColumn.setCellFactory(cell -> new TransactionDateTimeTableCell());
tableView.getColumns().add(dateTimeColumn);
final TableColumn<Transaction, String> typeColumn = new TableColumn<>(columnNames[2]);
typeColumn.setCellValueFactory(param -> new TransactionTypeWrapper(param.getValue()));
typeColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(typeColumn);
final TableColumn<Transaction, String> investmentColumn = new TableColumn<>(columnNames[3]);
investmentColumn.setCellValueFactory(param -> new TransactionSymbolWrapper(param.getValue()));
investmentColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(investmentColumn);
final TableColumn<Transaction, String> memoColumn = new TableColumn<>(columnNames[4]);
memoColumn.setCellValueFactory(param -> new MemoWrapper(param.getValue()));
memoColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(memoColumn);
final TableColumn<Transaction, String> reconciledColumn = new TableColumn<>(columnNames[5]);
reconciledColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getReconciled(account.getValue()).toString()));
reconciledColumn.setCellFactory(cell -> new TransactionStringTableCell());
tableView.getColumns().add(reconciledColumn);
final TableColumn<Transaction, BigDecimal> quantityColumn = new TableColumn<>(columnNames[6]);
quantityColumn.setCellValueFactory(param -> new QuantityProperty(param.getValue()));
quantityColumn.setCellFactory(cell -> new InvestmentTransactionQuantityTableCell());
tableView.getColumns().add(quantityColumn);
final TableColumn<Transaction, BigDecimal> priceColumn = new TableColumn<>(columnNames[7]);
priceColumn.setCellValueFactory(param -> new PriceProperty(param.getValue()));
priceColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(NumericFormats.getShortCommodityFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(priceColumn);
final TableColumn<Transaction, BigDecimal> netColumn = new TableColumn<>(columnNames[8]);
netColumn.setCellValueFactory(param -> new AmountProperty(param.getValue()));
netColumn.setCellFactory(cell -> new TransactionCommodityFormatTableCell(NumericFormats.getFullCommodityFormat(account.get().getCurrencyNode())));
tableView.getColumns().add(netColumn);
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableViewManager.setColumnFormatFactory(param -> {
if (param == netColumn) {
return NumericFormats.getFullCommodityFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == quantityColumn) {
return getQuantityColumnFormat();
} else if (param == priceColumn) {
return NumericFormats.getShortCommodityFormat(accountProperty().getValue().getCurrencyNode());
} else if (param == dateColumn) {
return DateUtils.getShortDateFormatter().toFormat();
} else if (param == dateTimeColumn) {
return DateUtils.getShortDateTimeFormatter().toFormat();
}
return null;
});
}
use of javafx.scene.control.TableColumn 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(NumericFormats.getShortCommodityFormat(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(NumericFormats.getShortCommodityFormat(newValue.getReportedCurrencyNode()));
closeTextField.scaleProperty().set(newValue.getScale());
lowTextField.scaleProperty().set(newValue.getScale());
highTextField.scaleProperty().set(newValue.getScale());
quoteSource.set(newValue.getQuoteSource());
JavaFXUtils.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);
});
}
});
JavaFXUtils.runLater(() -> MessageBus.getInstance().registerListener(SecurityHistoryController.this, MessageChannel.COMMODITY));
}
Aggregations