/** * Adds a listener for help requests in this viewer. Has no effect if an identical listener is * already registered. * * @param listener a help listener */ public void addHelpListener(HelpListener listener) { helpListeners.add(listener); if (!helpHooked) { Control control = getControl(); if (control != null && !control.isDisposed()) { if (this.helpListener == null) { this.helpListener = new HelpListener() { public void helpRequested(HelpEvent event) { handleHelpRequest(event); } }; } control.addHelpListener(this.helpListener); helpHooked = true; } } }
public void activateHoverHelp(final org.eclipse.swt.widgets.Control control) { control.addMouseListener( new org.eclipse.swt.events.MouseAdapter() { public void mouseDown(org.eclipse.swt.events.MouseEvent e) { if (tipShell.isVisible()) { tipShell.setVisible(false); } } }); control.addMouseTrackListener( new org.eclipse.swt.events.MouseTrackAdapter() { public void mouseExit(org.eclipse.swt.events.MouseEvent e) { if (tipShell.isVisible()) { tipShell.setVisible(false); } tipWidget = null; } public void mouseHover(org.eclipse.swt.events.MouseEvent event) { org.eclipse.swt.graphics.Point pt = new org.eclipse.swt.graphics.Point(event.x, event.y); org.eclipse.swt.widgets.Widget widget = event.widget; if (widget instanceof org.eclipse.swt.widgets.ToolBar) { org.eclipse.swt.widgets.ToolBar w = (org.eclipse.swt.widgets.ToolBar) widget; widget = w.getItem(pt); } if (widget instanceof org.eclipse.swt.widgets.Table) { org.eclipse.swt.widgets.Table w = (org.eclipse.swt.widgets.Table) widget; widget = w.getItem(pt); } if (widget instanceof org.eclipse.swt.widgets.Tree) { org.eclipse.swt.widgets.Tree w = (org.eclipse.swt.widgets.Tree) widget; widget = w.getItem(pt); } if (widget == null) { tipShell.setVisible(false); tipWidget = null; return; } if (widget == tipWidget) { return; } tipWidget = widget; tipPosition = control.toDisplay(pt); java.lang.String text = (java.lang.String) widget.getData("TIP_TEXT"); org.eclipse.swt.graphics.Image image = (org.eclipse.swt.graphics.Image) widget.getData("TIP_IMAGE"); tipLabelText.setText(text != null ? text : ""); tipLabelImage.setImage(image); tipShell.pack(); setHoverLocation(tipShell, tipPosition); tipShell.setVisible(true); } }); control.addHelpListener( new org.eclipse.swt.events.HelpListener() { public void helpRequested(org.eclipse.swt.events.HelpEvent event) { if (tipWidget == null) { return; } org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler handler = (org.eclipse.swt.examples.hoverhelp.HoverHelp.ToolTipHelpTextHandler) tipWidget.getData("TIP_HELPTEXTHANDLER"); if (handler == null) { return; } java.lang.String text = handler.getHelpText(tipWidget); if (text == null) { return; } if (tipShell.isVisible()) { tipShell.setVisible(false); org.eclipse.swt.widgets.Shell helpShell = new org.eclipse.swt.widgets.Shell(parentShell, SWT.SHELL_TRIM); helpShell.setLayout(new org.eclipse.swt.layout.FillLayout()); org.eclipse.swt.widgets.Label label = new org.eclipse.swt.widgets.Label(helpShell, SWT.NONE); label.setText(text); helpShell.pack(); setHoverLocation(helpShell, tipPosition); helpShell.open(); } } }); }