use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class ProfitLossTXT method run.
public void run() {
final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
Objects.requireNonNull(engine);
final CurrencyNode baseCommodity = engine.getDefaultCurrency();
final LocalDate[] dates = getDates();
if (dates != null) {
final String fileName = getFileName();
ProfitLossTextReport report = new ProfitLossTextReport(fileName, dates[0], dates[1], baseCommodity, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
report.run();
}
}
use of jgnash.engine.CurrencyNode 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.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyExchangeDialog method addExchangeRate.
private void addExchangeRate() {
if (validateForm()) {
CurrencyNode src = baseCurrencyCombo.getSelectedNode();
CurrencyNode dst = exchangeCurrencyCombo.getSelectedNode();
getEngine().setExchangeRate(src, dst, rateField.getDecimal(), dateField.getLocalDate());
clearForm();
}
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyExchangeDialog method getSelectedExchangeRate.
private ExchangeRate getSelectedExchangeRate() {
CurrencyNode src = baseCurrencyCombo.getSelectedNode();
CurrencyNode dst = exchangeCurrencyCombo.getSelectedNode();
return getEngine().getExchangeRate(src, dst);
}
use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.
the class CurrencyModifyDialog method messagePosted.
@Override
public void messagePosted(final Message event) {
final CommodityNode node = event.getObject(MessageProperty.COMMODITY);
if (node instanceof CurrencyNode) {
EventQueue.invokeLater(() -> {
switch(event.getEvent()) {
case CURRENCY_REMOVE:
model.removeElement((CurrencyNode) node);
if (currentCurrency.equals(node)) {
clearForm();
}
break;
case CURRENCY_REMOVE_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Warn.CurrencyInUse"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
case CURRENCY_ADD:
clearForm();
model.addElement((CurrencyNode) node);
break;
case CURRENCY_ADD_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.AddCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
case CURRENCY_MODIFY:
// node will be stale
model.removeElement((CurrencyNode) node);
model.addElement(getEngine().getCurrency(node.getSymbol()));
if (currentCurrency.equals(node)) {
updateForm();
}
break;
case CURRENCY_MODIFY_FAILED:
JOptionPane.showMessageDialog(CurrencyModifyDialog.this, rb.getString("Message.Error.ModifyCurrency"), rb.getString("Title.Error"), JOptionPane.ERROR_MESSAGE);
break;
default:
break;
}
});
}
}
Aggregations