use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountListComboBox method messagePosted.
@Override
public void messagePosted(final Message event) {
EventQueue.invokeLater(() -> {
if (event.getEvent() == ChannelEvent.FILE_CLOSING) {
MessageBus.getInstance().unregisterListener(AccountListComboBox.this, MessageChannel.ACCOUNT, MessageChannel.SYSTEM);
((AbstractModel) getModel()).messagePosted(event);
} else {
Account account = getSelectedAccount();
((AbstractModel) getModel()).messagePosted(event);
if (account != null && event.getEvent() != ChannelEvent.ACCOUNT_REMOVE && !account.equals(event.getObject(MessageProperty.ACCOUNT))) {
setSelectedAccount(account);
} else {
if (getModel().getSize() > 0) {
setSelectedIndex(0);
}
}
}
});
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class AccountSecurityComboBox method messagePosted.
@Override
public void messagePosted(final Message event) {
final Account a = event.getObject(MessageProperty.ACCOUNT);
if (account.equals(a)) {
final SecurityNode node = event.getObject(MessageProperty.COMMODITY);
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case ACCOUNT_REMOVE:
MessageBus.getInstance().unregisterListener(AccountSecurityComboBox.this, MessageChannel.ACCOUNT, MessageChannel.COMMODITY);
model.removeAllElements();
account = null;
break;
case ACCOUNT_SECURITY_ADD:
model.addElement(node);
break;
case SECURITY_REMOVE:
case ACCOUNT_SECURITY_REMOVE:
final CommodityNode commodityNode = getSelectedNode();
model.removeElement(node);
if (commodityNode != null && node != null) {
if (commodityNode.equals(node)) {
setSelectedItem(null);
}
}
break;
case SECURITY_MODIFY:
updateNode(node);
break;
default:
}
});
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class ImportTwo method getSettings.
@Override
@SuppressWarnings("unchecked")
public void getSettings(final Map<Enum<?>, Object> map) {
ImportBank<ImportTransaction> bank = (ImportBank<ImportTransaction>) map.get(ImportDialog.Settings.BANK);
if (bank != null) {
List<ImportTransaction> list = bank.getTransactions();
Account account = (Account) map.get(ImportDialog.Settings.ACCOUNT);
// set to sane account assuming it's going to be a single entry
for (ImportTransaction t : list) {
t.setAccount(account);
t.setState(ImportState.NEW);
}
// match up any pre-existing transactions
GenericImport.matchTransactions(list, account);
// classify the transactions
BayesImportClassifier.classifyTransactions(list, account.getSortedTransactionList(), account);
table.setTransactions(list);
refreshInfo();
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class NewFileUtility method buildNewFile.
public static void buildNewFile(final String fileName, final DataStoreType dataStoreType, final char[] password, final CurrencyNode currencyNode, final Collection<CurrencyNode> currencyNodes, final Collection<RootAccount> rootAccountCollection) throws IOException {
final ResourceBundle resources = ResourceUtils.getBundle();
// have to close the engine first
EngineFactory.closeEngine(EngineFactory.DEFAULT);
// try to delete any existing database
if (Files.exists(Paths.get(fileName))) {
if (!EngineFactory.deleteDatabase(fileName)) {
throw new IOException(ResourceUtils.getString("Message.Error.DeleteExistingFile", fileName));
}
}
// create the directory if needed
Files.createDirectories(Paths.get(fileName).getParent());
final Engine e = EngineFactory.bootLocalEngine(fileName, EngineFactory.DEFAULT, password, dataStoreType);
CurrencyNode defaultCurrency = currencyNode;
// creation of a duplicate currency
if (e.getDefaultCurrency().matches(defaultCurrency)) {
defaultCurrency = e.getDefaultCurrency();
}
// make sure a duplicate default is not added
for (final CurrencyNode node : currencyNodes) {
if (!node.matches(defaultCurrency)) {
e.addCurrency(node);
}
}
if (!defaultCurrency.equals(e.getDefaultCurrency())) {
e.setDefaultCurrency(defaultCurrency);
}
if (!rootAccountCollection.isEmpty()) {
// import account sets
for (final RootAccount root : rootAccountCollection) {
AccountTreeXMLFactory.importAccountTree(e, root);
}
} else {
// none selected, create a very basic account set
final RootAccount root = e.getRootAccount();
final Account bank = new Account(AccountType.BANK, defaultCurrency);
bank.setDescription(resources.getString("Name.BankAccounts"));
bank.setName(resources.getString("Name.BankAccounts"));
e.addAccount(root, bank);
final Account income = new Account(AccountType.INCOME, defaultCurrency);
income.setDescription(resources.getString("Name.IncomeAccounts"));
income.setName(resources.getString("Name.IncomeAccounts"));
e.addAccount(root, income);
final Account expense = new Account(AccountType.EXPENSE, defaultCurrency);
expense.setDescription(resources.getString("Name.ExpenseAccounts"));
expense.setName(resources.getString("Name.ExpenseAccounts"));
e.addAccount(root, expense);
}
}
use of jgnash.engine.Account in project jgnash by ccavanaugh.
the class ApiTest method testMove.
@Test
public void testMove() {
Account test = new Account(AccountType.ASSET, e.getDefaultCurrency());
test.setName("Test");
assertTrue(e.addAccount(e.getRootAccount(), test));
assertTrue(e.getRootAccount().contains(test));
assertTrue(e.moveAccount(test, usdBankAccount));
assertFalse(e.getRootAccount().contains(test));
assertTrue(usdBankAccount.contains(test));
}
Aggregations