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"));
}
}
}
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);
}
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);
}
}
}
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;
}
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);
}
}
Aggregations