Search in sources :

Example 1 with NumberColorLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider in project portfolio by buchen.

the class SecuritiesPerformanceView method addPerformanceColumns.

private void addPerformanceColumns() {
    // $NON-NLS-1$
    Column column = new Column("twror", Messages.ColumnTWROR, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setMenuLabel(Messages.ColumnTWROR_Description);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, r -> ((SecurityPerformanceRecord) r).getTrueTimeWeightedRateOfReturn()));
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "trueTimeWeightedRateOfReturn"));
    recordColumns.addColumn(column);
    // internal rate of return
    // $NON-NLS-1$
    column = new Column("izf", Messages.ColumnIRR, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setMenuLabel(Messages.ColumnIRR_MenuLabel);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, r -> ((SecurityPerformanceRecord) r).getIrr()));
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "irr"));
    recordColumns.addColumn(column);
    // $NON-NLS-1$
    column = new Column("capitalgains", Messages.ColumnCapitalGains, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setDescription(Messages.ColumnCapitalGains_Description);
    column.setLabelProvider(new MoneyColorLabelProvider(element -> ((SecurityPerformanceRecord) element).getCapitalGainsOnHoldings(), getClient().getBaseCurrency()));
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "capitalGainsOnHoldings"));
    recordColumns.addColumn(column);
    // $NON-NLS-1$
    column = new Column("capitalgains%", Messages.ColumnCapitalGainsPercent, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setDescription(Messages.ColumnCapitalGainsPercent_Description);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, r -> ((SecurityPerformanceRecord) r).getCapitalGainsOnHoldingsPercent()));
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "capitalGainsOnHoldingsPercent"));
    recordColumns.addColumn(column);
    // $NON-NLS-1$
    column = new Column("capitalgainsmvavg", Messages.ColumnCapitalGainsMovingAverage, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setMenuLabel(Messages.ColumnCapitalGainsMovingAverage_MenuLabel);
    column.setDescription(Messages.ColumnCapitalGainsMovingAverage_Description);
    column.setLabelProvider(new MoneyColorLabelProvider(element -> ((SecurityPerformanceRecord) element).getCapitalGainsOnHoldingsMovingAverage(), getClient().getBaseCurrency()));
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "capitalGainsOnHoldingsMovingAverage"));
    recordColumns.addColumn(column);
    // $NON-NLS-1$
    column = new Column("capitalgainsmvavg%", Messages.ColumnCapitalGainsMovingAveragePercent, SWT.RIGHT, 80);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setMenuLabel(Messages.ColumnCapitalGainsMovingAveragePercent_MenuLabel);
    column.setDescription(Messages.ColumnCapitalGainsMovingAveragePercent_Description);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, r -> ((SecurityPerformanceRecord) r).getCapitalGainsOnHoldingsMovingAveragePercent()));
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "capitalGainsOnHoldingsMovingAveragePercent"));
    recordColumns.addColumn(column);
    // delta
    // $NON-NLS-1$
    column = new Column("delta", Messages.ColumnAbsolutePerformance, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnAbsolutePerformance_Description);
    column.setMenuLabel(Messages.ColumnAbsolutePerformance_MenuLabel);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setLabelProvider(new MoneyColorLabelProvider(element -> ((SecurityPerformanceRecord) element).getDelta(), getClient().getBaseCurrency()));
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "delta"));
    recordColumns.addColumn(column);
    // delta percent
    // $NON-NLS-1$
    column = new Column("delta%", Messages.ColumnAbsolutePerformancePercent, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnAbsolutePerformancePercent_Description);
    column.setMenuLabel(Messages.ColumnAbsolutePerformancePercent_MenuLabel);
    column.setGroupLabel(Messages.GroupLabelPerformance);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, r -> ((SecurityPerformanceRecord) r).getDeltaPercent()));
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "deltaPercent"));
    column.setVisible(false);
    recordColumns.addColumn(column);
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) DND(org.eclipse.swt.dnd.DND) ToolBar(org.eclipse.swt.widgets.ToolBar) ReportingPeriodListener(name.abuchen.portfolio.ui.util.ReportingPeriodDropDown.ReportingPeriodListener) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Separator(org.eclipse.jface.action.Separator) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) Predicate(java.util.function.Predicate) SashLayout(name.abuchen.portfolio.ui.util.swt.SashLayout) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) DividendInitialTransaction(name.abuchen.portfolio.snapshot.security.DividendInitialTransaction) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ClientFilterMenu(name.abuchen.portfolio.ui.util.ClientFilterMenu) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) MessageFormat(com.ibm.icu.text.MessageFormat) Messages(name.abuchen.portfolio.ui.Messages) ReportingPeriodDropDown(name.abuchen.portfolio.ui.util.ReportingPeriodDropDown) MarkDirtyListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.MarkDirtyListener) Taxonomy(name.abuchen.portfolio.model.Taxonomy) DividendTransaction(name.abuchen.portfolio.snapshot.security.DividendTransaction) MoneyColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.MoneyColorLabelProvider) NumberColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SashLayoutData(name.abuchen.portfolio.ui.util.swt.SashLayoutData) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) DividendFinalTransaction(name.abuchen.portfolio.snapshot.security.DividendFinalTransaction) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) CTabItem(org.eclipse.swt.custom.CTabItem) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) IMenuManager(org.eclipse.jface.action.IMenuManager) ToolTip(org.eclipse.jface.window.ToolTip) SWTHelper(name.abuchen.portfolio.ui.util.SWTHelper) MoneyColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.MoneyColorLabelProvider) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) 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) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord)

Example 2 with NumberColorLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider in project portfolio by buchen.

the class SecuritiesTable method addDeltaColumn.

private // NOSONAR
void addDeltaColumn() {
    Column column;
    // $NON-NLS-1$
    column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 60);
    column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
    column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
        SecurityPrice price = ((Security) element).getSecurityPrice(LocalDate.now());
        if (!(price instanceof LatestSecurityPrice))
            return null;
        LatestSecurityPrice latest = (LatestSecurityPrice) price;
        if (latest.getPreviousClose() == LatestSecurityPrice.NOT_AVAILABLE)
            return null;
        return (latest.getValue() - latest.getPreviousClose()) / (double) latest.getPreviousClose();
    }));
    column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
        // NOSONAR
        SecurityPrice p1 = ((Security) o1).getSecurityPrice(LocalDate.now());
        SecurityPrice p2 = ((Security) o2).getSecurityPrice(LocalDate.now());
        if (!(p1 instanceof LatestSecurityPrice))
            p1 = null;
        if (!(p2 instanceof LatestSecurityPrice))
            p2 = null;
        if (p1 == null)
            return p2 == null ? 0 : -1;
        if (p2 == null)
            return 1;
        LatestSecurityPrice l1 = (LatestSecurityPrice) p1;
        LatestSecurityPrice l2 = (LatestSecurityPrice) p2;
        double v1 = ((double) (l1.getValue() - l1.getPreviousClose())) / l1.getPreviousClose() * 100;
        double v2 = ((double) (l2.getValue() - l2.getPreviousClose())) / l2.getPreviousClose() * 100;
        return Double.compare(v1, v2);
    }));
    support.addColumn(column);
}
Also used : ReportingPeriodColumnOptions(name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) BiFunction(java.util.function.BiFunction) DND(org.eclipse.swt.dnd.DND) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) StockSplitWizard(name.abuchen.portfolio.ui.wizards.splits.StockSplitWizard) Composite(org.eclipse.swt.widgets.Composite) AbstractFinanceView(name.abuchen.portfolio.ui.AbstractFinanceView) KeyEvent(org.eclipse.swt.events.KeyEvent) Factory(name.abuchen.portfolio.online.Factory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Separator(org.eclipse.jface.action.Separator) SecurityTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransferDialog) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) OptionLabelProvider(name.abuchen.portfolio.ui.util.viewers.OptionLabelProvider) List(java.util.List) UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) Colors(name.abuchen.portfolio.ui.util.Colors) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Watchlist(name.abuchen.portfolio.model.Watchlist) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) BooleanEditingSupport(name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Taxonomy(name.abuchen.portfolio.model.Taxonomy) NumberColorLabelProvider(name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Shell(org.eclipse.swt.widgets.Shell) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Dialog(org.eclipse.jface.dialogs.Dialog) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Menu(org.eclipse.swt.widgets.Menu) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) 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) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Aggregations

LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)2 Client (name.abuchen.portfolio.model.Client)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 Security (name.abuchen.portfolio.model.Security)2 Taxonomy (name.abuchen.portfolio.model.Taxonomy)2 Values (name.abuchen.portfolio.money.Values)2 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)2 Images (name.abuchen.portfolio.ui.Images)2 Messages (name.abuchen.portfolio.ui.Messages)2 SecurityDragListener (name.abuchen.portfolio.ui.dnd.SecurityDragListener)2 SecurityTransfer (name.abuchen.portfolio.ui.dnd.SecurityTransfer)2 Column (name.abuchen.portfolio.ui.util.viewers.Column)2 ColumnEditingSupport (name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport)2 ColumnViewerSorter (name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter)2 NumberColorLabelProvider (name.abuchen.portfolio.ui.util.viewers.NumberColorLabelProvider)2 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)2