Search in sources :

Example 41 with Message

use of jgnash.engine.message.Message in project jgnash by ccavanaugh.

the class Engine method removeCommodity.

public boolean removeCommodity(final CurrencyNode node) {
    boolean status = true;
    dataLock.writeLock().lock();
    try {
        if (isCommodityNodeUsed(node)) {
            status = false;
        } else {
            clearObsoleteExchangeRates();
            moveObjectToTrash(node);
        }
        Message message;
        if (status) {
            message = new Message(MessageChannel.COMMODITY, ChannelEvent.CURRENCY_REMOVE, this);
        } else {
            message = new Message(MessageChannel.COMMODITY, ChannelEvent.CURRENCY_REMOVE_FAILED, this);
        }
        message.setObject(MessageProperty.COMMODITY, node);
        messageBus.fireEvent(message);
        return status;
    } finally {
        dataLock.writeLock().unlock();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 42 with Message

use of jgnash.engine.message.Message in project jgnash by ccavanaugh.

the class Engine method postTransactionRemove.

private void postTransactionRemove(final Transaction transaction, final boolean result) {
    for (Account a : transaction.getAccounts()) {
        Message message;
        if (result) {
            message = new Message(MessageChannel.TRANSACTION, ChannelEvent.TRANSACTION_REMOVE, this);
        } else {
            message = new Message(MessageChannel.TRANSACTION, ChannelEvent.TRANSACTION_REMOVE_FAILED, this);
        }
        message.setObject(MessageProperty.ACCOUNT, a);
        message.setObject(MessageProperty.TRANSACTION, transaction);
        messageBus.fireEvent(message);
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 43 with Message

use of jgnash.engine.message.Message in project jgnash by ccavanaugh.

the class Engine method setAccountNumber.

/**
     * Sets the account number of an account.
     *
     * @param account account to change
     * @param number  new account number
     */
public void setAccountNumber(final Account account, final String number) {
    dataLock.writeLock().lock();
    try {
        account.setAccountNumber(number);
        getAccountDAO().updateAccount(account);
        Message message = new Message(MessageChannel.ACCOUNT, ChannelEvent.ACCOUNT_MODIFY, this);
        message.setObject(MessageProperty.ACCOUNT, account);
        messageBus.fireEvent(message);
        logInfo(rb.getString("Message.AccountModify"));
    } finally {
        dataLock.writeLock().unlock();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 44 with Message

use of jgnash.engine.message.Message in project jgnash by ccavanaugh.

the class Engine method setPreference.

public void setPreference(@NotNull final String key, @Nullable final String value) {
    dataLock.writeLock().lock();
    try {
        getConfig().setPreference(key, value);
        getConfigDAO().update(getConfig());
        // clear stale cached reference
        config = null;
        Message message = new Message(MessageChannel.CONFIG, ChannelEvent.CONFIG_MODIFY, this);
        message.setObject(MessageProperty.CONFIG, getConfig());
        messageBus.fireEvent(message);
    } finally {
        dataLock.writeLock().unlock();
    }
}
Also used : Message(jgnash.engine.message.Message)

Example 45 with Message

use of jgnash.engine.message.Message in project jgnash by ccavanaugh.

the class BudgetManagerDialog method deleteBudget.

private void deleteBudget() {
    Engine e = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(e);
    List<BudgetObject> values = budgetList.getSelectedValuesList();
    if (!values.isEmpty()) {
        String message = values.size() == 1 ? rb.getString("Message.ConfirmBudgetDelete") : rb.getString("Message.ConfirmMultipleBudgetDelete");
        if (YesNoDialog.showYesNoDialog(UIApplication.getFrame(), new JLabel(message), rb.getString("Title.Confirm"))) {
            values.stream().filter(value -> !e.removeBudget(value.getBudget())).forEach(value -> StaticUIMethods.displayError(rb.getString("Message.Error.BudgetRemove")));
        }
    }
}
Also used : DialogUtils(jgnash.ui.util.DialogUtils) Engine(jgnash.engine.Engine) SortedListModel(jgnash.ui.components.SortedListModel) ActionListener(java.awt.event.ActionListener) JDialog(javax.swing.JDialog) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder) EngineFactory(jgnash.engine.EngineFactory) IconUtils(jgnash.ui.util.IconUtils) ResourceUtils(jgnash.util.ResourceUtils) MessageBus(jgnash.engine.message.MessageBus) StaticUIMethods(jgnash.ui.StaticUIMethods) ChannelEvent(jgnash.engine.message.ChannelEvent) Level(java.util.logging.Level) Budget(jgnash.engine.budget.Budget) ResourceBundle(java.util.ResourceBundle) MessageChannel(jgnash.engine.message.MessageChannel) CellConstraints(com.jgoodies.forms.layout.CellConstraints) BorderLayout(java.awt.BorderLayout) MessageListener(jgnash.engine.message.MessageListener) EventQueue(java.awt.EventQueue) JButton(javax.swing.JButton) NotNull(jgnash.util.NotNull) JList(javax.swing.JList) Logger(java.util.logging.Logger) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) Objects(java.util.Objects) JScrollPane(javax.swing.JScrollPane) ButtonStackBuilder(com.jgoodies.forms.builder.ButtonStackBuilder) List(java.util.List) YesNoDialog(jgnash.ui.components.YesNoDialog) FormLayout(com.jgoodies.forms.layout.FormLayout) JLabel(javax.swing.JLabel) UIApplication(jgnash.ui.UIApplication) WindowConstants(javax.swing.WindowConstants) Message(jgnash.engine.message.Message) Borders(com.jgoodies.forms.factories.Borders) JLabel(javax.swing.JLabel) Engine(jgnash.engine.Engine)

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