use of jgnash.engine.CommodityNode 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.CommodityNode in project jgnash by ccavanaugh.
the class SecurityHistoryController method messagePosted.
@Override
public void messagePosted(final Message message) {
final CommodityNode eventNode = message.getObject(MessageProperty.COMMODITY);
if (eventNode.equals(selectedSecurityNode.get())) {
switch(message.getEvent()) {
case SECURITY_HISTORY_ADD:
case SECURITY_HISTORY_REMOVE:
case SECURITY_HISTORY_EVENT_ADD:
case SECURITY_HISTORY_EVENT_REMOVE:
Platform.runLater(this::loadTables);
Platform.runLater(chart::update);
break;
default:
}
}
}
Aggregations