use of name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions in project portfolio by buchen.
the class SecuritiesTable method addQuoteDeltaColumn.
private // NOSONAR
void addQuoteDeltaColumn() {
// create a modifiable copy as all menus share the same list of
// reporting periods
List<ReportingPeriod> options = new ArrayList<>(view.getPart().loadReportingPeriods());
BiFunction<Object, ReportingPeriod, Double> valueProvider = (element, option) -> {
Security security = (Security) element;
SecurityPrice latest = security.getSecurityPrice(option.getEndDate());
SecurityPrice previous = security.getSecurityPrice(option.getStartDate());
if (latest == null || previous == null)
return null;
if (previous.getValue() == 0)
return null;
if (previous.getDate().isAfter(option.getStartDate()))
return null;
return new Double((latest.getValue() - previous.getValue()) / (double) previous.getValue());
};
// $NON-NLS-1$
Column column = new Column("delta-w-period", Messages.ColumnQuoteChange, SWT.RIGHT, 80);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnQuoteChange_Option, options));
column.setDescription(Messages.ColumnQuoteChange_Description);
column.setLabelProvider(new QuoteReportingPeriodLabelProvider(valueProvider));
column.setVisible(false);
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
ReportingPeriod option = (ReportingPeriod) ColumnViewerSorter.SortingContext.getColumnOption();
Double v1 = valueProvider.apply(o1, option);
Double v2 = valueProvider.apply(o2, option);
if (v1 == null && v2 == null)
return 0;
else if (v1 == null)
return -1;
else if (v2 == null)
return 1;
return Double.compare(v1.doubleValue(), v2.doubleValue());
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions in project portfolio by buchen.
the class StatementOfAssetsViewer method addDividendColumns.
private void addDividendColumns(List<ReportingPeriod> options) {
ReportingPeriodLabelProvider labelProvider;
// $NON-NLS-1$
Column column = new Column("sumdiv", Messages.ColumnDividendSum, SWT.RIGHT, 80);
Function<Stream<Object>, Object> collector = elements -> elements.map(e -> (Money) e).collect(MoneyCollectors.sum(client.getBaseCurrency()));
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getSumOfDividends, collector, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendSum + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setMenuLabel(Messages.ColumnDividendSum_MenuLabel);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("d%", Messages.ColumnDividendTotalRateOfReturn, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDiv, null, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendTotalRateOfReturn + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setDescription(Messages.ColumnDividendTotalRateOfReturn_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("d%mvavg", Messages.ColumnDividendMovingAverageTotalRateOfReturn, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDivMovingAverage, null, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendMovingAverageTotalRateOfReturn + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setDescription(Messages.ColumnDividendMovingAverageTotalRateOfReturn_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
}
use of name.abuchen.portfolio.ui.util.viewers.ReportingPeriodColumnOptions in project portfolio by buchen.
the class StatementOfAssetsViewer method addPerformanceColumns.
private void addPerformanceColumns(List<ReportingPeriod> options) {
ReportingPeriodLabelProvider labelProvider;
// $NON-NLS-1$
Column column = new Column("ttwror", Messages.ColumnTWROR, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTrueTimeWeightedRateOfReturn);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnTTWROR_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnTWROR_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("irr", Messages.ColumnIRR, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getIrr);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnIRRPerformanceOption, options));
column.setMenuLabel(Messages.ColumnIRR_MenuLabel);
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
Function<Stream<Object>, Object> sum = elements -> elements.map(e -> (Money) e).collect(MoneyCollectors.sum(client.getBaseCurrency()));
// $NON-NLS-1$
column = new Column("capitalgains", Messages.ColumnCapitalGains, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getCapitalGainsOnHoldings, sum, true);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnCapitalGains_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnCapitalGains_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("capitalgains%", Messages.ColumnCapitalGainsPercent, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getCapitalGainsOnHoldingsPercent);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnCapitalGainsPercent_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnCapitalGainsPercent_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("capitalgainsmvavg", Messages.ColumnCapitalGainsMovingAverage, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getCapitalGainsOnHoldingsMovingAverage, sum, true);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnCapitalGainsMovingAverage_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnCapitalGainsMovingAverage_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("capitalgainsmvavg%", Messages.ColumnCapitalGainsMovingAveragePercent, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getCapitalGainsOnHoldingsMovingAveragePercent);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnCapitalGainsMovingAveragePercent_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnCapitalGainsMovingAveragePercent_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("delta", Messages.ColumnAbsolutePerformance_MenuLabel, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getDelta, sum, true);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnAbsolutePerformance_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnAbsolutePerformance_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("delta%", Messages.ColumnAbsolutePerformancePercent_MenuLabel, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getDeltaPercent);
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnAbsolutePerformancePercent_Option, options));
column.setGroupLabel(Messages.GroupLabelPerformance);
column.setDescription(Messages.ColumnAbsolutePerformancePercent_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
}
Aggregations