viewer.getTree().addMouseTrackListener(new MouseTrackListener() {
private Shell tip = null;
private MouseTrackListener tipShellMouseListener = new MouseTrackListener() {
public void mouseEnter(MouseEvent e) {}
public void mouseHover(MouseEvent e) {}
public void mouseExit(MouseEvent e) {
if(e.x < 0 || e.x > 397 || e.y < 0 || e.y > 147) {
tip.removeMouseTrackListener(tipShellMouseListener);
tip.dispose();
tip = null;
tableComponet = null;
}
}
};
private TableComponent tableComponet = null;
private String[] colnames = {"type","attribute"};
private String[] unmodify = {"type","attribute"};
public void mouseEnter(MouseEvent e) {}
public void mouseExit(MouseEvent e) {
TreeItem item = viewer.getTree().getItem (new Point (e.x, e.y));
if(item == null) {
if(tip == null) {
return;
}
tip.removeMouseTrackListener(tipShellMouseListener);
tip.dispose();
tip = null;
tableComponet = null;
}
}
public void mouseHover(final MouseEvent e) {
TreeItem item = viewer.getTree().getItem (new Point (e.x, e.y));
String[] strarray = {};
Point pt = viewer.getTree().toDisplay (e.x, e.y);
if (item != null) {
tooltipList = setToolTipList(item.getData());
if(tooltipList == null) {
if(tip != null) {
tip.removeMouseTrackListener(tipShellMouseListener);
tip.dispose();
tip = null;
tableComponet = null;
}
return;
}
if (tip != null && !tip.isDisposed ()) {
tip.dispose ();
}
tip = new Shell(parent.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
GridLayout gridLayout = new GridLayout(1,true);
tip.setLayout(gridLayout);
tip.addMouseTrackListener(tipShellMouseListener);
tip.setBackground (parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
tableComponet = new TableComponent(tip,strarray);
tableComponet.setModel(new AbstractCatalogTableModel(colnames,unmodify));
tableComponet.setBackground(tip.getBackground());
tableComponet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
tableComponet.setData(tooltipList);
tableComponet.setCellRenderer(1, new ToolTipCellRenderer());
tableComponet.getColumn(0).setWidth(50);
tip.setBounds (pt.x, pt.y, 400, 150);
tip.setVisible (true);
tip.setFocus();
tip.setActive();
}
else {
if(tip == null) {
return;
}
tip.dispose();
tip = null;
tableComponet = null;
}
}
});