Search in sources :

Example 1 with PendingReminder

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);
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) FXML(javafx.fxml.FXML)

Example 2 with PendingReminder

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;
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) PendingReminder(jgnash.engine.recurring.PendingReminder) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder) Reminder(jgnash.engine.recurring.Reminder) RecurringIterator(jgnash.engine.recurring.RecurringIterator) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 3 with PendingReminder

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();
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) SwingWorker(javax.swing.SwingWorker) List(java.util.List) Preferences(java.util.prefs.Preferences) ExecutionException(java.util.concurrent.ExecutionException) Engine(jgnash.engine.Engine)

Example 4 with PendingReminder

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);
    }
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) Engine(jgnash.engine.Engine)

Example 5 with PendingReminder

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"));
        }
    });
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) MonthlyReminder(jgnash.engine.recurring.MonthlyReminder) Reminder(jgnash.engine.recurring.Reminder)

Aggregations

PendingReminder (jgnash.engine.recurring.PendingReminder)5 LocalDate (java.time.LocalDate)2 Engine (jgnash.engine.Engine)2 MonthlyReminder (jgnash.engine.recurring.MonthlyReminder)2 Reminder (jgnash.engine.recurring.Reminder)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Preferences (java.util.prefs.Preferences)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 FXML (javafx.fxml.FXML)1 TableColumn (javafx.scene.control.TableColumn)1 SwingWorker (javax.swing.SwingWorker)1 RecurringIterator (jgnash.engine.recurring.RecurringIterator)1