ItsNat in NetBeans IDE

I don't know much about the new ItsNat web framework, but enough to know that it is very friendly to NetBeans IDE. When you download and unzip the distro, you'll find you have a NetBeans project. You can then open it in the IDE and deploy it, which will result in a long list of samples being available from the browser.

One of ItsNat's strengths is its IDE agnosticism (same as Wicket). In other words, there are no special artifacts, it simply uses standard Java EE artifacts such as JSP, or HTML, or servlets, or general Java classes. (And no ItsNat-specific servlet or filter needs to be registered in web.xml.) Hence, there's no actual need for a plugin for this framework. However, it would be handy if one, on completion of the web application wizard, would have all the ItsNat JARs (just 4 of them are needed) on the application's classpath.

This absolutely minimal need is interesting enough to create a plugin around, to show the simplest imaginable implementation of the NetBeans API WebFrameworkProvider class, in the context of everything else that is needed to implement it.

  1. Set dependencies on the following:
    • Dialogs API
    • External Libraries
    • File System API
    • Java Project Support
    • Project API
    • Swing Layout Extensions Integration
    • UI Utilities API
    • Utilities API
    • Web APIs

  2. Create a class called ItsNatWebFrameworkProvider that extends WebFrameworkProvider . Even though ProjectClassPathExtender is deprecated, it seems to be the only way of getting the job done. Below is the whole class:

    public class ItsNatWebFrameworkProvider extends WebFrameworkProvider {
    
        private ItsNatWebModuleExtender panel;
    
        //Constructor sets framework name and tip
        //in the Frameworks panel:
        public ItsNatWebFrameworkProvider() {
            super("ItsNat", "ItsNat");
        }
    
        //You'll need to test somehow whether the
        //application supports the framework, for the
        //Project Properties dialog. For now, set to true:
        @Override
        public boolean isInWebModule(WebModule arg0) {
            return true;
        }
        
        //This method will be called from the panel.
        //It is the method that adds the library to the
        //application's classpath:
        public Set extendImpl(WebModule wm) {
    
            FileObject fo = wm.getDocumentBase();
            Project project = FileOwnerQuery.getOwner(fo);
            
            //Name of the library that must be in the Library Manager (see step 3 below):
            Library lib = LibraryManager.getDefault().getLibrary("ItsNat");
            if (lib != null) {
                ProjectClassPathExtender cpExtender = (ProjectClassPathExtender) 
                        project.getLookup().lookup(ProjectClassPathExtender.class);
                if (cpExtender != null) {
                    try {
                        cpExtender.addLibrary(lib);
                    } catch (IOException ioe) {
                        Exceptions.printStackTrace(ioe);
                    }
                } else {
                    Logger.getLogger("global").log(Level.INFO,
                            "WebProjectClassPathExtender not found in the project lookup of project: " + 
                            project.getProjectDirectory().getPath());
                }
            
            }
            return null;
        }
    
        //This method used to return "ConfigurationPanel",
        //but now returns "WebModuleExtender", which is the
        //lower section of the Frameworks panel. Currently,
        //this can't be null, even though we don't actually
        //need it in this case:
        @Override
        public WebModuleExtender createWebModuleExtender(WebModule wm, ExtenderController arg1) {
            panel = new ItsNatWebModuleExtender(this);
            return panel;
        }
    
        //In this case, no configuration files are needed
        //by the framework, but if they were, such as
        //struts-config.xml, this method would be where you
        //handle this:
        @Override
        public File[] getConfigurationFiles(WebModule arg0) {
            return null;
        }
        
    }

  3. Use the "Java SE Library Descriptor wizard" to add the 4 ItsNat JARs to the module. You'll have to go to the ItsNat site and download the distribution, then add the JARs to the Library Manager so that you can use the "Java SE Library Descriptor wizard" to wrap them in the module.

    This wizard will end up causing the ItsNat JARs to be installed in the Library Manager when the module is installed. Since the same module that adds the class above will also add the JARs to the Library Manager, the extendImpl method (defined above) will correctly find the library.

  4. Create a class called ItsNatWebModuleExtender that extends WebModuleExtender. Here is all the code:

    public class ItsNatWebModuleExtender extends WebModuleExtender {
    
        private ItsNatVisualPanel component;
        private final ItsNatWebFrameworkProvider framework;
        
          public ItsNatWebModuleExtender(ItsNatWebFrameworkProvider framework) {
            this.framework = framework;
            getComponent();
        }
        
        //Call the method in the frameworkprovider class
        //that will add the library to the classpath:
        @Override
        public Set extend(WebModule webModule) {
            return framework.extendImpl(webModule);
        }
    
        //Return the panel, which is done from the
        //constructor above:
        @Override
        public JComponent getComponent() {
               if (component == null) {
                component = new ItsNatVisualPanel();
            }
            return component;
        }
    
        @Override
        public HelpCtx getHelp() {
            return null;
        }
        
        @Override
        public boolean isValid() {
            return true;
        }
    
        @Override
        public void update() {}
    
        @Override
        public void addChangeListener(ChangeListener arg0) {}
        
        @Override
        public void removeChangeListener(ChangeListener arg0) {}
    
    }

  5. Use the "Wizard wizard". Make it a "Custom" and "Static" wizard, with 1 panel. Click Next and use "ItsNat" as the classname prefix. Click Finish. Refactor the generated classes to rename them to "ItsNatVisualPanel" and "ItsNatWizardPanel". Since we don't need to have the user configure anything, we can just leave these classes untouched. However, since currently null can't be returned (which would make more sense in this case), add a JLabel to the visual panel and then set the text to "No configuration needed." At least this way there'll not be nothing at all under the "ItsNat Configuration" label in the Frameworks panel.

    NB: You can delete the "ItsNatWizardPanel". Why? Because there's no longer integration with the Wizard API. Instead of using the Wizard wizard, it is better to use the JPanel wizard, because all you need is a JPanel here, unlike before in the 5.5 version of the WebFrameworkProvider API class. This is a very good improvement, in my opinion. (For other changes in the 6.0 version of the WebFrameworkSupport class, click here).

  6. Register the framework provider class that you created in the first step above:

    <folder name="j2ee">
        <folder name="webtier">
            <folder name="framework">
                <file name="org-netbeans-modules-itsnatframeworksupport-ItsNatWebFrameworkProvider.instance"/>
            </folder>
        </folder>
    </folder>

Install the module. Create a new web application. In the Frameworks panel, you'll have an entry for "ItsNat". Complete the wizard... and the ItsNat JARs will be found within the Libraries node.

Comments:

Thanks for your ItsNat mini plug-in.

A note: ItsNat doesn't need JSP, I only use one JSP file (index.jsp) to start the Tomcat, normal mode and debug mode, on NetBeans :)

And certainly ItsNat is NetBeans friendly but it's so pure web that is a child game to create a new ItsNat based web project (or set up the Feature Showcase) using any other IDE.

And finally one idea for your plug-in: ItsNat doesn't provide a predefined servlet (and doesn't want), a very simple wizard can create an ItsNat capable servlet following the recommended set-up: a servlet class (concrete name can be entered) inheriting from org.itsnat.core.http.HttpServletWrapper with an empty init(ServletConfig) method calling the super method. No more predefined typical set up is needed because default values are usually the most appropriated ones. The HttpServletWrapper is very very mimimalist and its code can be generated too (avoiding this inheritance).

I'm sorry but at this moment ItsNat needs only a pure Java editor and a servlet container, I cannot give you more work to NetBeans :)

Anyway ItsNat code loves the Java editor and specially the "find uses" and refactoring part (as any other Java program). The HTML editor is nice too for me (I don't need any other). I'm a NetBeans user since Forte days.

Posted by Jose M. Arranz on January 20, 2008 at 03:31 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today