Wednesday, June 11, 2008

Netbeans6.1 Plugin - Use System Desktop

This plugin taps into the potential of java.awt.Desktop and allows users to open/edit, view in browser and send by mail the selected node. the caveats are as follows.

1. Behaviour is not guaranteed to be as expected. For example browse and open can do the same thing - open in the default editor. My testing has shown that only html and xml files open properly in browser.
2. Mail - Selected file is not intriduced as an attachment since the mailto protocol does not support attachments.
3. There are no options to set. What ever is set on the operating system will be used.
4. When file association are not set; For example for manifest.mf file there might not be a file association. In these case you get an IOException which is shown to the user.
5. Works with Netbeans 6.1 and JDK6 only
6. Tested Platforms - Netbeans 6.1 and JDK6 Update 10 on Windows XP
7. BIG NOTE: If an application is not associated with the given file. it does not bring up the "Open With" dialog

Screen Shots




















Note: This plugin is not supported for NB with Java 5
if installed with Java 5, then you see an empty menu under Tools-->Desktop

The plugin is now available from within the Plugin manager.

Thursday, June 05, 2008

Netbeans6.1 Plugin - Export as archive

Netbeans has been a fascination for me. Ere it was Forte For Java which was then rechristened as sun java studio. Those were the days. Then Netbeans 5.0 happened. It was time to bid adieu to Java studio. In my current place of work, I am the source of frustration and amusement to many people since I am the only one to use Netbeans when the rest of the organisation is eclipse based. So you can see that friction is high because I am one against many in a debate on which is better - Netbeans or Eclipse. (see my previous post on why I find Netbeans as a better option). In one such debate came the notion of export as. Eclipse has many options for their Export As feature. But Netbeans does not. And so this plugin.

You can download the plugin from the netbeans plugin portal Export as archive. It is not available in the Plugin-manager now pending verification.

Supported Platform - Netbeans 6.1
You can click the Download button on the banner to the left to get Netbeans.

Plugin details -
The source code is available at http://nb61plugineas.svn.sourceforge.net/viewvc/nb61plugineas/ExportAsArchive


Now for the interesting parts.
The action extends from CookieAction and Over-rides two methods of interest
  • performAction(Node[] activatedNodes)
  • enable(Node[] activatedNodes).
first the enable method
This ensures if for a selected node the export option should be enabled or not. I would have preferred along with that a visible option. But since that is not available will survive with it though. So the way I am enabling the option is checking with the DataObject. If the DataObject does not have a primary file, then don't enable other wise enable it.

performAction method - delegates call to a simple private method.
This method picks up the primary file from the DataObject, constructs an Ant Script. The idea of using an Ant Script was inspired by Geertjan's blog. Earlier I used a grossly inefficient way - traversing directories and adding them to a Zip stream.

Steps to create such a Plugin
1. Create a New Project - Choose Netbeans Module-->Module
2. In the next screen fill up the entries but ensure that the Standalone radio button is selected.Tis marked in a red box.
3. Finish the wizard.
4. Click on the Project and Select New (Bring up the New File wizard)
5. Select Conditionally Enabled radio button and DataObject from the dropdown/combo box
6. In the next screen you can choose any combinations
7. Complete the wizard steps.
8. Provide implementation for the performAction method.
Simple 8 steps.
What to expect in future? For now I am thinking of two things. You can pour in your views.
1. Multiple Selected nodes (With restrictions of course)
2. Wizard like facility to choose destinations.

Enjoy archiving your projects.