我使用添加复选框getColumnImages(Object element, int columnIndex)
的方法。ITableLabelProvider
我找到了一些选中和未选中复选框的图片,并在此方法中设置了选择逻辑。它在那里描述http://www.vogella.com/tutorials/EclipseJFaceTable/article.html#jfaceeditor。
然后我为列编辑实现了 EditingSupport,并在它的方法getCellEditor(Object element)
中将 CheckboxCellEditor 设置为复选框列的返回值。
public class CheckboxColumnEditor extends EditingSupport {
private GridTreeViewer gridViewer;
//...
@Override
protected void setValue(Object element, Object value) {
//...
getViewer().update(element, null);
}
@Override
protected Object getValue(Object element) {
//...
}
@Override
protected CellEditor getCellEditor(Object element) {
//...
return new CheckboxCellEditor(gridViewer.getGrid());
}
@Override
protected boolean canEdit(Object element) {
//...
}
}
然后用于列创建代码:
GridColumn column = new GridColumn(parent, SWT.CENTER);
//...
GridViewerColumn gvc = new GridViewerColumn(gridViewer, column);
gvc.setLabelProvider(new ColumnLabelProvider());
gvc.setEditingSupport(new CheckboxColumnEditor());
看看这个答案https://stackoverflow.com/a/13259350/1903580。描述了两种添加复选框的方法。