Composite tableArea = new Composite(composite, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(tableArea);
tableArea.setLayout(new FillLayout());
TableColumnLayout layout = new TableColumnLayout();
tableArea.setLayout(layout);
tableViewer = new TableViewer(tableArea, SWT.BORDER | SWT.FULL_SELECTION);
final Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE);
col.getColumn().setText(Messages.ColumnDate);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
Date date = ((ReportedIssue) element).getDate();
return date != null ? Values.Date.format(date) : null;
}
});
layout.setColumnData(col.getColumn(), new ColumnPixelData(80));
ColumnViewerSorter.create(ReportedIssue.class, "date").attachTo(tableViewer, col, true); //$NON-NLS-1$
col = new TableViewerColumn(tableViewer, SWT.NONE);
col.getColumn().setText(Messages.ColumnEntity);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
return ((ReportedIssue) element).getEntity().toString();
}
@Override
public Image getImage(Object element)
{
ReportedIssue issue = (ReportedIssue) element;
if (issue.getEntity() instanceof Account)
return PortfolioPlugin.image(PortfolioPlugin.IMG_ACCOUNT);
else if (issue.getEntity() instanceof Portfolio)
return PortfolioPlugin.image(PortfolioPlugin.IMG_PORTFOLIO);
else
return null;
}
});
layout.setColumnData(col.getColumn(), new ColumnPixelData(100));
ColumnViewerSorter.create(ReportedIssue.class, "entity").attachTo(tableViewer, col); //$NON-NLS-1$
col = new TableViewerColumn(tableViewer, SWT.RIGHT);
col.getColumn().setText(Messages.ColumnAmount);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
Long amount = ((ReportedIssue) element).getAmount();
return amount != null ? Values.Amount.format(amount) : null;
}
});
layout.setColumnData(col.getColumn(), new ColumnPixelData(80));
ColumnViewerSorter.create(ReportedIssue.class, "amount").attachTo(tableViewer, col); //$NON-NLS-1$
col = new TableViewerColumn(tableViewer, SWT.NONE);
col.getColumn().setText(Messages.ColumnIssue);
col.setLabelProvider(new OwnerDrawLabelProvider()
{
protected void measure(Event event, Object element)
{
ReportedIssue line = (ReportedIssue) element;
Point size = event.gc.textExtent(line.getLabel());
event.width = table.getColumn(event.index).getWidth();
event.width = size.x + 1;
event.height = size.y;
}
protected void paint(Event event, Object element)
{
ReportedIssue entry = (ReportedIssue) element;
event.gc.drawText(entry.getLabel(), event.x, event.y, true);
}
});
layout.setColumnData(col.getColumn(), new ColumnPixelData(300));
ColumnViewerSorter.create(ReportedIssue.class, "label").attachTo(tableViewer, col); //$NON-NLS-1$
col = new TableViewerColumn(tableViewer, SWT.NONE);
col.getColumn().setText(Messages.ColumnFix);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object element)
{
ReportedIssue issue = (ReportedIssue) element;
return issue.isFixed() ? issue.getFixedMessage() : null;
}
@Override
public Image getImage(Object element)
{
ReportedIssue issue = (ReportedIssue) element;
return PortfolioPlugin.image(issue.isFixed() ? PortfolioPlugin.IMG_CHECK
: PortfolioPlugin.IMG_QUICKFIX);
}
});
layout.setColumnData(col.getColumn(), new ColumnPixelData(100));
table.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{