Namux
Namux

Reputation: 325

JFace DialogCellEditor: how to make buttons always appear?

I use JFace DialogCellEditor to show a button in a cell of a row of my JFace TableViewer which triggers a dialog when activated. This behaviour works well with the following code but the button only appears when the cell of the table hosting the button is explicitly selected.

public class CompareDialogCellEditor extends DialogCellEditor {
    public CompareDialogCellEditor(Composite parent) {
           super(parent);
    }

    @Override
    protected Button createButton(Composite parent) {
           Button button = super.createButton(parent);
           button.setText("");
           button.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.COMPARE_ICON).createImage());
           return button;
    }

    @Override
    protected Object openDialogBox(Control cellEditorWindow) {
           MessageDialog.openInformation(cellEditorWindow.getShell(), "Test", "It works");
           return null;
    }    
}

Is there a way to force the button to always appear in the table and not only when the cell is selected? (the same behaviour goes for a label set by the overridden method setContents(...) )

Thanks

Upvotes: 2

Views: 2926

Answers (1)

sambi reddy
sambi reddy

Reputation: 3085

You can only edit one Viewer cell at a time. Viewer won't support editing multiple cells at a time unless you do some customization.

I can think of following solutions.

  1. Paint widget ( button, text, combo..etc) like image on table cell and invoke CellEditor when user activates it. You can find some examples here about how to paint on Table Cell. http://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.html

  2. I posted an answer about how to show button in table cell here. you can following the same concept with CellEditor SWT - Tableviewer adding a remove button to a column in the table

Upvotes: 3

Related Questions