2

On windows platform, I am implementing a TreeViewer. I added listeners for SWT.MeasureItem, SWT.PaintItem, and SWT.EraseItem. In SWT.EraseItem listener, I am clearin SWT.HOT bit too. Even after that I get hover highlight of that tree item. I want to completely disable the Hover Changes in tree. How can I achieve that?

I am developing eclipse e4 rcp application. I am using StyledCellLabelProvider for tree viewer and also tried specifying COLORS_ON_SELECTION. Still no luck.

Matt
  • 14,906
  • 27
  • 99
  • 149
Sachin Giri
  • 189
  • 11
  • 2
    Since this highlighting is done by the native control there probably isn't anything you can do to stop it. – greg-449 Oct 12 '15 at 11:46

1 Answers1

2

The following snippet works for me.

package test;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

public class TestTreeViewer {

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

    TreeViewer treeViewer = new TreeViewer(shell);
    Tree tree = treeViewer.getTree();

    TreeItem child1 = new TreeItem(tree, SWT.NONE, 0);
    child1.setText("1");
    TreeItem child2 = new TreeItem(tree, SWT.NONE, 1);
    child2.setText("2");
    TreeItem child3 = new TreeItem(tree, SWT.NONE, 2);
    child3.setText("3");

    tree.addListener(SWT.EraseItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
//          allow selection in tree?
//          event.detail &= ~SWT.SELECTED;
            event.detail &= ~SWT.HOT;
        }
    });

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

enter image description here

Monikka
  • 518
  • 6
  • 12
  • I have these lines in my Erase Item listner, but I have MeasureItem listner as well. If I set a larger width in the MeasureItem event, it seems there still hover pop-up appears. – Sachin Giri Oct 13 '15 at 05:56
  • Setting the width within the MeasureItem listener doesn't show the hover highlighting for me. Could you share your code? I tried adding the following lines to my snippet and the hover highlighting remains disabled. tree.addListener(SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { event.width = 200; } }); – Monikka Oct 17 '15 at 13:24