Download NetBeans!

20090405 Sunday April 05, 2009

Return of Marilyn Monroe

I'm rewriting the world famous Marilyn Monroe sample, using the various improvements/simplifications that have occurred since the time I first wrote it years ago—OutlineView instead of BeanTreeView, ChildFactory instead of Children.Keys, and the JDK 6 for-loop instead of the old iterators.

The result looks as follows:

If you want to take a look at it, especially if you want to learn about OutlineView, get it here:

http://blogs.sun.com/geertjan/resource/Marilyn-2.zip

Note that I haven't added the cut/copy/delete actions yet. So, right now the sample only shows how to create nodes and properties and how to display those in an OutlineView.

To me, the most interesting thing is how the property gets the current Movie object:

Property[] props = new Property[]{
    new ReviewProperty(em.getExploredContext().getLookup().lookup(Movie.class))
};

outlineView1.setProperties(props);

That's possible because when the MovieNode is created, it adds the current Movie object into the Lookup, which is then available to the ExplorerManager:

public MovieNode(Movie item) {
    super(Children.LEAF, Lookups.singleton(item));
    this.movie = item;
    setDisplayName(item.getTitle());
    setIconBaseWithExtension("/org/demo/marilyn/resources/marilyn.gif");
}

Slightly more advanced version of the above, using the CheckableNode class:

What's interesting about the above is that I now have three modules: the "Marilyn" display window, the "Selected Movies" window, and the API consisting of the domain objects shared between the other two. Whenever a movie is selected, it is added to the InstanceContent (a dynamic travel bag of objects placed in the application's context). The "Selected Movies" window listens to the context for the introduction of movies into it. At that point, the method for returning the title is called on the movie object, which is then added to the text area in the "Selected Movies" window.

Apr 05 2009, 04:28:13 AM PDT Permalink

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

Thanks for the project ! How do you define a dependency on ConvertAsProperties? Is there an extra Jar file to include? (org.netbeans.api.settings.ConvertAsProperties)

Posted by RunningTracker on April 05, 2009 at 11:48 AM PDT #

You need to be using some recent dev build of NetBeans IDE 6.7, which is where I developed the sample and which includes that JAR. It relates to a new annotation for handling persistence of topcomponents.

Posted by Geertjan on April 06, 2009 at 03:20 AM PDT #

@Geertjan: do you know a way to remove the "..." button from the review column?

Posted by RunningTracker on May 21, 2009 at 08:59 AM PDT #

How do you change the text of the first column header from "Node"?

Posted by 173.24.232.118 on June 27, 2009 at 12:11 AM PDT #

Hi Geertjan, could you please post the code for the Video Store (Return of Marilyn Monroe). I managed to get the same behavior as shown in the example, but I don't like my code. Maybe I get some ideas from your code.

Thanks Markus

Posted by Markus on October 20, 2009 at 03:14 AM PDT #

Here: http://blogs.sun.com/geertjan/entry/yet_another_return_for_marilyn

Posted by Geertjan Wielenga on October 25, 2009 at 05:03 AM PDT #

RunningTracker and 173.24.232.118, both questions are answered here:

http://blogs.sun.com/geertjan/entry/from_beantreeview_to_outlineview

Posted by Geertjan Wielenga on October 25, 2009 at 05:14 AM PDT #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed