Search in sources :

Example 6 with SecurityNode

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:
            }
        });
    }
}
Also used : Account(jgnash.engine.Account) SecurityNode(jgnash.engine.SecurityNode) CommodityNode(jgnash.engine.CommodityNode)

Example 7 with SecurityNode

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());
    }
}
Also used : AbstractXYDataset(org.jfree.data.xy.AbstractXYDataset) SecurityNode(jgnash.engine.SecurityNode) JFreeChart(org.jfree.chart.JFreeChart)

Example 8 with SecurityNode

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);
                    }
                }
            }));
        }
    }
}
Also used : Engine(jgnash.engine.Engine) DateUtils(jgnash.time.DateUtils) NotNull(jgnash.util.NotNull) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Transaction(jgnash.engine.Transaction) EngineFactory(jgnash.engine.EngineFactory) Logger(java.util.logging.Logger) SecurityNode(jgnash.engine.SecurityNode) Level(java.util.logging.Level) AccountGroup(jgnash.engine.AccountGroup) Objects(java.util.Objects) List(java.util.List) LocalDate(java.time.LocalDate) Account(jgnash.engine.Account) CurrencyNode(jgnash.engine.CurrencyNode) TransactionFactory(jgnash.engine.TransactionFactory) SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) Engine(jgnash.engine.Engine)

Example 9 with SecurityNode

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]);
        }
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode) SecurityHistoryNode(jgnash.engine.SecurityHistoryNode) LocalDate(java.time.LocalDate) Engine(jgnash.engine.Engine)

Example 10 with SecurityNode

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());
    }
}
Also used : SecurityNode(jgnash.engine.SecurityNode) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

SecurityNode (jgnash.engine.SecurityNode)39 Engine (jgnash.engine.Engine)12 Account (jgnash.engine.Account)10 SecurityHistoryNode (jgnash.engine.SecurityHistoryNode)8 LocalDate (java.time.LocalDate)7 ArrayList (java.util.ArrayList)6 AbstractEngineTest (jgnash.engine.AbstractEngineTest)6 Test (org.junit.jupiter.api.Test)6 CurrencyNode (jgnash.engine.CurrencyNode)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 List (java.util.List)4 QuoteSource (jgnash.engine.QuoteSource)4 SecurityParser (jgnash.net.security.SecurityParser)4 FXML (javafx.fxml.FXML)3 InvestmentTransaction (jgnash.engine.InvestmentTransaction)3 SecurityHistoryEvent (jgnash.engine.SecurityHistoryEvent)3 Transaction (jgnash.engine.Transaction)3 IEXParser (jgnash.net.security.iex.IEXParser)3 InjectFXML (jgnash.uifx.util.InjectFXML)3 NotNull (jgnash.util.NotNull)3