use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class BudgetResultsModel method processTransactionEvent.
private void processTransactionEvent(final Message message) {
final Transaction transaction = message.getObject(MessageProperty.TRANSACTION);
descriptorList.stream().filter(descriptor -> descriptor.isBetween(transaction.getLocalDate())).forEach(descriptor -> {
final Set<Account> accountSet = new HashSet<>();
for (Account account : transaction.getAccounts()) {
accountSet.addAll(account.getAncestors());
}
accountSet.forEach(this::clearCached);
});
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class BudgetManagerDialogController method handleDeleteAction.
@FXML
private void handleDeleteAction() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final List<Budget> selected = new ArrayList<>(budgetListView.getSelectionModel().getSelectedItems());
if (!selected.isEmpty()) {
final String message = selected.size() == 1 ? resources.getString("Message.ConfirmBudgetDelete") : resources.getString("Message.ConfirmMultipleBudgetDelete");
if (StaticUIMethods.showConfirmationDialog(resources.getString("Title.Confirm"), message).getButtonData() == ButtonBar.ButtonData.YES) {
selected.stream().filter(value -> !engine.removeBudget(value)).forEach(value -> StaticUIMethods.displayError(resources.getString("Message.Error.BudgetRemove")));
}
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class UIApplication method restartUI.
/**
* Forces a restart of the UI without having to reload the engine. Useful when changing the look and feel
*/
public static void restartUI() {
EventQueue.invokeLater(() -> {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
MessageBus messageBus = MessageBus.getInstance(engine.getName());
Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.UI_RESTARTING, engine);
messageBus.fireEvent(message);
}
mainFrame.setVisible(false);
mainFrame.doPartialDispose();
// recreate the main UI twice to flush look and feel info from the JXSwing components
mainFrame = new MainFrame();
mainFrame.doPartialDispose();
mainFrame = new MainFrame();
mainFrame.setVisible(true);
if (engine != null) {
MessageBus messageBus = MessageBus.getInstance(engine.getName());
Message message = new Message(MessageChannel.SYSTEM, ChannelEvent.UI_RESTARTED, engine);
messageBus.fireEvent(message);
}
});
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method updateBudgetGoals.
private void updateBudgetGoals(final Budget budget, final Account account) {
dataLock.writeLock().lock();
try {
Message message;
boolean result = getBudgetDAO().update(budget);
if (result) {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_GOAL_UPDATE, this);
} else {
message = new Message(MessageChannel.BUDGET, ChannelEvent.BUDGET_GOAL_UPDATE_FAILED, this);
}
message.setObject(MessageProperty.BUDGET, budget);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
logger.log(Level.FINE, "Budget goal updated for {0}", account.getPathName());
} finally {
dataLock.writeLock().unlock();
}
}
use of jgnash.engine.message.Message in project jgnash by ccavanaugh.
the class Engine method moveAccount.
/**
* Move an account to a new parent account..
*
* @param account account to move
* @param newParent the new parent account
* @return true if successful
*/
public boolean moveAccount(final Account account, final Account newParent) {
Objects.requireNonNull(account);
Objects.requireNonNull(newParent);
dataLock.writeLock().lock();
try {
// cannot invert the child/parent relationship of an account
if (account.contains(newParent)) {
Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY_FAILED, this);
message.setObject(MessageProperty.ACCOUNT, account);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountMoveFailed"));
return false;
}
Account oldParent = account.getParent();
if (oldParent != null) {
// check for detached account
oldParent.removeChild(account);
getAccountDAO().updateAccount(account);
getAccountDAO().updateAccount(oldParent);
Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY, this);
message.setObject(MessageProperty.ACCOUNT, oldParent);
messageBus.fireEvent(message);
}
newParent.addChild(account);
getAccountDAO().updateAccount(account);
getAccountDAO().updateAccount(newParent);
Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY, this);
message.setObject(MessageProperty.ACCOUNT, newParent);
messageBus.fireEvent(message);
logInfo(rb.getString("Message.AccountModify"));
return true;
} finally {
dataLock.writeLock().unlock();
}
}
Aggregations