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