views:

452

answers:

3

I'm using the following

org.eclipse.jface.viewers.CheckboxCellEditor.CheckboxCellEditor(Composite parent)

I'm creating a table viewer with cellEditors and doing the following

CellEditor[] editors = new CellEditor[columnNames.length];
editors[7] = new CheckboxCellEditor(table);

I have a CellModifier that has the following

public Object getValue(Object element, String property) {
        Object result = null;
        ...
        result = Boolean.valueOf(task.isDfRequested());
        return result;
}

 public void modify(Object element, String property, Object value) {
       item.isSelected(((Boolean)value).booleanValue());
}

Finally I have a LabelProvider that has the following

 public String getColumnText(Object element, int columnIndex) {
        String result = "";
        try { 
            result = Boolean.toString(item.isSelected());
        } catch (Exception ex) { } 

        break;

However, in my UI instead of having a check box I have the word true or false && clicking it results in switching state to false or true. Any ideas on why I don't have a checkbox??

A: 

Well, I have no idea how SWT works or what component you are even talking about.

But I do know that when using Swing you can have custom editors for a column in a JTable. If you don't tell the table the class of data for the column then the toString() method of the data is invoked. But if you tell the table that Boolean data is displayed in the column then the table will use the check box editor.

Sounds like a similiar symptom, but I don't know your particular solution.

camickr
A: 

What I've decided to do is to just implement a dirty hack others have been using.

Create two images of check boxes, one checked the other not checked. Switch the state between the two based on the boolean.

It's not perfect, but for now it gets the job done

PSU_Kardi
A: 

I've searched in the source code of CheckboxCellEditor class and in the constructor the control associated to the CellEditor is created in the createControl(Composite parent) method. This method is abstract in CellEditor class and it's implemented like this in CheckboxCellEditor:

protected Control createControl(Composite parent) {
    return null;
}

So a control is not created, that's why you don't see the checkbox. In the documentation of the Class you can read:

Note that this implementation simply fakes it and does does not create any new controls. The mere activation of this editor means that the value of the check box is being toggled by the end users; the listener method applyEditorValue is immediately called to signal the change.

I solved this using a ComboBoxCellEditor with yes and no items.

Regards.

Miguel