X

Geertjan's Blog

  • February 17, 2007

Layer-Based Popup Menus in TopComponents

Geertjan Wielenga
Product Manager
I've learnt something pretty interesting from Tonny Kohar, the NetBeans module writer, based in Indonesia, who is the project lead of the team that created Sketsa SVG Editor. I've been working on an interview with him and, when it is published, you'll see that he describes a very interesting tip. You can build popup menus in your custom TopComponent by using the NetBeans Lookup API to leverage entries in your layer.xml file. So, here's what the user sees, in my implementation of this approach:

Installed in my toolbar is a TopComponent with a JLabel and JTextField. (Same approach as in the NetBeans Google Toolbar Module Tutorial, except that I'm using a TopComponent instead of a JPanel.) However, you also see a popup. The menu items in the popup come from my layer.xml file. I've added a MouseListener to the JTextField, which triggers the building of the menu items when the popup is invoked. The building of the popup menu items is done through the Lookup API, which Tonny finds absolutely fantastic, as you'll see when you read the interview (once it is published). As a result, it is very easy for external contributors to add their own menu items to my popup, because they can just register their contributions in the same folder structure that I did when I created my module:

<folder name="Web">
<folder name="Search">
<folder name="Engines">
<file name="GoogleAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-mysearch-GoogleAction.instance"/>
</file>
<file name="WebcrawlerAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-mysearch-WebcrawlerAction.instance"/>
</file>
</folder>
</folder>
</folder>

So, if you had a menu item to add to my popup, you'd simply provide a module with your action, with a layer.xml folder structure like the above. Then the popup would be built seamlessly by the code in my module, and all you've done is contribute the action and the registration entries in your layer.xml file. For the code for this scenario, as well as a technical interview and extensive explanation of the usefulness of the above approach, you'll have to wait a few days. The publication of the interview with Tonny should be within the coming week sometime.

In other news. Toni Epple, the guy behind Jarvis, spends some time discussing his project in this brand new interview: Meet a NetBeans Module Writer: Toni Epple. (You also get to see what he looks like!) If nothing else, you should play the Flash demo that he provides in the interview. You'll see that you can already pull data from a database straight into a JasperReport and then generate a PDF document from it. Toni is looking for contributors to his project and lists some open areas that, if you want to help, you might be interested in providing. If it were up to me, then sooner or later this visual designer for JasperReports would become part of the NetBeans code base. It is really really cool.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.