X

Geertjan's Blog

  • November 29, 2006

Pulling Documentation from Bundle Files

Geertjan Wielenga
Product Manager
In previous blog entries, I showed that you can use a web service to pull documentation into a code completion box's documentation section. (There's also a detailed tutorial on this subject here.) However, chances are that you don't want to use a web service, especially when you have no control over it. Therefore, the approach taken by the nbtapestrysupport project is quite useful. There, a Bundle.properties file stores the documentation, and the CompletionDocumentation.getText() method pulls the documentation from the Bundle.properties file into the documentation section in the code completion box. Here's how:

String theDocumentation = null;
public String getText() {
String theWord = _item.getFilteredWord();
theDocumentation = NbBundle.getMessage(this.getClass, theWord + ".definition");
return theDocumentation;
}

Importantly, the method above is the one that renders in the documentation section. (You could even, as discussed previously and shown in the key/values below, include HTML tags in the method above and it would be rendered, because the documentation section is basically a Swing browser.) And then, in the Bundle.properties file, you'd have key/value pairs like this:

NetBeans.definition = the world's best IDE
work.definition = <b>fun,</b> if you're using <i>NetBeans</i>

Next, whenever the user types "NetBeans" or "work", they'd get the above definitions in the documentation section of the code completion box.

But, what's really interesting is that (just like the tooltip a few days ago), the documentation section could be supported separately from the code completion box. If you press Ctrl-Shift-Space in a Java file, you'll see the documentation section, without seeing the code completion box. So, in "_item.getFilteredWord()" in the code snippet above, "_item" could either be the CompletionProvider or the CompletionItem. In the case of the latter, the documentation section would be part of the code completion box. But, in the case of the former, it would appear separately.

In other news. Stan Aubrecht, the NetBeans drag-and-drop guru, created two new issues in Issuezilla yesterday. The first, issue 90212, will ensure that the Palette DTD does not rely on Bundle.properties files. As a result, you'll be able to let the user add their own palette items, with user-defined labels and icons (unlike my HTML Palette Extension module, which forced me to set labels and icons in the Bundle.properties file). The second issue he created, issue 90213, is equally interesting. It will let you add a palette to an existing editor, without needing to change the editor's source code. This means that you'll be able to register a palette in the XML layer by MIME type, just like you register completion providers, hyperlink providers, and so on. This is really great news, in my humble opinion. I'm looking forward to seeing both these issues resolved... hopefully in 6.0, but that hasn't been decided yet.

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.