use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.
the class RecurringViewController method handleNewAction.
@FXML
private void handleNewAction() {
final Optional<Reminder> optional = RecurringEntryDialog.showAndWait(null);
optional.ifPresent(reminder -> {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
if (!engine.addReminder(reminder)) {
StaticUIMethods.displayError(resources.getString("Message.Error.ReminderAdd"));
}
});
}
use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.
the class RecurringViewController method initialize.
@FXML
private void initialize() {
tableView.setTableMenuButtonVisible(true);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
// hide the horizontal scrollbar and prevent ghosting
tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
final TableColumn<Reminder, String> descriptionColumn = new TableColumn<>(resources.getString("Column.Description"));
descriptionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
tableView.getColumns().add(descriptionColumn);
final TableColumn<Reminder, String> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
accountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
accountColumn.setCellValueFactory(param -> {
if (param.getValue().getAccount() != null) {
return new SimpleObjectProperty<>(param.getValue().getAccount().toString());
}
return null;
});
tableView.getColumns().add(accountColumn);
final TableColumn<Reminder, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
amountColumn.setCellValueFactory(param -> {
if (param.getValue().getTransaction() != null) {
return new SimpleObjectProperty<>(param.getValue().getTransaction().getAmount(param.getValue().getAccount()));
}
return null;
});
amountColumn.setCellFactory(new Callback<TableColumn<Reminder, BigDecimal>, TableCell<Reminder, BigDecimal>>() {
@Override
public TableCell<Reminder, BigDecimal> call(TableColumn<Reminder, BigDecimal> param) {
return new TableCell<Reminder, BigDecimal>() {
{
setStyle("-fx-alignment: center-right;");
}
@Override
protected void updateItem(final BigDecimal amount, final boolean empty) {
super.updateItem(amount, empty);
if (!empty && getTableRow() != null && getTableRow().getItem() != null) {
final Reminder reminder = (Reminder) getTableRow().getItem();
if (reminder.getTransaction() != null) {
setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(amount));
if (amount != null && amount.signum() < 0) {
setId(StyleClass.NORMAL_NEGATIVE_CELL_ID);
} else {
setId(StyleClass.NORMAL_CELL_ID);
}
} else {
setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(BigDecimal.ZERO));
}
}
}
};
}
});
tableView.getColumns().add(amountColumn);
final TableColumn<Reminder, String> frequencyColumn = new TableColumn<>(resources.getString("Column.Freq"));
frequencyColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getReminderType().toString()));
tableView.getColumns().add(frequencyColumn);
final TableColumn<Reminder, Boolean> enabledColumn = new TableColumn<>(resources.getString("Column.Enabled"));
enabledColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isEnabled()));
enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn));
tableView.getColumns().add(enabledColumn);
final TableColumn<Reminder, LocalDate> lastPosted = new TableColumn<>(resources.getString("Column.LastPosted"));
lastPosted.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLastDate()));
lastPosted.setCellFactory(cell -> new ShortDateTableCell<>());
tableView.getColumns().add(lastPosted);
final TableColumn<Reminder, LocalDate> due = new TableColumn<>(resources.getString("Column.Due"));
due.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getIterator().next()));
due.setCellFactory(cell -> new ShortDateTableCell<>());
tableView.getColumns().add(due);
sortedReminderList.comparatorProperty().bind(tableView.comparatorProperty());
tableView.setItems(sortedReminderList);
selectedReminder.bind(tableView.getSelectionModel().selectedItemProperty());
// bind enabled state of the buttons to the selected reminder property
deleteButton.disableProperty().bind(Bindings.isNull(selectedReminder));
modifyButton.disableProperty().bind(Bindings.isNull(selectedReminder));
MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM, MessageChannel.REMINDER);
JavaFXUtils.runLater(this::loadTable);
startTimer();
// Update the period when the snooze value changes
Options.reminderSnoozePeriodProperty().addListener((observable, oldValue, newValue) -> {
stopTimer();
startTimer();
});
}
use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.
the class Engine method createDefaultReminder.
/**
* Creates a default reminder given a transaction and the primary account. The Reminder will need to persisted.
*
* @param transaction Transaction for the reminder. The transaction wil be cloned
* @param account primary account
* @return new default {@code MonthlyReminder}
*/
public Reminder createDefaultReminder(final Transaction transaction, final Account account) {
final Reminder reminder = new MonthlyReminder();
try {
reminder.setAccount(account);
reminder.setStartDate(transaction.getLocalDate().plusMonths(1));
reminder.setTransaction((Transaction) transaction.clone());
reminder.setDescription(transaction.getPayee());
reminder.setNotes(transaction.getMemo());
} catch (final CloneNotSupportedException e) {
logSevere(e.getLocalizedMessage());
}
return reminder;
}
use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.
the class Engine method processPendingReminders.
public void processPendingReminders(final Collection<PendingReminder> pendingReminders) {
pendingReminders.stream().filter(PendingReminder::isApproved).forEach(pending -> {
final Reminder reminder = pending.getReminder();
if (reminder.getTransaction() != null) {
final Transaction t = reminder.getTransaction();
t.setDate(pending.getCommitDate());
addTransaction(t);
}
reminder.setLastDate();
if (!updateReminder(reminder)) {
logSevere(rb.getString("Message.Error.ReminderUpdate"));
}
});
}
Aggregations