Tag Archives: Programming

Reflection problem in the Netbeans Nodes API tutorial

I’ve been following the Netbeans tutorial on using the Nodes API to implement a tree structure with some information in it.

In the second part of the tutorial the author shows how to set up and show a property sheet sheet when an element in the tree structure is selected. Most of the examples work pretty straight forward, but when I tried to adapt the example to my own code, I got a problem with the way the tutorial uses the Java reflection to set the fields of the property sheet. Here is the line in the tutorial:

APIObject obj = getLookup().lookup(APIObject.class);
Property indexProp = new PropertySupport.Reflection(obj, Integer.class, "getIndex", null);

When ever I try to do that with my own implementation of an APIObject, I get a NoSuchMethodException. After trying to work out why that was happening, without any success, I figured another way to create the property sheet, based on this blog post: http://blogs.oracle.com/geertjan/entry/connecting_shapes_showing_properties by Geertjan Wielenga from the Netbeans group.

The code becomes like this instead:

APIObject obj = getLookup().lookup(APIObject.class);
Property indexProp = new PropertySupport.ReadOnly("objIndex" Integer.class,"Index","Object index") { 

@Override
public Integer getValue() throws IllegalAccessException, InvocationTargetException {
 return obj.getIndex();
}
};

While that is not really a solution to the non-working reflection, it is still a workaround that can be used.

Adding javadoc to JAR files in a Netbeans project

The other day I was working on a Netbeans project where I had to create a new module that was dependent on a external JAR file. From the platform document I found out that you can add a JAR file in two ways: Using the Library Manager or using a Library Wrapper Module. First I tried the second option, and it worked fine except for one thing – there was no javadoc attached to the jar, and no way to attach it.

Project Properties
There is no way to edit the jar file properties

Then I tried the other option, adding the JAR as a library using the Libraries option from the Tools menu. Using this method it was possible to add both the javadoc and the source to the library. Unfortunately there was no way to include the library in a project, which kind of renders the whole ting useless. I still don’t know what the Library Manager is supposed to be used for, but apparently not for including JARs in projects.

After Googling for a while, coming up blank on what to do, I got in touch with a Netbeans expert Andrzej Olszak – author of the cool Featureous tool. He already knew the problem from his own work and also knew a work-around:

  1. Select the main module suite, click the New Project… option in the file menu and add a new Library Wrapper Module
  2. Select the JAR file to be included and complete the forms as needed. When you press OK, the new module should be opened along with your other modules.
  3. Right click on the module in the list of projects and select Properties at the bottom of the menu. Select the Libraries node on the left side, and click on the Wrapped JARs tab to the right.
  4. Now you see the same options as on the image above, with the Edit… button disabled. Here comes the trick:
  5. Select the JAR and press Remove, then press the Add JAR button and re-add the same JAR file again… and watch what happens to the Edit… button. Suddenly it is enabled! That is it…

Now you can include the wrapper module as a dependency in any module you like, and the javadoc will be available.

Javadoc for an included JAR file in Netbeans
Now the javadoc is visible...

Back from JAOO2007

JAOO2007JAOO2007 is over, and I’m back from one day of tutorial and three days of conference. Got to see a lot of stuff, hear some great people, and talk to other developers and it-professionals. Didn’t quite get to see as much as hoped for, since working as crew this year definitely took more of my time than last year.

As previously said here I was participating in Diana Larsons “Leading Agile Retrospectives” tutorial. The tutorial was held Sunday before the conference and was joined by about 25 people. We were split in four groups and used the time before the lunch break for presentations and performing a simulated retrospective in the groups, with Diana as a leader. The goal was to try out some different techniques and the discuss how each group felt about using the technique and what results were achieved.

After lunch we worked with in groups again, analysing a “case” and coming up with a plan for a retrospective. Our group had a hard one, with a 20 people team using 30 day iterations, not currently using retrospectives and a completely failed project. Now the VP of the organisation had decreed the need for a project post-mortem, and everybody were suspecting that the board were out looking for somebody to blame. It was a challenge coming up with a retrospective that would convince the team that it was not about blame, but more about what to do better. We made quite a good plan, which I’ll try to write up and publish here later.

Anyway… the tutorial was definitely the best thing about JAOO2007 seen from my perspective. It was the first time I participated in one, and next year, I’ll try to get to participate in all three days.

The conference it self wasn’t bad of course. There were some really good speakers, and the exhibitors who had found their way to the main hall of the conference area, genuinely had some good products to show, and were willing to talk about technical stuff, and not just marketspeech.

I got to hear the following speakers (in no particular order):

  • Refactoring Databases – Pramod Sadalage
  • Testing Data Access Code Programmatically – Roy Osherove
  • .NET Cardspaces – Rene Løhde
  • Introduction to Spring.NET – Mark Pollack
  • .NET Language Integrated Query (LINQ) – Luca Bolognese
  • C# 3.0 Under the Hood – Mads Torgersen
  • Scrum @ Yahoo – Gabrielle Benefield
  • Democratizing the Cloud – Erik Meijer

and several others. Sadalage, Osherove and Bolognese immediately got to have their blogs added to my feed-reader. Gabrielle Benefield gave a very good presentation but doesn’t seem to have blog, most unfortunately. The best speaker I heard at JAOO2007 was probably Roy Osherove, who both had some neat techniques to show, but also held the entire audience at his presentation awake and focussed with his style and humour. He ended his session with a small performance by him self on guitar, singing a tune about database design. Fantastic.

Roy Osherove

Luca Bolognese also had a very good mix of humour and coding in his presentation. He had 3 slides and then proceeded by writing code in a tweaked Visual Studio 2008 for 50 minutes. And everybody was kept focused throughout the entire session. Mads Torgensen actually used the same style, but Bolognese was the master of the new dicipline “codetainment”.

In addition I had the opportunity to hear Robert C. Martin (Uncle Bob) talk about applying craftsmanship to programming. Don’t know how useful it was, but Uncle Bob is very entertaining, and has some very strong opinions on rules every developer should “live” by.

Finally some pictures from JAOO2007:

CharlesInSpace
Charles Simonyi (inventor of Word and Excel) shows slides from his tour to space.

Ridehuset
Ridehuset, the main food and party area. Monday night conference party.

Sun Booth
The Sun Campus Ambassador from SDU being busy….

Exhibition area JAOO2007
Part of the exhibition area, IBM and Google booths in the foreground.

Well, that was JAOO2007. Already looking forward to 2008, with even more tutorials for me.