column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
SecurityPrice price = ((Security) e).getSecurityPrice(Dates.today());
if (!(price instanceof LatestSecurityPrice))
return null;
LatestSecurityPrice latest = (LatestSecurityPrice) price;
return String.format("%,.2f %%", //$NON-NLS-1$
((double) (latest.getValue() - latest.getPreviousClose()) / (double) latest
.getPreviousClose()) * 100);
}
@Override
public Color getForeground(Object element)
{
SecurityPrice price = ((Security) element).getSecurityPrice(Dates.today());
if (!(price instanceof LatestSecurityPrice))
return null;
LatestSecurityPrice latest = (LatestSecurityPrice) price;
return latest.getValue() >= latest.getPreviousClose() ? Display.getCurrent().getSystemColor(
SWT.COLOR_DARK_GREEN) : Display.getCurrent().getSystemColor(SWT.COLOR_DARK_RED);
}
});
column.setSorter(ColumnViewerSorter.create(new Comparator<Object>()
{
@Override
public int compare(Object o1, Object o2)
{
SecurityPrice p1 = ((Security) o1).getSecurityPrice(Dates.today());
SecurityPrice p2 = ((Security) o2).getSecurityPrice(Dates.today());
if (!(p1 instanceof LatestSecurityPrice))
return p2 == null ? 0 : -1;
if (!(p2 instanceof LatestSecurityPrice))
return 1;