use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class JpaCommodityDAO method getSecurities.
/*
* @see jgnash.engine.dao.CommodityDAO#getSecurities()
*/
@Override
@NotNull
public List<SecurityNode> getSecurities() {
List<SecurityNode> securityNodeList = Collections.emptyList();
try {
Future<List<SecurityNode>> future = executorService.submit(() -> {
emLock.lock();
try {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<SecurityNode> cq = cb.createQuery(SecurityNode.class);
Root<SecurityNode> root = cq.from(SecurityNode.class);
cq.select(root);
TypedQuery<SecurityNode> q = em.createQuery(cq);
return stripMarkedForRemoval(new ArrayList<>(q.getResultList()));
} finally {
emLock.unlock();
}
});
securityNodeList = future.get();
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return securityNodeList;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class AccountSecuritiesPanel method setSecuritiesList.
void setSecuritiesList(final Set<SecurityNode> list) {
selectedModel = new SortedListModel<>();
if (account != null) {
Set<SecurityNode> used = account.getUsedSecurities();
for (SecurityNode node : list) {
if (used.contains(node)) {
selectedModel.addElement(new SecurityElement(node, false));
} else {
selectedModel.addElement(new SecurityElement(node, true));
}
}
} else {
for (SecurityNode node : list) {
selectedModel.addElement(new SecurityElement(node, true));
}
}
selectedJList.setModel(selectedModel);
buildAvailableList();
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class AccountTools method createAccount.
static void createAccount(final Account account) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
Account parentAccount = account;
final ResourceBundle rb = ResourceUtils.getBundle();
if (parentAccount == null) {
parentAccount = engine.getRootAccount();
if (parentAccount == null) {
// no root account at all, file was closed
return;
}
}
AccountDialog dlg = new AccountDialog();
dlg.setParentAccount(parentAccount);
dlg.setAccountType(parentAccount.getAccountType());
dlg.setTitle(rb.getString("Title.NewAccount"));
dlg.setVisible(true);
if (dlg.returnStatus()) {
CurrencyNode currency = dlg.getCurrency();
AccountType accType = dlg.getAccountType();
if (currency == null) {
currency = engine.getRootAccount().getCurrencyNode();
Logger.getLogger(AccountTools.class.getName()).warning("Forcing use of the default currency");
}
Account newAccount = new Account(accType, currency);
if (accType.getAccountGroup() == AccountGroup.INVEST) {
Collection<SecurityNode> collection = dlg.getAccountSecurities();
collection.forEach(newAccount::addSecurity);
}
newAccount.setName(dlg.getAccountName());
newAccount.setAccountCode(dlg.getAccountCode());
newAccount.setAccountNumber(dlg.getAccountNumber());
newAccount.setBankId(dlg.getBankId());
newAccount.setDescription(dlg.getAccountDescription());
newAccount.setNotes(dlg.getAccountNotes());
newAccount.setLocked(dlg.isAccountLocked());
newAccount.setPlaceHolder(dlg.isAccountPlaceholder());
newAccount.setVisible(dlg.isAccountVisible());
newAccount.setExcludedFromBudget(dlg.isExcludedFromBudget());
engine.addAccount(dlg.getParentAccount(), newAccount);
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class AccountPanel method updateCommodityText.
private void updateCommodityText() {
if (!commodityList.isEmpty()) {
StringBuilder buf = new StringBuilder();
Iterator<SecurityNode> it = commodityList.iterator();
SecurityNode node = it.next();
buf.append(node.getSymbol());
while (it.hasNext()) {
buf.append(", ");
node = it.next();
buf.append(node.getSymbol());
}
securityButton.setText(buf.toString());
securityButton.setToolTipText(buf.toString());
} else {
securityButton.setText(rb.getString("Word.None"));
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class YahooSecurityHistoryImportDialog method doImport.
private void doImport() {
bar.setIndeterminate(true);
// do not allow another start
okButton.setEnabled(false);
final LocalDate start = startField.getLocalDate();
final LocalDate end = endField.getLocalDate();
int[] list = securityList.getSelectedIndices();
SecurityNode[] nodes = new SecurityNode[list.length];
for (int i = 0; i < list.length; i++) {
nodes[i] = securityList.getModel().getElementAt(list[i]);
}
// create the runnable and start the thread
run = new ImportRun(nodes, start, end);
new Thread(run, "doImport").start();
}
Aggregations