use of jgnash.engine.recurring.PendingReminder 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();
Platform.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());
snoozeComboBox.setSelectedPeriod(Options.reminderSnoozePeriodProperty().get());
// Bind options to the snooze period property
Options.reminderSnoozePeriodProperty().bind(snoozeComboBox.periodProperty());
MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM);
}
use of jgnash.engine.recurring.PendingReminder in project jgnash by ccavanaugh.
the class Engine method getPendingReminders.
public List<PendingReminder> getPendingReminders() {
final ArrayList<PendingReminder> pendingList = new ArrayList<>();
final List<Reminder> list = getReminders();
// today's date
final LocalDate now = LocalDate.now();
for (final Reminder r : list) {
if (r.isEnabled()) {
final RecurringIterator ri = r.getIterator();
LocalDate next = ri.next();
while (next != null) {
LocalDate date = next;
if (r.isAutoCreate()) {
date = date.minusDays(r.getDaysAdvance());
}
if (DateUtils.before(date, now)) {
// need to fire this reminder
pendingList.add(new PendingReminder(r, next));
next = ri.next();
} else {
next = null;
}
}
}
}
return pendingList;
}
use of jgnash.engine.recurring.PendingReminder in project jgnash by ccavanaugh.
the class RecurringPanel method showRecurringDialog.
private synchronized void showRecurringDialog() {
// exit if engine is not running or a dialog is already visible
if (showingDialog || EngineFactory.getEngine(EngineFactory.DEFAULT) == null) {
return;
}
SwingWorker<List<PendingReminder>, Void> worker = new SwingWorker<List<PendingReminder>, Void>() {
@Override
protected List<PendingReminder> doInBackground() throws Exception {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
return engine.getPendingReminders();
}
@Override
protected void done() {
try {
List<PendingReminder> reminders = get();
// Event occurs on the EDT, so no need to invoke later
if (!reminders.isEmpty()) {
showingDialog = true;
Preferences p = Preferences.userNodeForPackage(getClass());
int snooze = p.getInt(SNOOZE, DEFAULT_SNOOZE);
// display the notification dialog
snooze = NotificationDialog.showDialog(reminders, snooze);
p.putInt(SNOOZE, snooze);
if (timer != null) {
if (snooze != 0) {
timer.setDelay(snooze);
timer.setInitialDelay(snooze);
timer.restart();
} else {
timer.stop();
}
} else {
throw new RuntimeException("Lost the timer!");
}
showingDialog = false;
}
} catch (final InterruptedException | ExecutionException | RuntimeException e) {
logSevere(RecurringPanel.class, e);
}
}
};
worker.execute();
}
use of jgnash.engine.recurring.PendingReminder in project jgnash by ccavanaugh.
the class RecurringViewController method showReminderDialog.
private void showReminderDialog() {
Logger.getLogger(RecurringViewController.class.getName()).info("Show dialog");
if (dialogShowing.compareAndSet(false, true)) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final Collection<PendingReminder> pendingReminders = engine.getPendingReminders();
if (!pendingReminders.isEmpty()) {
final NotificationDialog notificationDialog = new NotificationDialog();
notificationDialog.setReminders(pendingReminders);
notificationDialog.showAndWait();
engine.processPendingReminders(notificationDialog.getApprovedReminders());
}
dialogShowing.getAndSet(false);
}
}
use of jgnash.engine.recurring.PendingReminder 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