Search in sources :

Example 1 with Message

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);
    });
}
Also used : Engine(jgnash.engine.Engine) RootAccount(jgnash.engine.RootAccount) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) MessageProxy(jgnash.engine.message.MessageProxy) MathConstants(jgnash.engine.MathConstants) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) MessageBus(jgnash.engine.message.MessageBus) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) MessageProperty(jgnash.engine.message.MessageProperty) MessageChannel(jgnash.engine.message.MessageChannel) Map(java.util.Map) AccountType(jgnash.engine.AccountType) EnumSet(java.util.EnumSet) CurrencyNode(jgnash.engine.CurrencyNode) MessageListener(jgnash.engine.message.MessageListener) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EnumMap(java.util.EnumMap) Comparators(jgnash.engine.Comparators) Set(java.util.Set) Collectors(java.util.stream.Collectors) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) Account(jgnash.engine.Account) Message(jgnash.engine.message.Message) RootAccount(jgnash.engine.RootAccount) Account(jgnash.engine.Account) Transaction(jgnash.engine.Transaction) HashSet(java.util.HashSet)

Example 2 with Message

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")));
        }
    }
}
Also used : Button(javafx.scene.control.Button) Engine(jgnash.engine.Engine) ListView(javafx.scene.control.ListView) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) MessageBus(jgnash.engine.message.MessageBus) ChannelEvent(jgnash.engine.message.ChannelEvent) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Budget(jgnash.engine.budget.Budget) ResourceBundle(java.util.ResourceBundle) MessageChannel(jgnash.engine.message.MessageChannel) MessageListener(jgnash.engine.message.MessageListener) ButtonBar(javafx.scene.control.ButtonBar) StaticUIMethods(jgnash.uifx.StaticUIMethods) TextInputDialog(jgnash.uifx.control.TextInputDialog) FXMLUtils(jgnash.uifx.util.FXMLUtils) Logger(java.util.logging.Logger) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) Optional(java.util.Optional) Collections(java.util.Collections) Message(jgnash.engine.message.Message) ArrayList(java.util.ArrayList) Budget(jgnash.engine.budget.Budget) Engine(jgnash.engine.Engine) FXML(javafx.fxml.FXML)

Example 3 with Message

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);
        }
    });
}
Also used : MessageBus(jgnash.engine.message.MessageBus) Message(jgnash.engine.message.Message) Engine(jgnash.engine.Engine)

Example 4 with 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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 5 with Message

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();
    }
}
Also used : Message(jgnash.engine.message.Message)

Aggregations

Message (jgnash.engine.message.Message)46 MessageBus (jgnash.engine.message.MessageBus)9 List (java.util.List)7 Objects (java.util.Objects)7 MessageChannel (jgnash.engine.message.MessageChannel)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ResourceBundle (java.util.ResourceBundle)6 Level (java.util.logging.Level)6 Logger (java.util.logging.Logger)6 ResourceUtils (jgnash.util.ResourceUtils)6 BigDecimal (java.math.BigDecimal)5 Optional (java.util.Optional)5 ExecutionException (java.util.concurrent.ExecutionException)5 Budget (jgnash.engine.budget.Budget)5 ChannelEvent (jgnash.engine.message.ChannelEvent)5 MessageProperty (jgnash.engine.message.MessageProperty)5 LocalDate (java.time.LocalDate)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4