Tuesday, October 20, 2009

Serial Version UID - Netbeans 6.8 M2

Providing a code template is a very simple affair in Netbeans. You can manually create the entry in the options dialog or write a plugin. The plugin affair is quite simple.

Steps:

  1. Create a new NB Module
  2. Expand the Tree as follows in the projects view
    1. -->Important files-->XML Layer-->-->Editors-->text-->x-java-->CodeTemplates-->Defaults
    2. Right click on the file named org-netbeans-modules-editor-java-codetemplates.xml.
    3. Click Edit
    4. append the following line near the end of the file (before the </codetemplates> tag)  
<codetemplate abbreviation="suid" descriptionId="Generate Serial version uid"><code><![CDATA[private static final long serialVersionUID = 1L; ]]></code></codetemplate>
    • Run the project, 
    • a new instance of netbeans will be started. 
    • Bring up the options dialog. 
    • Click on editor-->Code templates tab
    • Select Java as the language
    • Scroll down the list looking for suid
    Viola, code template ready.


    Another option is to use the code generator




    1. in the module create above right click on the module package and click new
    2. Optionally click other
    3. Select code generator in the Module development
    4. Provide a name
    5. in the mime type enter text/x-java
    6. Open the class that is generated and search for the getDisplayName method and replace the method content as return NbBundle.getMessage(SerialVersionUIDGenerator.class, "SerialVersionUIDGenerator.label");
    7. Now for the meat of the implementation. Search for the invoke method and add the following contents


            Caret caret = textComp.getCaret();
            int start = Math.min(caret.getDot(), caret.getMark());
            StringBuilder builder = new StringBuilder("private static final long serialVersionUID = 1L;");
            builder.append(System.getProperty("line.separator","\n"));
            Document doc = textComp.getDocument();
            try {
                doc.insertString(start, builder.toString(), null);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }

    The plugin is available for download from Kenai or netbeans plugin portal

    Monday, October 20, 2008

    Rebuild application on top of the NB Platform

    My colleague and friend Dinesh had a problem which goes like this
    Can I take my application xStudio and port it on top of the NBPlatform? What I am looking for is
    this -
    1. My Code base should remain fairly intact.
    2. I want my own menus and toolbars and splash screens.
    3. What I need NB to take care of is Interaction between different views - Tree and table, Report generation based on selected node, row etc.
    4. What code I want to eliminate is mainly all the listeners we use to report user input among different widgets
    5. Maintain organisation 's UI standards.
    Given this criteria - it took me 9 hours in total to figure it out. - 4 hours to read tutorials and try them out and 5 hours to complete the task.

    Preparation -
    Understand thoroughly the concepts explained in the NB Quick start guide. This tutorial completes problems 2&5 by just editing one XML file that too by using context menus alone.

    Selection management tutorial completed the rest.

    Steps followed -
    1. Replace NB actions with our actions - simple to do since both are javax.swing.Action.
    2. Replace JSplitpanes with NB topcomponents
    3. Replace Tree and table combo with the TreeTableView (slight refactoring in our datamodel accomplished this).

    9 hours later application has been ported.

    Sorry no screen shots are available due to organisation's legal restrictions.

    To fully understand the NB architecture, one has to just start with the quick start and system file system tutorial and after that things are rather simple.

    Happy 10th Birthday Netbeans - My Genesis with NB

    Today Netbeans reaches a decade milestone and wow what a progression.

    I saw netbeans long back in the year 2000 (yep Y2K) when I first saw it on java.sun.com and the Sun application Forte for java (built on NB3) rechristened as Sun One studio. That is when I first moved away from batch files, editplus/text pad and DOS editor and Forte For Java was my first Java IDDE and there was no looking back.

    That was NB3.0. Then couple of years later, Sun one studio became bloated which was not to my liking. Thats when I fully transitioned into a NB user starting with NB3.5 and there has been no looking back. In my organisation I am the only one who uses NB for development. I have given a couple of plugins, developed (not marketed) one NB based application and with NB6.5 beta the progression can only be forward.

    What is the next best thing after NB - the netbeans community. 90% of the time I faced problems or issues, I find answers here within the community - be it code snippets, docs, tutorials or forum threads. The rest 10% I can figure it out based on related information. After all I should be doing something.

    If there is anything I miss from the later releases (NB 5 I guess) of NB it is the MDI view. Why did you guys remove it. Bring it back, Bring it back.

    Friday, August 29, 2008

    Netbeans6.1 Plugin - Export as archive version 1.02.1

    Read all about the Export as archive version 1.01.1.

    In this version I have provided a dialog to choose the archive name and the folder in which the archive has to be created. The rest is the same.

    I have a question from users
    1. Is the dialog neccessary
    2. If not all the time, would a check box "Don't show dialog again" suffice

    Do provide your comments.

    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.

    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.




    my Experiences with Netbeans

    For a long time I was enamoured by Forte For Java with their broken App theme. Then I gave up with Netbeans turning out to be lighter and swifter. Since that time I have been developing with Netbeans much to the amusement and sometime frustration of my colleagues who use Eclipse. I have worked with eclipse enough time to hate it. I hate it all the more when it gives me OutOfmemory error when I run a build using ANT. But I digress. The objective of this blog is not to make Netbeans look good by describing Eclipse as bad.

    What role does an IDDE play in the development life cycle?

    Most of the time an IDDE is linked with DnD type of programming suitable for GUI building. But an IDDE is more than that. The following are what I looked for and got from Netbeans (6 being the best till date).

    1. No Spoon feeding - Let the IDDE make me write code related to business need and prevent me from templates and boiler plates. Netbeans does not provide different types of code templates like what Eclipse does. For ex. in Eclipse if I type test and use ctrl+space it gives me a lot of options. Netbeans does not do that. (10 for Eclipse, -1 for Netbeans)

    2. The IDDE should be very responsive. A user action should result in near-immediate response. For ex. If i do a ctrl+space, my IDDE should not go into a Zombie state and hang for a long time or worse crash. (10 for Netbeans, -1 for eclipse)

    3. Bare platform should be sufficient. It is wrong to assume that a desktop/library developer would not be needing web components. In Eclipse you need to pull in plugins and additional things, cross your fingers, toes, hands and legs and pray that this would work. Netbeans gives it to me without much ado. - No plugins needed. (10 For Netbeans, -5 for Eclipse)

    4. User Interface and accessibility. Less said about eclipse, the better. Sad part is NB6 has moved a little in the eclipse direction. Most of the key board short cuts have changed and it needed some trying around to figure out how to get the NB 5 Keyboard mappings. Eclipse Debug window is a pain. To add a watch statement, I need to right click on the breakpoint and select a menu option. Pain!!!
    (Would have given 10 to Netbeans but they deserve to be punished for the Key mapping fiasco. So for this I give 5 to Netbeans and -1 to Eclipse)

    5. Bloated workspace: I hate the concept of the workspace in eclipse. Every time I create a workspace, I need to give a lot of MBs for the .metadata folder. Check the properties of that folder any time and you would wonder, why do I need plugins in my workspace when my eclipse installation has it. Change settings in the workspace and when I move to a new workspace, I need to change the same settings again? Why? In my 10 years of working with technology I never found a need for such a feature. Netbeans use XML to maintain the information instead of copying needed plugins to the workspace. Infact there is no concept of workspace in netbeans.
    (10 for Netbeans and -1 for Eclipse).

    6. If there was one feature in Eclipse which I liked very much was the CVS feature. Netbeans 5 was pathetic in terms of diff, commiting etc. But with NB 6, Netbeans has thrashed eclipse soundly. ( So 5 for Netbeans and 10 for Eclipse for getting it right earlier)

    7. Web tech debugging. Ever tried debugging a JSP in Eclipse, by just setting your break point and invoking the debugger. In Netbeans I just need to do that. The time I saved by NB Debugger feature is legendary. (-1 for Eclipse, 10 for Netbeans). I would have given -10 for this feature to eclipse, but did not since it would seem vengeful.

    On a final note - Netbeans should be watchful that it does not fall into the trap of Eclipse of being unwieldy with nice features that dont work.


    So total Score
    Netbeans : 49
    Eclipse : 9