eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
114 stars 130 forks source link

Native tooltip doesn't show up on TableViewer #752

Open JohnRandomdude opened 1 year ago

JohnRandomdude commented 1 year ago

Describe the bug Native tooltip doesn't show up on TableViewer

To Reproduce This one can be used, but make sure useNativeToolTip returns true on a sub-class of org.eclipse.jface.viewers.CellLabelProvider

Expected behavior A native tooltip appears when hovering table cells

Environment:

  1. Select the platform(s) on which the behavior is seen:

      • [ ] All OS
      • [x] Windows
      • [ ] Linux
      • [ ] macOS
  2. Additional OS info (e.g. OS version, Linux Desktop, etc) Windows 10 Pro N 22H2 (OS build 19045.3208)

  3. JRE/JDK version Openjdk "17.0.3" 2022-04-19

Version since Since org.eclipse.swt.win32.win32.x86_64 3.116.0

Workaround (or) Additional context Possible workaround - downgrading org.eclipse.swt.win32.win32.x86_64 to 3.115.100

Phillipus commented 1 year ago

Can confirm this not working on Windows, but working on Mac. (Does work for TreeViewer, though).

As OP says, add the following to the snippet's CellLabelProvider:

@Override
public boolean useNativeToolTip(Object object) {
    return true;
}
Phillipus commented 1 year ago

Also, see OP's comment https://github.com/eclipse-platform/eclipse.platform.swt/issues/509#issuecomment-1642305423

Phillipus commented 1 year ago

Can confirm this broke with this commit:

https://github.com/eclipse-platform/eclipse.platform.swt/commit/6c3f1fb37bb90b0bd3f5c6ab4d37a884b729dbbe

I don't know how to fix that regression.

Phillipus commented 1 year ago

The problem lies here:

https://github.com/eclipse-platform/eclipse.platform.swt/blob/1a939af1dfb0d050f91e5357887fa068f336da23/bundles/org.eclipse.swt/Eclipse%20SWT/win32/org/eclipse/swt/widgets/Shell.java#L1952-L1963

Comment out isCurrentlyVisible and the tooltip appears.

Phillipus commented 1 year ago

For convenience, here's a full snippet to reproduce:

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class TooltipTest {

    public static void main(String[] args) {
        final Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
        v.getTable().setLinesVisible(true);
        v.getTable().setHeaderVisible(true);
        v.setContentProvider(ArrayContentProvider.getInstance());
        ColumnViewerToolTipSupport.enableFor(v);

        CellLabelProvider labelProvider = new CellLabelProvider() {

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

            @Override
            public void update(ViewerCell cell) {
                cell.setText(cell.getElement().toString());
            }

            @Override
            public boolean useNativeToolTip(Object object) {
                return true;
            }
        };

        TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
        column.setLabelProvider(labelProvider);
        column.getColumn().setText("Column 1");
        column.getColumn().setWidth(100);
        String[] values = new String[]{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
        v.setInput(values);

        shell.setSize(200, 200);
        shell.open();

        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }

        display.dispose();
    }
}