为TableViewer单元添加工具提示不起作用

时间:2019-07-01 09:36:38

标签: java eclipse-plugin jface

This answer说明了如何为表格查看器单元设置工具提示。我试图遵循该方法,但是它不起作用。这是我的代码:

TableViewer coTableViewer = createBasicTableViewer(coDetailsComposite);
TableViewerColumn labelColumn = new TableViewerColumn(coTableViewer, SWT.NONE);
coTableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

labelColumn.getColumn().setText("Property");
ColumnViewerToolTipSupport.enableFor(coTableViewer);

EditingSupport coTableEditingSupport = new CoTableEditingSupport(coTableViewer, treeViewer, this, valueColumn.getViewer(), outlineElements);
valueColumn.setEditingSupport(coTableEditingSupport);

coTableViewer.setContentProvider(new CoTableContentProvider());
// coTableViewer.setLabelProvider(new CoTableLabelProvider());
labelColumn.setLabelProvider(new CoTableLabelProvider(0));
valueColumn.setLabelProvider(new CoTableLabelProvider(1));

如您所见,我已经为两个TableViewerColumn实例设置了标签提供程序。标签提供者源自ColumnLabelProvider,并覆盖getColumnText。这部分有效。但是从未调用getToolTipText方法。我在这里想念什么?

public final class CoTableLabelProvider extends ColumnLabelProvider implements ITableLabelProvider {

    private int columnIndex;
    public CoTableLabelProvider(int columnIndex) {
        super();
        this.columnIndex = columnIndex;
    }

    public Image getColumnImage(Object element, int columnIndex) {
        return null;
    }

    public String getColumnText(Object element, int columnIndex) {
        return null;
    }

    @Override
    // this method works
    public String getText(Object element) {
        if (element instanceof ...) {
            if (columnIndex == 0) {
                ...
            } else if (columnIndex == 1) {
                ...
            }
        }
        return "";
    }

    @Override
    public String getToolTipText(Object element) {
        return "hello";
    }
}

0 个答案:

没有答案