Search in sources :

Example 21 with ExchangeRate

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));
}
Also used : ExchangeRate(name.abuchen.portfolio.money.ExchangeRate)

Example 22 with ExchangeRate

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);
    });
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Arrays(java.util.Arrays) DND(org.eclipse.swt.dnd.DND) Classification(name.abuchen.portfolio.model.Classification) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) UIConstants(name.abuchen.portfolio.ui.UIConstants) Separator(org.eclipse.jface.action.Separator) Predicate(java.util.function.Predicate) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) UUID(java.util.UUID) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TransferData(org.eclipse.swt.dnd.TransferData) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) TreeSelection(org.eclipse.jface.viewers.TreeSelection) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) LinkedList(java.util.LinkedList) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) Viewer(org.eclipse.jface.viewers.Viewer) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) Action(org.eclipse.jface.action.Action) TreeViewerCSVExporter(name.abuchen.portfolio.ui.util.TreeViewerCSVExporter) Preference(org.eclipse.e4.core.di.extensions.Preference) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Named(name.abuchen.portfolio.model.Named) StringJoiner(java.util.StringJoiner) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ToolTip(org.eclipse.jface.window.ToolTip) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Assignment(name.abuchen.portfolio.model.Classification.Assignment) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 23 with ExchangeRate

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;
}
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

ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)23 Test (org.junit.Test)8 ExchangeRateTimeSeries (name.abuchen.portfolio.money.ExchangeRateTimeSeries)6 BigDecimal (java.math.BigDecimal)5 LocalDate (java.time.LocalDate)5 HashMap (java.util.HashMap)3 List (java.util.List)3 Column (name.abuchen.portfolio.ui.util.viewers.Column)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 MessageFormat (java.text.MessageFormat)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Inject (javax.inject.Inject)2 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)2 Values (name.abuchen.portfolio.money.Values)2 Messages (name.abuchen.portfolio.ui.Messages)2 Colors (name.abuchen.portfolio.ui.util.Colors)2 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)2