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);
}
}
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()));
}
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;
}
Aggregations