Search in sources :

Example 6 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class RecurringPanel method showNewDialog.

private static void showNewDialog() {
    Reminder r = RecurringEntryDialog.showDialog();
    if (r != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        if (!engine.addReminder(r)) {
            final ResourceBundle rb = ResourceUtils.getBundle();
            StaticUIMethods.displayError(rb.getString("Message.Error.ReminderAdd"));
        }
    }
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) ResourceBundle(java.util.ResourceBundle) Engine(jgnash.engine.Engine)

Example 7 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class MessageBusClient method processRemoteMessage.

/**
     * Takes a remote message and forces remote updates before sending the message to the MessageBus to notify UI
     * components of changes.
     *
     * @param message Message to process and send
     */
private void processRemoteMessage(final Message message) {
    logger.fine("processing a remote message");
    final Engine engine = EngineFactory.getEngine(name);
    Objects.requireNonNull(engine);
    if (message.getChannel() == MessageChannel.ACCOUNT) {
        final Account account = message.getObject(MessageProperty.ACCOUNT);
        switch(message.getEvent()) {
            case ACCOUNT_ADD:
            case ACCOUNT_REMOVE:
                engine.refresh(account);
                message.setObject(MessageProperty.ACCOUNT, engine.getAccountByUuid(account.getUuid()));
                engine.refresh(account.getParent());
                break;
            case ACCOUNT_MODIFY:
            case ACCOUNT_SECURITY_ADD:
            case ACCOUNT_SECURITY_REMOVE:
            case ACCOUNT_VISIBILITY_CHANGE:
                engine.refresh(account);
                message.setObject(MessageProperty.ACCOUNT, engine.getAccountByUuid(account.getUuid()));
                break;
            default:
                break;
        }
    }
    if (message.getChannel() == MessageChannel.BUDGET) {
        final Budget budget = message.getObject(MessageProperty.BUDGET);
        switch(message.getEvent()) {
            case BUDGET_ADD:
            case BUDGET_UPDATE:
            case BUDGET_REMOVE:
            case BUDGET_GOAL_UPDATE:
                engine.refresh(budget);
                message.setObject(MessageProperty.BUDGET, engine.getBudgetByUuid(budget.getUuid()));
                break;
            default:
                break;
        }
    }
    if (message.getChannel() == MessageChannel.COMMODITY) {
        switch(message.getEvent()) {
            case CURRENCY_ADD:
            case CURRENCY_MODIFY:
                final CommodityNode currency = message.getObject(MessageProperty.COMMODITY);
                engine.refresh(currency);
                message.setObject(MessageProperty.COMMODITY, engine.getCurrencyNodeByUuid(currency.getUuid()));
                break;
            case SECURITY_ADD:
            case SECURITY_MODIFY:
            case SECURITY_HISTORY_ADD:
            case SECURITY_HISTORY_REMOVE:
                final CommodityNode node = message.getObject(MessageProperty.COMMODITY);
                engine.refresh(node);
                message.setObject(MessageProperty.COMMODITY, engine.getSecurityNodeByUuid(node.getUuid()));
                break;
            case EXCHANGE_RATE_ADD:
            case EXCHANGE_RATE_REMOVE:
                final ExchangeRate rate = message.getObject(MessageProperty.EXCHANGE_RATE);
                engine.refresh(rate);
                message.setObject(MessageProperty.EXCHANGE_RATE, engine.getExchangeRateByUuid(rate.getUuid()));
                break;
            default:
                break;
        }
    }
    if (message.getChannel() == MessageChannel.CONFIG) {
        switch(message.getEvent()) {
            case CONFIG_MODIFY:
                final Config config = message.getObject(MessageProperty.CONFIG);
                engine.refresh(config);
                message.setObject(MessageProperty.CONFIG, engine.getStoredObjectByUuid(Config.class, config.getUuid()));
                break;
            default:
                break;
        }
    }
    if (message.getChannel() == MessageChannel.REMINDER) {
        switch(message.getEvent()) {
            case REMINDER_ADD:
            case REMINDER_REMOVE:
                final Reminder reminder = message.getObject(MessageProperty.REMINDER);
                engine.refresh(reminder);
                message.setObject(MessageProperty.REMINDER, engine.getReminderByUuid(reminder.getUuid()));
                break;
            default:
                break;
        }
    }
    if (message.getChannel() == MessageChannel.TRANSACTION) {
        switch(message.getEvent()) {
            case TRANSACTION_ADD:
            case TRANSACTION_REMOVE:
                final Transaction transaction = message.getObject(MessageProperty.TRANSACTION);
                engine.refresh(transaction);
                message.setObject(MessageProperty.TRANSACTION, engine.getTransactionByUuid(transaction.getUuid()));
                final Account account = message.getObject(MessageProperty.ACCOUNT);
                engine.refresh(account);
                message.setObject(MessageProperty.ACCOUNT, engine.getAccountByUuid(account.getUuid()));
                break;
            default:
                break;
        }
    }
    /* Flag the message as remote */
    message.setRemote();
    logger.fine("fire remote message");
    MessageBus.getInstance(name).fireEvent(message);
}
Also used : Account(jgnash.engine.Account) ExchangeRate(jgnash.engine.ExchangeRate) Reminder(jgnash.engine.recurring.Reminder) Transaction(jgnash.engine.Transaction) Config(jgnash.engine.Config) CommodityNode(jgnash.engine.CommodityNode) Budget(jgnash.engine.budget.Budget) Engine(jgnash.engine.Engine)

Example 8 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class RecurringPanel method showModifyDialog.

private void showModifyDialog() {
    int index = reminderTable.getSelectedRow();
    if (index != -1) {
        // get the old reminder
        final Reminder old = getReminderByRow(index);
        try {
            // create a new reminder
            Reminder modified = RecurringEntryDialog.showDialog((Reminder) old.clone());
            if (modified != null) {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                if (engine.removeReminder(old)) {
                    // remove the old
                    if (!engine.addReminder(modified)) {
                        // add the new
                        StaticUIMethods.displayError(rb.getString("Message.Error.ReminderUpdate"));
                    }
                } else {
                    StaticUIMethods.displayError(rb.getString("Message.Error.ReminderUpdate"));
                }
            }
        } catch (CloneNotSupportedException e) {
            logSevere(RecurringPanel.class, e);
        }
    }
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) Engine(jgnash.engine.Engine)

Example 9 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class JpaRecurringDAO method getReminderList.

/*
     * @see jgnash.engine.ReminderDAOInterface#getReminderList()
     */
@Override
public List<Reminder> getReminderList() {
    List<Reminder> reminderList = Collections.emptyList();
    try {
        final Future<List<Reminder>> future = executorService.submit(() -> {
            emLock.lock();
            try {
                final CriteriaBuilder cb = em.getCriteriaBuilder();
                final CriteriaQuery<Reminder> cq = cb.createQuery(Reminder.class);
                final Root<Reminder> root = cq.from(Reminder.class);
                cq.select(root);
                final TypedQuery<Reminder> q = em.createQuery(cq);
                return stripMarkedForRemoval(new ArrayList<>(q.getResultList()));
            } finally {
                emLock.unlock();
            }
        });
        reminderList = future.get();
    } catch (final InterruptedException | ExecutionException e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    return reminderList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Reminder(jgnash.engine.recurring.Reminder) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with Reminder

use of jgnash.engine.recurring.Reminder in project jgnash by ccavanaugh.

the class RecurringViewController method handleModifyAction.

@FXML
private void handleModifyAction() {
    final Reminder old = selectedReminder.get();
    try {
        final Optional<Reminder> optional = RecurringEntryDialog.showAndWait((Reminder) old.clone());
        optional.ifPresent(reminder -> {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            if (engine.removeReminder(old)) {
                if (!engine.addReminder(reminder)) {
                    StaticUIMethods.displayError(resources.getString("Message.Error.ReminderUpdate"));
                }
            } else {
                StaticUIMethods.displayError(resources.getString("Message.Error.ReminderUpdate"));
            }
        });
    } catch (final CloneNotSupportedException e) {
        Logger.getLogger(RecurringViewController.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) Engine(jgnash.engine.Engine) FXML(javafx.fxml.FXML)

Aggregations

Reminder (jgnash.engine.recurring.Reminder)14 PendingReminder (jgnash.engine.recurring.PendingReminder)8 Engine (jgnash.engine.Engine)7 MonthlyReminder (jgnash.engine.recurring.MonthlyReminder)4 FXML (javafx.fxml.FXML)3 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 DailyReminder (jgnash.engine.recurring.DailyReminder)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 TableCell (javafx.scene.control.TableCell)1 TableColumn (javafx.scene.control.TableColumn)1 CheckBoxTableCell (javafx.scene.control.cell.CheckBoxTableCell)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Account (jgnash.engine.Account)1