use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class ExchangeRateTimeSeriesImpl method lookupRate.
@Override
public Optional<ExchangeRate> lookupRate(LocalDate requestedTime) {
if (rates.isEmpty())
return Optional.empty();
ExchangeRate r = new ExchangeRate(requestedTime, BigDecimal.ZERO);
int index = Collections.binarySearch(rates, r);
if (index >= 0)
return Optional.of(rates.get(index));
else if (// requested is date before first rate
index == -1)
return Optional.of(rates.get(0));
else
return Optional.of(rates.get(-index - 2));
}
use of name.abuchen.portfolio.money.ExchangeRate in project portfolio by buchen.
the class AbstractNodeTreeViewer method addAdditionalColumns.
protected // NOSONAR
void addAdditionalColumns(// NOSONAR
ShowHideColumnHelper support) {
// $NON-NLS-1$
Column column = new Column("exchangeRate", Messages.ColumnExchangeRate, SWT.RIGHT, 80);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new // NOSONAR
ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (!node.isAssignment())
return null;
String baseCurrency = node.getAssignment().getInvestmentVehicle().getCurrencyCode();
if (baseCurrency == null)
return null;
CurrencyConverter converter = getModel().getCurrencyConverter();
ExchangeRate rate = converter.getRate(LocalDate.now(), baseCurrency);
if (useIndirectQuotation)
rate = rate.inverse();
return Values.ExchangeRate.format(rate.getValue());
}
@Override
public String getToolTipText(Object e) {
String text = getText(e);
if (text == null)
return null;
String term = getModel().getCurrencyConverter().getTermCurrency();
String base = ((TaxonomyNode) e).getAssignment().getInvestmentVehicle().getCurrencyCode();
return text + ' ' + (useIndirectQuotation ? base + '/' + term : term + '/' + base);
}
});
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("actBaseCurrency", Messages.ColumnActualValue + Messages.BaseCurrencyCue, SWT.RIGHT, 100);
column.setDescription(Messages.ColumnActualValueBaseCurrency);
column.setGroupLabel(Messages.ColumnForeignCurrencies);
column.setLabelProvider(new // NOSONAR
ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.isClassification() || getModel().getCurrencyCode().equals(node.getAssignment().getInvestmentVehicle().getCurrencyCode())) {
return Values.Money.format(node.getActual(), getModel().getCurrencyCode());
} else if (node.getAssignment().getInvestmentVehicle().getCurrencyCode() != null) {
// currency code (e.g. is not an stock market index)
return Values.Money.format(getModel().getCurrencyConverter().with(node.getAssignment().getInvestmentVehicle().getCurrencyCode()).convert(LocalDate.now(), node.getActual()), getModel().getCurrencyCode());
} else {
return null;
}
}
});
column.setVisible(false);
support.addColumn(column);
//
getModel().getClient().getSettings().getAttributeTypes().filter(//
a -> a.supports(Security.class)).forEach(attribute -> {
Column col = new AttributeColumn(attribute);
col.setVisible(false);
col.setSorter(null);
col.getEditingSupport().addListener(this);
support.addColumn(col);
});
}
use of name.abuchen.portfolio.money.ExchangeRate 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