开发者

How can i retrieve the tool tip information in eclipse plugin?

开发者 https://www.devze.com 2023-03-23 13:08 出处:网络
In eclipse, if we are focusing any of the variable or instances or whatever using our mouse pointer we will be notified with some info开发者_StackOverflowrmation about the focused thing. Is it possibl

In eclipse, if we are focusing any of the variable or instances or whatever using our mouse pointer we will be notified with some info开发者_StackOverflowrmation about the focused thing. Is it possible to to fake that mouse move and obtain the tool tip information in our own plugin project?

If possible can you please say me some way to achieve it.

Thanks in advance, Easwar


There are two pieces to what you are looking for:

  1. figuring out what thing is at a given location. For this, you need to call the API method: org.eclipse.jdt.core.ICodeAssist.codeSelect(int, int). If you have a file handle, then you can do somthieng like this:

    IFile file = getFile(); ICompilationUnit unit = JavaCore.create(file); IJavaElement[] elts = unit.codeSelect(start, length);

Then, once you have the Java elements, you need to extract the Javadoc information from them. This is a little bit less straight forward, but you can have a look at the org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover class, specifically the getHoverInfo class.

If you just want the javadoc, then you should have a look at the org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2 class.


There are basically two ways to provide tooltips in SWT:

  • You can set it using control.setToolTipText(text).
  • You can add a SWT.MouseHower listener and show your own tool tip information when invoked - really anything. This method is used by org.eclipse.jface.window.ToolTip.

In the first case, you can retrieve the tooltip with control.getToolTipText(). In the later case, you cannot find the text programmatically... it does not even have to be a string...

You can show the tooltip - for both methods above - using Display.post(Event) by first positioning the mouse with SWT.MouseMove and then wait a second with Display.timedExec(Runnable).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号