Geertjan's Blog

  • November 27, 2006

Integrating Web Services into Tooltips

Geertjan Wielenga
Product Manager
Yesterday I blogged about the tooltip that CompletionItem.createToolTipTask() can give you. However, in order to invoke that tooltip, you need to be inside the code completion box and then press Alt-P when an entry is selected. Wouldn't it be cool if you could get a tooltip without even opening the code completion box? Well, fortunately you can set a tooltip in the CompletionProvider, by using CompletionResultSet.setToolTip().

This particular tooltip is really powerful. It is a gift that the Editor Code Completion API gives you: without even calling up the code completion box, you can make use of the API. Now, when I press Alt-P over any word, i.e., without calling up the code completion box, I get a tooltip that is populated by a web service (the same web service used in previous blog entries to populate the documentation section of the code completion box):

In this particular case, the tooltip appears and defines the word "other", here making use of a thesaurus so that without invoking code completion, I can immediately see alternative words for the currently typed word. If you use CompletionProvider.getAutoQueryTypes(), you can make the tooltip appear automatically, so that the user doesn't need to know about the Alt-P binding.

To make all this possible, this is now the end of my query method in the CompletionProvider:

JToolTip tooltip = new JToolTip();

And the getDefinitionsFromWS(filter) method is the same as that used for filling the documentation section of the code completion box, which is described in the Code Completion tutorial.

The tooltip thingy on the CompletionProvider is really cool, I think, especially because of its separation from the code completion box.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.