X

Geertjan's Blog

  • February 6, 2007

JavaMail Client on the NetBeans Platform (Step 5)

Geertjan Wielenga
Product Manager
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.

Join the discussion

Comments ( 2 )
  • Mamata Tuesday, March 27, 2007
    Hi Geertjan,
    I have followed exactly the same steps to create my navigator. But it does not work for me. Here you can find the details of my problem.
    http://www.nabble.com/navigator-panel-does-not-work-tf3475464.html
    Any help would be highly appreciated.
    Thanks.
    Mamata
  • Geertjan Wednesday, March 28, 2007
    Has your question been answered? I see Tim responded a bit. If not, please send an e-mail to geertjan.wielenga@sun.com, and please include as much of the code as possible in your e-mail, best would be to include as much of your module as relates to the problem as possible.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.