use of jgnash.engine.SecurityNode 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.SecurityNode in project jgnash by ccavanaugh.
the class SecurityHighLowChart method updateChart.
private void updateChart() {
try {
SecurityNode sNode = combo.getSelectedSecurityNode();
if (sNode != null) {
final AbstractXYDataset dataSet = createHighLowDataSet(sNode);
JFreeChart chart = createHighLowChart(sNode.getDescription(), rb.getString("Column.Date"), rb.getString("Column.Price"), dataSet, false);
chart.setBackgroundPaint(null);
chartPanel.setChart(chart);
chartPanel.validate();
}
} catch (Exception ex) {
Logger.getAnonymousLogger().severe(ex.toString());
}
}
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).isPresent()) {
// 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 SecuritiesHistoryDialog method removeNode.
/**
* Delete the history nodes selected in the table model
*/
private void removeNode() {
SecurityNode node = securityCombo.getSelectedSecurityNode();
int[] selection = table.getSelectedRows();
for (int i = 0; i < selection.length; i++) {
selection[i] = table.convertRowIndexToModel(selection[i]);
}
List<SecurityHistoryNode> history = node.getHistoryNodes();
/* Capture a list of references */
LocalDate[] temp = new LocalDate[selection.length];
for (int i = 0; i < selection.length; i++) {
temp[i] = history.get(selection[i]).getLocalDate();
}
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
if (engine != null) {
for (int i = selection.length - 1; i >= 0; i--) {
engine.removeSecurityHistory(node, temp[i]);
}
}
}
use of jgnash.engine.SecurityNode in project jgnash by ccavanaugh.
the class SecuritiesHistoryDialog method updateChart.
private void updateChart() {
try {
final SecurityNode sNode = securityCombo.getSelectedSecurityNode();
final JFreeChart chart = createChart(sNode);
chartPanel.setChart(chart);
chartPanel.validate();
} catch (final Exception ex) {
Logger.getLogger(SecuritiesHistoryDialog.class.getName()).severe(ex.toString());
}
}
Aggregations