问题
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
回答1:
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.
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 onTable
Cell. http://www.eclipse.org/articles/article.php?file=Article-CustomDrawingTableAndTreeItems/index.htmlI 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
来源:https://stackoverflow.com/questions/14464611/jface-dialogcelleditor-how-to-make-buttons-always-appear