Download NetBeans!

20080815 Friday August 15, 2008

Migrating from TreeTableView to OutlineView

Here, based on an existing example, is how to migrate from "TreeTableView" to the new NetBeans Platform 6.5 "OutlineView":

  1. Install the Marilyn TreeTableView Sample.

  2. Create the sample, i.e., choose "Samples | Java | Marilyn" in the New Project wizard and complete the steps in the wizard.

  3. Add the following JARs from "platform9" folder in the NetBeans installation directory to the app's classpath: org-openide-actions.jar, org-openide-awt.jar, org-openide-dialogs.jar, org-openide-explorer.jar, org-openide-nodes.jar, org-openide-util.jar.

  4. Run the application to check everything is working and that you're set for migration.

  5. Open demo.MyFirstFrame.java in the Design view. Delete the Swing component you find there, which is the TreeTableView.

  6. Right-click in the Palette to the right of the Design view and choose Palette Manager. Click "Add from JAR" and browse to "org-openide-explorer.jar". From the list of available components, choose "OutlineView" and click Next. Add it to any palette category and then click Finish.

  7. From the "platform9" folder, add the org-netbeans-swing-outline.jar onto the app's classpath.

  8. From the category where you added the "OutlineView" component, drag it onto the JFrame. Then switch to the Source view.

  9. Change these lines:
    treeTableView1.setProperties(props);
    treeTableView1.setRootVisible(false);

    To these lines:

    outlineView1.setProperties(props);
    //treeTableView1.setRootVisible(false);

  10. Run the application again and now you have the same result as before, except that you're using "OutlineView" instead of "TreeTableView".

In other words, you're using the same concepts as before, i.e., the Nodes API, the ExplorerManager, and the NodeTableModel. However, the explorer view is changed to one that is not buggy (which was the original reason for replacing TreeTableView) and has a few extra features, based on the "Outline" component. These additional features will be discussed here soon.

Aug 15 2008, 01:27:02 PM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/migrating_from_treetableview_to_outlineview
Comments:

It could be useful to have a screenshot of what the outline view looks like.

Posted by Vincent Cantin on August 15, 2008 at 06:36 PM PDT #

Same as the TreeTableView.

Posted by Geertjan on August 15, 2008 at 06:38 PM PDT #

You should mention for mac users how to find the jar files and add them to the classPath, due to a rather puzzling decision on how to distribute NetBeans.
On MacOS X, Netbeans is delivered as a 'package'. This is a folder which is presented to the user as if it were a single file. Therefore, I had a hell of a time finding the jar files you mentioned. Neither the system's indexed search feature (Spotlight) nor the unix 'locate' commands could find it, although the very slow unix 'find' command did get it.
The next problem is that when you try to add the classpath, the java file browser won't penetrate into the contents of the package. Adding the package seems to work, but the IDE still thinks the imported packages don't exist.
I haven't figured that out. I would appreciate help.

Posted by kevin Jaques on November 23, 2008 at 09:47 AM PST #

Here is a work around to the inability of NetBeans to penetrate its own Mac package structure to permit you to add JARs it contains to the ClassPath.
1. In Finder, control Click NetBeans application and choose, 'show package contents'.
2. in Finder, select the folder containing the NetBeans Application. Oddly, it comes locked down against any changes by administrators. So, 'get info', click the padlock, enter your administrator password, and then select 'read and write' access for administrators.
3. In Finder, option drag the 'contents' folder from the package contents to the Netbeans folder, making an alias.
4. Now, you can use the alias to permit Netbeans to access the contents of the Netbeans application package.
5. Remember to do this for every update. Prepare for frustration and confusion since you obviously won't remember that. Try renaming the alias to provide a hint.

Posted by kevin Jaques on November 23, 2008 at 10:26 AM PST #

NetBeans 6.5 did not contain org-openide-util.jar. It did contain org-openide-util-enumerations.jar. That didn't work. You can download this library from http://www.java2s.com/Code/Jar/netbeans-5.5/Downloadorgopenideutiljar.htm.
Note that it appears to be from a much prior version. Oh oh.
Anyway, on the Mac, Apple recommends that java Class Libraries get installed into either "/Library/Java/Extensions" or "~/Library/Java/Extensions". However, NetBeans doesn't see them there.
Adding the jar file as a new Library to Netbeans or adding the path to it under global library doesn't solve the problem. You must right click 'Libraries' under the project in the projects window, and choose 'add jar'.

Posted by Kevin Jaques on November 23, 2008 at 11:11 AM PST #

By the way, the math question must time out or something. It only works for me when I hit it very quickly after the page loads.

Posted by Kevin Jaques on November 23, 2008 at 11:12 AM PST #

The demo, prior to conversion, doesn't run. It complains of "no such method" regarding the 'mutex' method from the obsolete openIDE library I just posted about.
It says:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.openide.util.Mutex.<init>(Lorg/openide/util/Mutex$Privileged;Ljava/util/concurrent/Executor;)V
at org.openide.nodes.Children.<clinit>(Children.java:99)
at org.openide.nodes.Node.<clinit>(Node.java:111)
at org.openide.explorer.ExplorerManager.init(ExplorerManager.java:159)
at org.openide.explorer.ExplorerManager.<init>(ExplorerManager.java:153)
at demo.MyFirstFrame.<init>(MyFirstFrame.java:30)
at demo.MyFirstFrame$1.run(MyFirstFrame.java:96)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Posted by kevin Jaques on November 23, 2008 at 11:25 AM PST #

It would be completely impossible to run NetBeans IDE if it didn't contain org-openide-util.jar.

Posted by Geertjan on November 24, 2008 at 09:58 AM PST #

You removed the "treeTableView1.setRootVisible(false);" line in the ported version. Is it possible to hide the root node in the OutlineView? If this isn't possible directly, is there another way to achieve this, without using a custom tree model and Outline?

Posted by Achim on January 11, 2009 at 11:32 AM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed