use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class SecurityModifyPanel method buildSecurityNode.
private SecurityNode buildSecurityNode() {
SecurityNode node = new SecurityNode(currencyCombo.getSelectedNode());
node.setDescription(descriptionField.getText());
node.setScale(Byte.parseByte(scaleField.getText()));
node.setSymbol(symbolField.getText().trim());
node.setISIN(isinField.getText().trim());
node.setQuoteSource((QuoteSource) sourceComboBox.getSelectedItem());
return node;
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class SecurityModifyPanel method updateForm.
private void updateForm() {
SecurityNode node = securityList.getSelectedValue();
if (node != null) {
symbolField.setText(node.getSymbol());
isinField.setText(node.getISIN());
descriptionField.setText(node.getDescription());
scaleField.setText(Short.toString(node.getScale()));
currencyCombo.setSelectedNode(node.getReportedCurrencyNode());
sourceComboBox.setSelectedItem(node.getQuoteSource());
isModifying = true;
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class AbstractRegisterPanel method messagePosted.
@Override
public void messagePosted(final Message event) {
final Account account = getAccount();
// must update on EDT or a deadlock can occur
EventQueue.invokeLater(() -> {
Account a = event.getObject(MessageProperty.ACCOUNT);
if (account.equals(a)) {
switch(event.getEvent()) {
case ACCOUNT_MODIFY:
updateAccountState();
updateAccountInfo();
break;
case TRANSACTION_ADD:
final Transaction t = event.getObject(MessageProperty.TRANSACTION);
final int index = account.indexOf(t);
if (index == account.getTransactionCount() - 1) {
autoScroll();
}
setSelectedTransaction(t);
updateAccountInfo();
break;
case TRANSACTION_REMOVE:
updateAccountInfo();
break;
default:
break;
}
}
if (event.getEvent() == ChannelEvent.SECURITY_HISTORY_ADD || event.getEvent() == ChannelEvent.SECURITY_HISTORY_REMOVE) {
SecurityNode node = event.getObject(MessageProperty.COMMODITY);
if (account.containsSecurity(node)) {
updateAccountInfo();
}
}
});
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class GenericImport method importSecurities.
public static void importSecurities(final List<ImportSecurity> importSecurities, final CurrencyNode currencyNode) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (final ImportSecurity importSecurity : importSecurities) {
if (ImportUtils.matchSecurity(importSecurity).isEmpty()) {
// Import only if a match is not found
final SecurityNode securityNode = ImportUtils.createSecurityNode(importSecurity, currencyNode);
// link the security node
importSecurity.setSecurityNode(securityNode);
engine.addSecurity(securityNode);
// if the ImportSecurity has pricing information, import it as well
importSecurity.getLocalDate().ifPresent(localDate -> importSecurity.getUnitPrice().ifPresent(price -> {
SecurityHistoryNode securityHistoryNode = new SecurityHistoryNode(localDate, price, 0, price, price);
engine.addSecurityHistory(securityNode, securityHistoryNode);
}));
} else {
// check to see if the cuspid needs to be updated
// link the security node
ImportUtils.matchSecurity(importSecurity).ifPresent(importSecurity::setSecurityNode);
ImportUtils.matchSecurity(importSecurity).ifPresent(securityNode -> importSecurity.getId().ifPresent(securityId -> {
if (securityNode.getISIN() == null || securityNode.getISIN().isEmpty()) {
try {
final SecurityNode clone = (SecurityNode) securityNode.clone();
clone.setISIN(securityId);
engine.updateCommodity(securityNode, clone);
Logger.getLogger(GenericImport.class.getName()).info("Assigning CUSPID");
} catch (final CloneNotSupportedException e) {
Logger.getLogger(GenericImport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
}));
}
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class ImportUtils method matchSecurity.
static Optional<SecurityNode> matchSecurity(final ImportSecurity security) {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
for (final SecurityNode securityNode : engine.getSecurities()) {
if (securityNode.getSymbol().equals(security.getTicker())) {
return Optional.of(securityNode);
}
}
return Optional.empty();
}
Aggregations