Search in sources :

Example 6 with ExchangeRateTimeSeries

use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.

the class AccountTransactionModel method updateExchangeRate.

private void updateExchangeRate() {
    // transaction
    if (sourceTransaction != null)
        return;
    if (getAccountCurrencyCode().equals(getSecurityCurrencyCode())) {
        setExchangeRate(BigDecimal.ONE);
    } else if (!getSecurityCurrencyCode().isEmpty()) {
        ExchangeRateTimeSeries series = // 
        getExchangeRateProviderFactory().getTimeSeries(getSecurityCurrencyCode(), getAccountCurrencyCode());
        if (series != null)
            setExchangeRate(series.lookupRate(date).orElse(new ExchangeRate(date, BigDecimal.ONE)).getValue());
        else
            setExchangeRate(BigDecimal.ONE);
    }
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries)

Example 7 with ExchangeRateTimeSeries

use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.

the class ExchangeRatesListView method createTopTable.

@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    TableViewer indeces = new TableViewer(container, SWT.FULL_SELECTION);
    ShowHideColumnHelper support = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    ExchangeRatesListView.class.getSimpleName() + "@top2", getPreferenceStore(), indeces, layout);
    Column column = new Column(Messages.ColumnBaseCurrency, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ExchangeRateTimeSeries) element).getBaseCurrency();
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ExchangeRateTimeSeries.class, "baseCurrency", "termCurrency").attachTo(column, SWT.DOWN);
    support.addColumn(column);
    column = new Column(Messages.ColumnTermCurrency, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ExchangeRateTimeSeries) element).getTermCurrency();
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ExchangeRateTimeSeries.class, "termCurrency", "baseCurrency").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnCurrencyProvider, SWT.None, 150);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ExchangeRateTimeSeries) element).getProvider().getName();
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(ExchangeRateTimeSeries.class, "provider").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnDateLatestExchangeRate, SWT.None, 150);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            ExchangeRateTimeSeries series = (ExchangeRateTimeSeries) element;
            List<ExchangeRate> rates = series.getRates();
            return rates.isEmpty() ? null : Values.Date.format(rates.get(rates.size() - 1).getTime());
        }
    });
    ColumnViewerSorter.create(element -> {
        ExchangeRateTimeSeries series = (ExchangeRateTimeSeries) element;
        List<ExchangeRate> rates = series.getRates();
        return rates.isEmpty() ? null : rates.get(rates.size() - 1).getTime();
    }).attachTo(column);
    support.addColumn(column);
    support.createColumns();
    indeces.getTable().setHeaderVisible(true);
    indeces.getTable().setLinesVisible(true);
    indeces.setContentProvider(ArrayContentProvider.getInstance());
    indeces.setInput(providerFactory.getAvailableTimeSeries());
    indeces.refresh();
    indeces.addSelectionChangedListener(event -> refreshChart((ExchangeRateTimeSeries) ((IStructuredSelection) event.getSelection()).getFirstElement()));
}
Also used : Values(name.abuchen.portfolio.money.Values) TableViewer(org.eclipse.jface.viewers.TableViewer) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) DecimalFormat(java.text.DecimalFormat) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) ISeries(org.swtchart.ISeries) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) Inject(javax.inject.Inject) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) Column(name.abuchen.portfolio.ui.util.viewers.Column) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) List(java.util.List) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 8 with ExchangeRateTimeSeries

use of name.abuchen.portfolio.money.ExchangeRateTimeSeries in project portfolio by buchen.

the class ExchangeRateWidget method createControl.

@Override
public Composite createControl(Composite parent, DashboardResources resources) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setBackground(parent.getBackground());
    GridLayoutFactory.fillDefaults().numColumns(1).margins(5, 5).applyTo(container);
    title = new Label(container, SWT.NONE);
    title.setText(getWidget().getLabel());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(title);
    indicator = new Label(container, SWT.NONE);
    indicator.setFont(resources.getKpiFont());
    // $NON-NLS-1$
    indicator.setText("");
    GridDataFactory.fillDefaults().grab(true, false).applyTo(indicator);
    InfoToolTip.attach(indicator, () -> {
        ReportingPeriod period = get(ReportingPeriodConfig.class).getReportingPeriod();
        ExchangeRateTimeSeries series = get(ExchangeRateSeriesConfig.class).getSeries();
        Optional<ExchangeRate> rate = series.lookupRate(period.getEndDate());
        return rate.isPresent() ? MessageFormat.format(Messages.TooltipDateOfExchangeRate, formatter.format(rate.get().getTime())) : // $NON-NLS-1$
        "";
    });
    return container;
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) Composite(org.eclipse.swt.widgets.Composite) ExchangeRateTimeSeries(name.abuchen.portfolio.money.ExchangeRateTimeSeries) Label(org.eclipse.swt.widgets.Label)

Aggregations

ExchangeRateTimeSeries (name.abuchen.portfolio.money.ExchangeRateTimeSeries)8 ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)5 ExchangeRateProviderFactory (name.abuchen.portfolio.money.ExchangeRateProviderFactory)4 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)2 Composite (org.eclipse.swt.widgets.Composite)2 DecimalFormat (java.text.DecimalFormat)1 MessageFormat (java.text.MessageFormat)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Values (name.abuchen.portfolio.money.Values)1 Messages (name.abuchen.portfolio.ui.Messages)1 Colors (name.abuchen.portfolio.ui.util.Colors)1 TimelineChart (name.abuchen.portfolio.ui.util.chart.TimelineChart)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 ColumnViewerSorter (name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter)1 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1