0

I an using nebula grid which contains some texts, images and checkboxes in different columns. If I want to map texts and images to model, I can simply use getColumnText(Object e1, int c1) and getColumnImages(Object e1, int c1) from jface's ITableLabelProvider respectively.

I want to know if there is a similar way of setting checkbox states based on the model in nebula grid? On the view, I can set this as follows:

GridItem item = grid.getItem(3);
item.setChecked(2, true);
Shafi
  • 1,368
  • 10
  • 24

1 Answers1

0

I used getColumnImages(Object element, int columnIndex) method of ITableLabelProvider to add checkboxes. I found some pictures of checked and uncheked checkbox and set the selection logic in this method. It is described there http://www.vogella.com/tutorials/EclipseJFaceTable/article.html#jfaceeditor.

Then I implemented EditingSupport for column editing and in it's method getCellEditor(Object element) I set CheckboxCellEditor as a return value for checkbox column.

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) {
    //...
 }
}

And then for column creating code:

GridColumn column = new GridColumn(parent, SWT.CENTER);
//...
GridViewerColumn gvc = new GridViewerColumn(gridViewer, column);
gvc.setLabelProvider(new ColumnLabelProvider());
gvc.setEditingSupport(new CheckboxColumnEditor());

Have a look to this answer https://stackoverflow.com/a/13259350/1903580. There are described 2 ways to add checkboxes.

Community
  • 1
  • 1
  • In the vogella article, they use JFace Table which do not provide checkbox support(except CheckboxTableViewer which only puts checkboxes before each row). But nebula grid does provide such support. This is why I dont think that being forced to use checkbox images should be the only way when it is so easily done on the view as calling `setChecked()` over `GridItem`. – Shafi Apr 04 '16 at 11:52