Tuesday February 06, 2007
JavaMail Client on the NetBeans Platform (Step 5)
My JavaMail client now has a Navigator for the current folder's subject lines, with a double-click action that opens the related e-mail in the Swing browser and HTML editor. The toolbar displays the name of the currently selected subject line's sender. Here's the result:

I was surprised how easy it was to create a Navigator. Actually, the Navigator displays a TopComponent, because that's what the getComponent() method returns. Here's the whole Navigator class:
public class SubjectNavigatorPanel implements NavigatorPanel {
public SubjectNavigatorPanel() {
}
public String getDisplayHint() {
return NbBundle.getMessage(SubjectNavigatorPanel.class, "HINT_SubjectNavigatorPanel");
}
public String getDisplayName() {
return NbBundle.getMessage(SubjectNavigatorPanel.class, "CTL_SubjectNavigatorPanel");
}
public JComponent getComponent() {
return SubjectLineTopComponent.getDefault();/
}
public void panelActivated(Lookup context) {
}
public void panelDeactivated() {
}
public Lookup getLookup() {
return null;
}
}
You also need a class that implements NavigatorLookupHint:
public class ShapeNavigatorHint implements NavigatorLookupHint {
public String getContentType () {
return "mail/client"; // NOI18N
}
}
Notice that a content type is set. This is matched in the layer.xml registration for the Navigator:
<folder name="Navigator">
<folder name="Panels">
<folder name="mail">
<folder name="client">
<file name="org-netbeans-modules-javamail-SubjectNavigatorPanel.instance"/>
</folder>
</folder>
</folder>
</folder>
So, notice that you don't even need a data object, or a MIME type. (Although, this is some kind of MIME type anyway.) Finally, I added the Navigator to the other TopComponent's Lookup, so that when the Mail Explorer opens, the Navigator opens as well. This Lookup is found in the Mail Explorer's constructor, and combines the Explorer Manager with the Navigator in my Lookup, thanks to a tip I picked up from the mailing list:
associateLookup(new ProxyLookup(new Lookup[]{
ExplorerUtils.createLookup(explorerManager, getActionMap()),
Lookups.fixed( new Object[] {new SubjectNavigatorHint()} )
}));
And, that's it. I have a method in the TopComponent, the one returned in the getComponent() method, for adding subject lines to a JList. So, at the appropriate time, the subject lines are added to the JList in the TopComponent that is inserted in the Navigator. Really simple.
Feb 06 2007, 07:03:54 AM PST Permalink


