Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 174675 - [Viewers] Native Tooltip no longer showing using OwnerDrawLabelProvider
Summary: [Viewers] Native Tooltip no longer showing using OwnerDrawLabelProvider
Status: RESOLVED DUPLICATE of bug 178044
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-19 14:44 EST by Benjamin Pasero CLA
Modified: 2008-04-18 08:19 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Pasero CLA 2007-02-19 14:44:36 EST
Eclipse: 3.3 M5

Consider the following snippet:

public class CustomOwnerDrawnExample {

  private final Color GREEN;
  private final Color BLUE;
  private final Color RED;
  private final Color WHITE;

  private final Object[] myModel = new String[] { "Hello World (Blue)", "Hello World (Green)", "Hello World (Red)" };

  public CustomOwnerDrawnExample() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    BLUE = display.getSystemColor(SWT.COLOR_BLUE);
    GREEN = display.getSystemColor(SWT.COLOR_GREEN);
    RED = display.getSystemColor(SWT.COLOR_RED);
    WHITE = display.getSystemColor(SWT.COLOR_WHITE);

    createViewer(shell);

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

  private void createViewer(Shell shell) {
    TreeViewer viewer = new TreeViewer(shell, SWT.FULL_SELECTION);
    viewer.getTree().setLinesVisible(true);
    viewer.getTree().setHeaderVisible(true);

    /* Enable Custom Owner Drawn for Viewer */
    OwnerDrawLabelProvider.setUpOwnerDraw(viewer);

    viewer.setContentProvider(new MyContentProvider());

    TreeViewerColumn col1 = new TreeViewerColumn(viewer, SWT.NONE);
    TreeViewerColumn col2 = new TreeViewerColumn(viewer, SWT.NONE);

    col1.getColumn().setWidth(20);
    col2.getColumn().setWidth(200);

    col1.setLabelProvider(new MyCellLabelProvider());
    col2.setLabelProvider(new MyCellLabelProvider());

    viewer.setInput(myModel);
  }

  /* The Labelprovider is a OwnerDrawLabelProvider */
  private class MyCellLabelProvider extends OwnerDrawLabelProvider {
    public void update(ViewerCell cell) {
      Object modelItem = cell.getElement();

      if (cell.getColumnIndex() == 0)
        cell.setBackground(getColor(modelItem));
      else
        cell.setText(modelItem.toString());
    }

    protected void erase(Event event, Object element) {
    /* Ignore */
    }

    protected void measure(Event event, Object element) {
    /* Ignore */
    }

    protected void paint(Event event, Object element) {
    /* Ignore */
    }
  }

  private Color getColor(Object object) {
    if ("Hello World (Blue)".equals(object))
      return BLUE;

    if ("Hello World (Green)".equals(object))
      return GREEN;

    if ("Hello World (Red)".equals(object))
      return RED;

    return null;
  }

  private class MyContentProvider implements ITreeContentProvider {
    public Object[] getElements(Object inputElement) {
      return (Object[]) inputElement;
    }

    public void dispose() {}

    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}

    public Object[] getChildren(Object parentElement) {
      return null;
    }

    public Object getParent(Object element) {
      return null;
    }

    public boolean hasChildren(Object element) {
      return false;
    }
  }

  public static void main(String[] args) {
    new CustomOwnerDrawnExample();
  }
}

Steps to reproduce:
1.) Start snippet as is
2.) Reduce size of second col so that the text is no longer showing fully
3.) Hover over the text with the mouse

Actual results:
No tooltip showing

Expected results:
The native tooltip shows. You can see this in action when you comment out the line where "OwnerDrawLabelProvider.setUpOwnerDraw(viewer);" is called.

Ben
Comment 1 Markus Keller CLA 2007-03-19 09:53:12 EDT
Probably an SWT problem, see bug 178044.
Comment 2 Markus Keller CLA 2008-04-18 08:19:36 EDT
Indeed a dup of bug 178044 (snippet works fine in I20080415-1646).

*** This bug has been marked as a duplicate of bug 178044 ***