Geertjan's Blog

  • November 26, 2006

Hidden Browser Inside NetBeans

Geertjan Wielenga
Product Manager
There's a handy class called CompletionDocumentation. That class, all on its own, controls the documentation section of a code completion box. The documentation section is, in the screenshot below, the lower part of the screenshot, which here displays the text "Word: were", with definitions of the word "were", retrieved from an online web service:

In effect, the documentation section is a browser. It renders HTML tags. So, above you see a hyperlink for the word "were". When you click it, a page opens in the documentation section. In this case, what opens is a page that defines the word "were". However, when the new page opens, you can also click the links within that page, within the documentation section.

The left and right arrow buttons in the documentation section's toolbar let you navigate between the pages you opened in the documentation section. There are two other buttons, one that opens a URL of your chosing in the external browser and the other for opening a source view, if one exists.

Together, the methods in the CompletionDocumentation class provide the functionality described above. And it is not very hard to work with this class. You instantiate it from the createDocumentationTask() method in the related CompletionItem class.

By they way, above you can see that I also implemented the createToolTipTask() in the CompletionItem class. That was pretty easy too, here's the definition:

public CompletionTask createToolTipTask() {
return new AsyncCompletionTask( new AsyncCompletionQuery() {
protected void query(CompletionResultSet completionResultSet, Document document, int i) {
JToolTip toolTip = new JToolTip();
toolTip.setTipText("Press Enter to insert \\"" + getText() + "\\"");
} );

So now, whenever I press Alt-P over an entry, I get the tooltip defined above. This means that each code completion item could provide a different text for its tooltips, which is also nice. However, I wonder how many people know that the Alt-P keybinding exists... Probably not many. Wthout that, no tooltip. On the other hand, the tooltip can never be incredibly meaningful anyway, beyond telling the user to press Enter, there's probably not very much it could do.

Join the discussion

Comments ( 2 )
  • Andreas Andreou Sunday, November 26, 2006
    "I wonder how many people know that the Alt-P keybinding exists"

    Yep, that applies in my case... I even tried implementing <code>createToolTipTask</code> for nbtapestrysupport, but since i didn't see any visible changes + couldn't know how to invoke the tooltip i simply thought it wasn't working and quickly removed that method from my code !!!
  • Geertjan Monday, November 27, 2006
    Hi Andreas. Yes, that keybinding is pretty obscure. To help users, it is probably better to (if you have a tooltip there) have it appear automatically (CompletionProvider.getAutoQueryTypes). Have a look at my next experiment with tooltips in the Editor Code Completion API... it is pretty cool, imho and is discussed in today's blog entry.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.