Using StyledCellLabelProvider in a TableViewer killed my tooltips

201 views Asked by At

I have a TableViewer in my Eclipse plugin.

When I was just using a regular label provider, my tooltips worked beautifully:

Tootlips work

However, when I switched to have my LabelProvider implement IStyledLabelProvider, my tooltips went haywire:

Tooltips work

Here is the code creating the StyledString

    @Override
public StyledString getStyledText(final Object element) {
    if( !(element instanceof MyInterface<?>) ) {
        return null;
    }

    final String elemText = getColumnText(element, this.columnIndex);
    final StyledString styledString = new StyledString(elemText == null ? "" : elemText);
    if( !(element instanceof MyObject) ) {
        return styledString;
    }

    final MyObject settingElement = (MyObject) element;
    // grayed out text
    if( settingElement.shouldBeGray() ) {
        styledString.setStyle(0, elemText.length(), AdaptabilityStyles.GRAY_STYLER;
    } else if( !settingElement.shouldBeBlue() ) {
        styledString.setStyle(0, elemText.length(), AdaptabilityStyles.BLUE_STYLER);
    }

    return styledString;
}

And getTooltTipText()

    @Override
public String getToolTipText(final Object element) {
    return getColumnText(element, this.columnIndex);
}

What am I doing wrong?

1

There are 1 answers

0
chama On

As I was writing this question, I wanted to reference a bug report that I am familiar with that is related to tooltips. I looked at the bug report again and came across the following line:

For now, I simply try this : ColumnViewerToolTipSupport.enableFor(commonViewer)

I wasn't calling that method when I created my viewer. When I tried that, my tooltips came back (though slightly different than they were before.

Tooltips working again