Friday, November 23, 2012

Tooltip on tree viewer items

This describes about how to add a tooltip on tree viewer items based on the context of object. 

ExplorerViewer.getTree().addMouseTrackListener(new ExplorerMouseListener());


private class ExplorerMouseListener implements MouseTrackListener {

@Override
public void mouseEnter(MouseEvent e) {
}

@Override
public void mouseExit(MouseEvent e) {
}

@Override
public void mouseHover(MouseEvent event) {

TreeItem item = explorerViewer.getTree().getItem(new Point(event.x, event.y));
if (item != null && item.getData() instanceof MyResource) {
MyResource selectedElement = (MyResource) item.getData();
if (selectedElement.getResourceType() == MyResourceType.APP_GROUP
|| selectedElement.getResourceType() == MyResourceType.DATA) {
if (selectedElement.getData() instanceof INameDescription)
explorerViewer.getTree().setToolTipText(
((INameDescription) selectedElement.getData())
.getDescription());
} else {
explorerViewer.getTree().setToolTipText(null);
}
}
}

}

No comments:

Post a Comment