switch (event.type) {
case SWT.MouseHover: {
if (toolTipShell != null && !toolTipShell.isDisposed())
toolTipShell.dispose();
TableItem item = table.getItem( new Point( event.x, event.y ));
if (item == null)
return;
Object oToolTip = item.getData( "tooltip" );
if ( oToolTip == null ){
oToolTip = item.getText(0);
}
// TODO: support composite, image, etc
if (oToolTip == null || !(oToolTip instanceof String))
return;
String sToolTip = (String) oToolTip;
Display d = table.getDisplay();
if (d == null)
return;
// We don't get mouse down notifications on trim or borders..
toolTipShell = new Shell(table.getShell(), SWT.ON_TOP);
FillLayout f = new FillLayout();
try {
f.marginWidth = 3;
f.marginHeight = 1;
} catch (NoSuchFieldError e) {
/* Ignore for Pre 3.0 SWT.. */
}
toolTipShell.setLayout(f);
toolTipShell.setBackground(d.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
toolTipLabel = new Label(toolTipShell, SWT.WRAP);
toolTipLabel.setForeground(d.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
toolTipLabel.setBackground(d.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
//toolTipShell.setData("TableCellSWT", item);
toolTipLabel.setText(sToolTip.replaceAll("&", "&&"));
// compute size on label instead of shell because label
// calculates wrap, while shell doesn't
Point size = toolTipLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (size.x > 600) {
size = toolTipLabel.computeSize(600, SWT.DEFAULT, true);
}
size.x += toolTipShell.getBorderWidth() * 2 + 2;
size.y += toolTipShell.getBorderWidth() * 2;
try {
size.x += toolTipShell.getBorderWidth() * 2 + (f.marginWidth * 2);
size.y += toolTipShell.getBorderWidth() * 2 + (f.marginHeight * 2);
} catch (NoSuchFieldError e) {
/* Ignore for Pre 3.0 SWT.. */
}
Point pt = table.toDisplay(event.x, event.y);
Rectangle displayRect;
try {
displayRect = table.getMonitor().getClientArea();
} catch (NoSuchMethodError e) {
displayRect = table.getDisplay().getClientArea();