Geertjan's Blog

  • July 12, 2007

Porting Kirk Pepperdine to the NetBeans Platform

Geertjan Wielenga
Product Manager
I had an excellent evening with the NetBeans User Group in Munich. About 30 or so, all hosted at the company where Toni Epple works. My presentation was 'Porting a Java Application to the NetBeans Platform'. Then there was a small session hanging out in a pub. We learned a lot from each other, but more about that in a future blog entry. I got back to the hotel to find an e-mail from Kirk Pepperdine, with some source code that he wanted to port to the NetBeans Platform. Hmmm... he should've been at the NetBeans User Group meeting where his scenario was discussed, because he had a container and so... he needs a TopComponent. Then a small bit of code movement into the TopComponent and then:

What you see is some test output that will come out of a performance tool that Kirk is working on. And, as you can see Kirk, running it on the NetBeans Platform means creating a new window (via the New Window Component wizard) and then adding the panel to the window. All the rest of the code is unchanged... Hurray, in the same evening that I preached the (relative) ease of porting I was able to put it into practise too!

Join the discussion

Comments ( 6 )
  • kirk Thursday, July 12, 2007
    Hey Geertjan,
    Nice work.. now how did you do it? ;-)
  • Geertjan Thursday, July 12, 2007
    1. Create a new module project, using the Module Project wizard in the New Project wizard.
    2. Copy all your classes into the module's source structure.
    3. Use the Window Component wizard to create stubs for a new window. Now, all the rest of the work you need to do involves moving stuff from com.kodework.netbeans.sites.ui.SitesWindow into the TopComponent.
    4. Set the layout in the TopComponent to BorderLayout, add a JScrollPane to the TopComponent, then add a JPanel to the JScrollPane, and also set that to BorderLayout. Don't use any code for this step, just the Matisse GUI Builder. (Optional to do it that way, but then the next step will make sense.)
    5. Assuming the TopComponent is called SitesTopComponent, let this be your TopComponent's constructor:
      private SitesTopComponent() {
      try {
      setName(org.openide.util.NbBundle.getMessage(kom.kodewerk.sites.SitesTopComponent.class, "CTL_SitesTopComponent"));
      setToolTipText(org.openide.util.NbBundle.getMessage(kom.kodewerk.sites.SitesTopComponent.class, "HINT_SitesTopComponent"));
      javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(java.lang.System.getProperty("user.dir"));
      int returnValue = chooser.showOpenDialog(null);
      if (!(returnValue == javax.swing.JFileChooser.APPROVE_OPTION)) {
      kom.kodewerk.sites.JSitesPanel panel = new kom.kodewerk.sites.JSitesPanel(chooser.getSelectedFile());
      } catch (IOException ex) {
    6. Now delete the SitesWindow class.
    7. I found that I needed to pass a java.io.File around, instead of a String, for some reason. So, instead of a file name, send the whole file, so you might need to tweak a few other classes to receive and handle the file rather than the file name.
    8. Right-click the module and install. Look under the Window menu and you will see a new menu item. Use it to open the new window. This will call up the file chooser and you can then select your file.
    9. Bob's your auntie.
    10. kirk Friday, July 13, 2007
      Nice, my problem is that I was trying to create the component on top of the already existing project. That doesn't quite work for some reason. So started hand coding a TopComponent instead of using Matisse. I like to do things the hard way ;-)
      SitesWindow is just a convince test harness. The real solution is to rid the constructor of the file chooser and have that in the profiler drop down menu instead.
      Wow, hacking netbeans in a blog.
    11. Geertjan Friday, July 13, 2007
      Yes, you need to create a new project called a 'Module Project', which is separate from your existing project. This provides the source structure and required files and entries for a new module, which is what you're creating. No need to handcode the TopComponent. Really. Just use the New Window Component wizard. I agree about the file chooser, that should ultimately be removed. I'm pretty sure that there are no API's for the Profiler, so you wouldn't be able to integrate with the Profiler. You'd probably open the file from the Favorites window instead. Once you are at the stage where you can see the TopComponent with your data, as in this blog entry, we can go to that next step. And how to include the result in the NetBeans distro? Well, just right-click the module project and choose Create NBM. Then you have an NBM file, which is a binary containing your module. That can be distributed via an update center. You could add the NBM to the Plugin Portal, once it is finished.
    12. Markus Jais Friday, July 13, 2007
      Hi Geertjan
      thanks a lot again for the talk yesterday. I learned a lot.
      and thanks for writing some of it down again here in your blog.
    13. Toni Epple Friday, July 13, 2007
      Hi Geertjan, thanks again for the great talk at our NetBeans Usergroup meeting, we enjoyed it a lot; and thanks for porting Kirk Pepperdine! I just picture him on my screen saying: "It looks like you're tuning an application. Would you like help?" :) Toni
    Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.