JFace DialogCellEditor: how to make buttons always appear?

痴心易碎 提交于 2019-12-31 03:31:07

问题


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.

  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



来源:https://stackoverflow.com/questions/14464611/jface-dialogcelleditor-how-to-make-buttons-always-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!