5 Working with NetBeans Modules

This chapter describes the basics of working with NetBeans Modules.

This chapter contains the following sections:

5.1 About NetBeans Modules

A NetBeans module is a Java archive file which contains Java classes written to interact with the NetBeans APIs. For more information, see Section 5.7, "Using the NetBeans APIs".

A module identifies itself as a module by an entry in its MANIFEST.MF file. NetBeans modules are packaged as NBM files (.nbm extension) for non-installer distribution, usually via the Plugins manager under the Tools menu.

NetBeans modules are written with one of two aims in mind:

  • Extending the IDE - You can very easily generate skeleton code for extending the IDE's functionality with new features. For example, you can use the skeleton code to write modules that make your favorite cutting-edge technologies available to the NetBeans IDE. Or, if you miss some functionality in the IDE, you can add it yourself, by using the skeleton code to write a module that provides the desired functionality.

  • Building a rich-client application - You can use the core of the IDE as a platform on top of which you develop standalone desktop applications. The core of the IDE is a separate product called the NetBeans Platform. For more information, see Section 5.2, "About the NetBeans Platform". By basing your application on the NetBeans Platform, you can save a lot of development time, because you can reuse the platform's existing features such as menus, toolbars, and windowing systems.

    Even though it is a separate product, there is little need to download the NetBeans Platform separately—you can develop the rich-client application in the IDE and then exclude the modules that are specific to the IDE but that are superfluous to your application. Only when you want to use a different version of the platform than is included in the IDE, does it make sense to download the NetBeans Platform and install the modules that define the application into it.

5.2 About the NetBeans Platform

The NetBeans Platform provides an application's common requirements—such as menus, document management, and settings—right out of the box. Building an application "on top of NetBeans" means that, instead of writing applications from scratch, you only provide the parts of your application that the NetBeans Platform doesn't already have. At the end of the development cycle, you bundle your application with the NetBeans Platform, saving you time and energy and resulting in a solid, reliable application.

5.3 Working with NetBeans Modules

A NetBeans module is a set of Java classes written to interact with the NetBeans APIs, for extending the IDE or for creating your own application on the NetBeans Platform. For more information, see Section 5.2, "About the NetBeans Platform" and Section 5.7, "Using the NetBeans APIs".

The following table outlines the development cycle of NetBeans modules, from creation to distribution.

Step Description
1. Set up the module
  1. Begin creating your module by using the module project template. For more information, see Section 5.6.2, "How to Create a Module Project".
  2. Optionally, if the module will consist of a collection of module projects, use the module suite project template. For more information, see Section 5.6.4, "How to Create a Module Suite Project". For example, the collection may make use of external JAR files. If this is the case, put the external JAR files on the module's classpath by using one or more library wrapper module project templates. For more information, see Section 5.6.3, "How to Create a Library Wrapper Module Project".

2. Develop the module
  1. Right-click a module project in the Projects window and choose New > Other.
  2. In the New File wizard, choose the best NetBeans API template for your programming needs. For more information, see Section 5.7.1, "Generating Skeleton API Implementations".

  3. After using a wizard, double-click the file that you would like to edit. Use the Source Editor to edit the file.

  4. Refer to the NetBeans API Javadoc.

3. Build the module Choose Build > Build Main Project or right-click any project and choose Build Project.
4. Try out the module Right-click a module project node and choose Run (later Reload in Target Platform) or Install/Reload in Development IDE to try out the module. For more information, see Section 5.12, "Trying Out a Module".
5. Distribute the module
  1. Right-click the module project and choose Create NBM. For more information, see Section 5.11.2, "How to Build an NBM File".

    An NBM file is created.

  2. Distribute the NBM file for installation via the Plugins manager.


5.4 Working with Rich-Client Applications

A rich-client application is a complete, functioning, standalone Swing application, built on top of the NetBeans Platform. For more information, see Section 5.2, "About the NetBeans Platform".

The following table outlines the development cycle of rich-client applications, from creation to distribution.

To perform this task: Follow these steps:
1. Set up the application.
  1. Begin creating your application by using the NetBeans Platform application project template. For more information, see Section 5.6.5, "How to Create a NetBeans Platform Application Project".
  2. Optionally, before going further, brand the application by providing a splash screen and other external customizations.

2. Develop the application.
  1. Begin creating each distinct part of your application by using the module project template. For more information, see Section 5.6.2, "How to Create a Module Project".
  2. Right-click a module project in the Projects window and choose New > Other.

  3. In the New File wizard, choose the best NetBeans API template for your programming needs. For more information, see Section 5.7.1, "Generating Skeleton API Implementations".

  4. After using a wizard, double-click the file that you would like to edit. Use the Source Editor to edit the file.

  5. Refer to the NetBeans API Javadoc.

3. Build the application. Choose Build > Build Main Project or right-click any project and choose Build Project.
4. Try out the application. Right-click the application project node and choose Run Project.
5. Brand the application.
  • Right-click the application node in the Projects window and choose Properties. Use the Application panel to brand the name of the application launcher.
  • Right-click the application node again, choose Branding, and then use the tabs Basic, Splash Screen, Window System, and Resource Bundles to brand these details of the application.

6. Distribute the application. You can distribute the application in any of the following ways:
  • Create a ZIP Distribution

    • Right-click the application project and choose Package as | ZIP Distribution. For more information, see Section 5.15.1, "How to Build a ZIP Distribution". The application's executable and its clusters are packaged in a ZIP distribution.

    • Distribute the ZIP file.

  • Create a JNLP Application

  • Create an installer

    • Right-click the application project and choose Project Properties. In the Installer panel, specify the installers you would like to create.

    • Close the Project Properties dialog, right-click the application project and choose Package as | Installers. The installers are created in the application 'dist' folder, visible in the Files window (Ctrl-2).

7. Distribute updates to the application.
  1. Right-click the application project and choose Create NBMs. For more information, see Section 5.11.2, "How to Build an NBM File". An NBM file is created for each module project in the application project. In addition, an autoupdate descriptor is created. For more information, see Section 5.13.2, "How to Generate an Autoupdate Descriptor".
  2. Distribute the NBM file for installation via the Plugins manager.


5.5 Module and Rich-Client Application Tasks: Quick Reference

This section common tasks you can perform with module projects.

To perform this task: Follow these steps:
Create a project.
  1. Choose File > New Project (Ctrl-Shift-N).
  2. Select the right template for your project. For more information, see Section 5.6.1, "About Module Project Templates".

Add a JAR file to a project's classpath.
  1. Choose File > New Project (Ctrl-Shift-N).
  2. From the NetBeans Modules category, select Library Wrapper Module. For more information, see Section 5.6.3, "How to Create a Library Wrapper Module Project".

  3. Follow the steps in the rest of the wizard.

Set up deployment dependencies between projects. After making a Module Suite project, you can create module projects in it, or add existing module projects to it. Then you can set up dependencies among projects in the suite by using the Libraries panel of each project's Project Properties dialog box. You create a module suite project as follows:
  1. Choose File > New Project (Ctrl-Shift-N).

  2. From the NetBeans Modules category, select Module Suite. For more information, see Section 5.6.4, "How to Create a Module Suite Project".

  3. Follow the steps in the rest of the wizard.

Build a project. Choose Build > Build Main Project (F11) or right-click any project node and choose Build Project. In addition, you can use the IDE to build the following:
Clean a project. Right-click the project node and choose Clean Project.
Run a project Choose Run > Run Main Project (F6) or right-click any project node and choose Run Project.
Attach source code to libraries for debugging.
  1. Choose Tools > Library Manager in the main menu.
  2. If the JAR file is not already registered in the Ant Library Manager, create a new library using the Add Library button.

  3. Select the library in the left panel of the Ant Library Manager.

  4. In the Classpath tab, click Add JAR/Folder and specify the location of the JAR file containing the compiled class files. The JAR must be the copied version in the project's release/modules/ext/ directory, not its original location that you picked it up from when creating the library wrapper project. A library can contain multiple JAR files.

  5. In the Sources tab, add the folder or archive file containing the source code.

Add Javadoc to a project.
  1. Choose Tools > Ant Libraries in the main menu.
  2. If the JAR file is not already registered in the Ant Library Manager, register the JAR file as described above.

  3. In the Javadoc tab, click Add ZIP/Folder and specify the location of the Javadoc files.

Set the main project. In the main menu, choose Run > Set Main Project and choose the project name.

5.6 Setting Up Modules

The IDE contains a set of standard project templates and file templates for setting up modules. The standard distribution of the IDE contains the following module project templates:

  • Module. Use a module project as the place where you code your module.

  • Library Wrapper Module. Use library wrapper module projects to put one or more library JAR files on a module's classpath.

  • Module Suite. Use a module suite project to group and deploy a set of interdependent module projects and library wrapper module projects.

  • NetBeans Platform Application. Use a NetBeans Platform Application project as the skeleton framework as the starting point of your own applications.

For more information, see Section 5.6.1, "About Module Project Templates".

The standard distribution of the IDE contains the following module file templates:

  • Action. Creates an action that can be invoked from a menu item, pop-up menu, toolbar button, or keyboard shortcut.

  • Code Generator. Creates a new menu item in the Insert Code popup in the editor of your choice.

  • File Type. Lets the IDE recognize a new type of file.

  • Java SE Library Descriptor. Adds a new class library to the Ant Library Manager of the user's IDE.

  • JavaHelp Help Set. Creates all the files needed for building a JavaHelp help set.

  • Installer/Activator. Creates a ModuleInstall class for a NetBeans module or a BundleActivator for OSGi bundles.

  • Layout of Windows. Lets you design the layout of the windows in your application.

  • Options Panel. Adds a new panel to the Options window.

  • Project Template. Adds a new template to the New Project wizard.

  • Quick Search Provider. Creates a new entry in the Quick Search field.

  • Update Center. Registers an update center in the Plugins manager. As a result, the user does not need to manually register the Update Center via the Plugins manager.

  • Window. Creates a new window with an Open action invoked from a menu item.

  • Wizard. Creates a new wizard for creating, for example, new files in the IDE.

  • XML Layer. Creates a layer file for registering folders and files into the central registry, also known as the System FileSystem.

Some of the file templates are used to kickstart your work with the NetBeans APIs. Other file templates are used for bundling supporting items, such as project samples and JavaHelp help sets, with your modules. For more information, see Section 5.7.1, "Generating Skeleton API Implementations" and Section 5.8, "Bundling Supporting Items".

5.6.1 About Module Project Templates

The IDE contains a set of standard project templates for module development. The standard distribution of the IDE contains the following module project templates:

  • Module. Use a module project as the place where you code your module.

  • Library Wrapper Module. Use library wrapper module projects to put one or more library JAR files on a module's classpath.

  • Module Suite. Use a module suite project to group and deploy a set of interdependent module projects and library wrapper module projects.

  • NetBeans Platform Application. Use a NetBeans Platform Application project as the skeleton framework as the starting point of your own applications.

Important Files

Module projects, library wrapper module projects, and module suite projects have an Important Files node where the IDE stores the Ant script, layer.xml file, and other project data.

The following table lists the highlights of the Important Files node and whether each is found in a module project template, a library wrapper module project template, a module suite project, or all three:

Item Description Availability
XML Layer The System Filesystem registration file (layer.xml). You use this file to register new items in the System Filesystem. When you use file-level templates, the IDE automatically registers items for you. For example, when you use the Action wizard, you specify that a Java class should be invoked as a menu item, toolbar button, or keyboard shortcut, and the IDE registers your specification accordingly in thelayer.xml file. Module Project
Build Script The build script called by the IDE. This build script only contains an import statement that imports targets from nbproject/build-impl.xml. Use the build.xml to override targets from build-impl.xml or to create new targets. All
Module Manifest The JAR manifest (MANIFEST.MF) with sections defining attributes for the module. By default, the MANIFEST.MF file created for a module project specifies its name, layer.xml, localizing bundle, and specification version. Module Project
Project Metadata The project.xml file. IDE-generated metadata file for specifying module dependencies and classpaths. Although you can edit project.xml manually, you generally do not need to. When you use a file-level template to create items, such as actions, the IDE automatically specifies module dependencies required by the item in question. Should you need to specify module dependencies yourself, use the Libraries panel in the project's Project Properties dialog box. For more information, see Section 5.7.1, "Generating Skeleton API Implementations". All

5.6.2 How to Create a Module Project

Use a module project template to create a module project. The module project is the place where you code your module. Module projects implement the module's features and functionality that extend the NetBeans APIs, which you kickstart by using file templates. In addition, module projects include the business logic that integrate the library wrapper module projects into the module. Code housed in module projects also provides, for example, the user interface for receiving and processing user input.

To create a module project:

  1. Choose File > New Project (Ctrl-Shift-N).

  2. From the NetBeans Modules category, select Module. Click Next.

  3. In the Name and Location panel, specify the following:

    • Project Name. Specifies the folder in which the project will be housed, prepended by the project location, which is specified in the next field.

    • Project Location. Specifies the location where you want to store the project metadata and source code.

    • Project Folder. Specifies the folder where you want to store the project metadata and source code. The folder is a concatenation of the project location and the project name.

    • Standalone Module. Specifies that the module does not belong to a module suite. In addition, you must specify which platform the module will be compiled and deployed against. To add additional platforms to the list, click Manage and use the NetBeans Platform Manager.

    • Add to Module Suite. Specifies that the module belongs to a module suite. If the module suite is not currently open in the IDE, click Browse to locate the module suite in your filesystem.

  4. Click Next.

  5. In the Basic Module Configuration panel, specify the following:

    • Code Name Base. Specifies a unique name for the module. A main package will be created with the same name as the code name base. If your code name base is org.modules.foo, your default package structure will be org/modules/foo.

    • Module Display Name. Specifies the name that will be displayed in the Projects window.

    • Localizing Bundle. Specifies location of the Bundle.properties file. Normally, the default suggestion should be appropriate.

    • OSGi Bundle. If the "Generate OSGi Bundle" checkbox is selected, an OSGi bundle will be created, instead of a NetBeans module. The difference will be visible in the Manifest file.

  6. Click Finish.

5.6.3 How to Create a Library Wrapper Module Project

Use a library wrapper module project template to create a library wrapper module project. Library wrapper module projects put one or more library JAR files on a module's classpath. You have to export some or all of the packages as public, and you need to have a regular module depend on it, or the library wrapper module becomes useless. The wizard that you use to create the library wrapper module project automatically exports as public any packages it finds in the JARs.

To create a library wrapper module project:

  1. Choose File > New Project (Ctrl-Shift-N).

  2. From the NetBeans Modules category, select Library Wrapper Module.

  3. In the Select Library panel, specify the following:

    • Library. Specifies one or more JAR files that make up the library. Use Shift-Click and Ctrl-Click to select more than one JAR file. You are encouraged to only include more than one JAR file if their versions are likely to increment at the same time.

    • License. Specifies the License of the JAR files.

  4. In the Name and Location panel, specify the following:

    • Project Name. Specifies the folder in which the project will be housed, prepended by the project location, which is specified in the next field.

    • Project Location. Specifies the location where you want to store the project metadata and source code.

    • Project Folder. Specifies the folder where you want to store the project metadata and source code. The folder is a concatenation of the project location and the project name.

    • Add to Module Suite. Specifies that the module belongs to a module suite. If the module suite is not currently open in the IDE, click Browse to locate the module suite in your filesystem.

  5. Click Next.

  6. In the Basic Module Configuration panel, specify the following:

    • Code Name Base. Specifies a unique name for the module. A main package will be created with the same name as the code name base. If your code name base is org.modules.foo, your default package structure will be org/modules/foo.

    • Module Display Name. Specifies the name that will be displayed in the Projects window.

    • Localizing Bundle. Specifies location of the Bundle.properties file. Normally, the default suggestion should be appropriate.

  7. Click Finish.

5.6.4 How to Create a Module Suite Project

Use a module suite project template to create a module suite. A module suite groups and deploys a set of interdependent module projects and library wrapper module projects. For rich-client applications, the module suite project is a skeleton application to which you can attach a splash screen, a progress bar, a name for the application's executable, and a title for the application's titlebar.

To create a module suite project:

  1. Choose File > New Project (Ctrl-Shift-N).

  2. From the NetBeans Modules category, select Module Suite.

  3. In the Name and Location panel, specify the following:

    • Project Name. Specifies the folder in which the project will be housed, prepended by the project location, which is specified in the next field.

    • Project Location. Specifies the location where you want to store the project metadata.

    • Project Folder. Specifies the folder where you want to store the project metadata and source code. The folder is a concatenation of the project location and the project name.

    • NetBeans Platform. Specifies the platform against which the module will be compiled and deployed. To add additional platforms to the list, click Manage and use the NetBeans Platform Manager.

  4. Click Finish.

5.6.5 How to Create a NetBeans Platform Application Project

Use a NetBeans Platform Application project template to create the starting point of your application on top of the NetBeans Platform. This template project provides a skeleton application to which you can attach a splash screen, a progress bar, a name for the application's executable, and a title for the application's titlebar.

To create a NetBeans Platform Application project:

  1. Choose File > New Project (Ctrl-Shift-N).

  2. From the NetBeans Modules category, select NetBeans Platform Application.

  3. In the Name and Location panel, specify the following:

    • Project Name. Specifies the folder in which the project will be housed, prepended by the project location, which is specified in the next field.

    • Project Location. Specifies the location where you want to store the project metadata.

    • Project Folder. Specifies the folder where you want to store the project metadata and source code. The folder is a concatenation of the project location and the project name.

    • NetBeans Platform. Specifies the platform against which the module will be compiled and deployed. To add additional platforms to the list, click Manage and use the NetBeans Platform Manager.

  4. Click Finish.

5.7 Using the NetBeans APIs

The NetBeans APIs are the public interfaces and classes which are available to module writers. They are divided into specific APIs for dealing with different types of functionality. The contents and behavior of the Java source packages and its subpackages, as specified in the NetBeans API List, are the NetBeans APIs. After you register the NetBeans API sources and Javadoc, you can refer to them in the Source Editor, while developing NetBeans modules. For more information, see Section 5.7.3, "How to Register the NetBeans Sources and Javadoc" and Section 5.7.4, "How to Use the NetBeans Sources and Javadoc".

For the NetBeans API List, see http://bits.netbeans.org/dev/javadoc/.

5.7.1 Generating Skeleton API Implementations

To simplify the process of working with the NetBeans APIs, the NetBeans IDE provides several wizards that guide you through the initial phase of working with a NetBeans API. For more information, see Section 5.7, "Using the NetBeans APIs". For example, the New Action wizard provides the basis of an implementation of the NetBeans Actions API, the New File Type wizard provides the basis of an implementation of the NetBeans Datasystems API, and so on.

The NetBeans API wizards are as follows:

  • Module. Use a module project as the place where you code your module.

  • Library Wrapper Module. Use library wrapper module projects to put one or more library JAR files on a module's classpath.

  • Module Suite. Use a module suite project to group and deploy a set of interdependent module projects and library wrapper module projects.

  • NetBeans Platform Application. Use a NetBeans Platform Application project as the skeleton framework as the starting point of your own applications.

Project Templates

Project templates come in two types:

  • Templates that users build on when creating their own project. For example, in the IDE a user chooses the 'Web Application' project template in the New Project wizard, then the IDE creates a project consisting of a JSP file, a web.xml file, a server-specific deployment file, and project metadata within a specific structure that is useful for web application projects.

  • Samples that illustrate some aspect of project functionality. For example, in the Samples directory within the New Project wizard, an Anagram Game is included to demonstrate Java SE functionality. Samples are a kind of project template; they have the same behavior as project templates, but they are used for a different purpose.

A project template is made available to the IDE's New Project wizard once it has been registered in the layer.xml file. For more information, see Section 5.9.2, "About XML Layer Files".

You use the New Project Template wizard to create the basic files and to register the template in the layer.xml file.

Before you can use the New Project Template wizard, you must have project in the IDE that is structured in exactly the way that you would like it to be available in the New Project wizard. For example, if you are going to create a new project sample, you must first lay it out in the IDE. Then use the New Project Template wizard to add the template to the New Project wizard.

When you make the module that contains the new project template available as an NBM file, the user can install it via the Plugins manager and then, once it has been successfully installed, select it from the New Project wizard.

The standard distribution of the IDE contains the following module file templates:

  • Action. Creates an action that can be invoked from a menu item, pop-up menu, toolbar button, or keyboard shortcut.

  • Code Generator. Creates a new menu item in the Insert Code popup in the editor of your choice.

  • File Type. Lets the IDE recognize a new file type.

  • Java SE Library Descriptor. Adds a new class library to the Ant Library Manager of the user's IDE.

  • JavaHelp Help Set. Creates all the files needed for building a JavaHelp help set.

  • Installer/Activator. Creates a ModuleInstall class for a NetBeans module or a BundleActivator for OSGi bundles.

  • Layout of Windows. Lets you design the layout of the windows in your application.

  • Options Panel. Adds a new panel to the Options window.

  • Project Template. Adds a new template to the New Project wizard.

  • Quick Search Provider. Creates a new entry in the Quick Search field.

  • Update Center. Registers an update center in the Plugins manager. As a result, the user does not need to manually register the Update Center in the Plugins manager.

  • Window. Creates a new window with an Open action invoked from a menu item.

  • Wizard. Creates a new wizard for creating, for example, new files in the IDE.

  • XML Layer. Creates a layer file for registering folders and files into the central registry, also known as the System FileSystem.

The NetBeans API wizards create the starting point for your development activities. Once you have worked through a wizard, you build your module's functionality on top of the files that the wizard creates for you.

Related NetBeans API Javadoc

The NetBeans API wizards create the starting point for your development activities. Once you have worked through a wizard, you build your module's functionality on top of the files that the wizard creates for you.

The following table lists the Javadoc that you will need to refer to when building on top of the skeleton API implementations:

File Template Related NetBeans Javadoc
Action Utilities API
File Type Datasystems API
Module Installer Module System API
Options Panel Options Dialog and SPI
Project Template Project UI API

Project API

Window Window System API
Wizard Dialogs API

5.7.1.1 About Actions

Actions are defined by the Actions API.

The Actions API is a standard representation of the actions a user can invoke. It provides an interface to such IDE elements as toolbars, menus, and keyboard shortcuts, allowing third parties to create actions that are sensitive to context and invocable in more than one way. The Actions API offers the ability to write the action once, and have it automatically apply as appropriate. For example, a user action might both show up in a toolbar and be selected by a keyboard shortcut, all from the same implementation.Actions are typically presented in pop-up menus, or attached to a component such as a window, node, or data object.

5.7.1.2 How to Create an Action

The New Action wizard creates a new action. For more information, see Section 5.7.1.1, "About Actions".

To create a new action:

  1. Right-click a module project and choose New > Action.

  2. In the Action Type page, you set the type:

    • Always Enabled. Specifies that the action will be invoked from a menu item in the menu bar, from a toolbar button in a toolbar, or from a keyboard shortcut anywhere in the IDE.

    • Conditionally Enabled. Specifies the classes for which the action will be created. This is normally one of your own business objects. However, optionally, you can also include one or more of the following, which creates the action for all classes that subclass them:

      • DataObject

      • EditCookie

      • EditorCookie

      • OpenCookie

      • Project

  3. User Selects One Node.

  4. User May Select Multiple Nodes. Specifies the conditions under which the action will be enabled. By default, will be enabled if one, and only one, node holding the business object of interest is selected. If checked, it will also be enabled if multiple nodes all holding the desired business object(s) are selected.

  5. Click Next.

  6. In the GUI Registration page, you have to specify how the user will be able to call the new action.

    • Category. Specifies where the action will be displayed in the Keymap section of the Options window.

    • Global Menu Item. Specifies the menu where the action will be displayed as an item. You can also specify the position within the menu, and whether you want a separator to appear before it, after it, or both.

    • Global Toolbar Button. Specifies the toolbar where the action will be displayed as a button. You can also specify the position within the toolbar.

    • Global Keyboard Shortcut. Specifies a shortcut that will invoke the action.

    Only if Conditionally Enabled is selected in the Action Type page can you set the following items:

    • File Type Context Menu Item. Specifies the file type where the action will be displayed in the pop-up menu.

    • Editor Context Menu Item. Specifies the IDE editor where the action will be displayed in the pop-up menu.

    Click Next.

  7. In the Name, Icon, and Location page, you set the following:

    • Class Name. Specifies the name of the new Action class.

    • Display Name. Specifies the action's label. (Optional)

    • Icon. Specifies the icon that will accompany the action. For example, if the action will be invoked by a toolbar button, the icon specified here is displayed on the toolbar button.

    • Package. Specifies the name of the package where the class will be housed.

    Click Finish.

  8. After completing the wizard, you can do the following:

    • Tweak the layer.xml file to change the icon or to rearrange the position of the action within the actions provided by the available modules. For more information, see Section 5.9.2, "About XML Layer Files".

5.7.1.3 About Code Generators

A code generator is an action that is added to the Insert Code popup, which the user invokes when pressing Alt-Insert. When invoked, the action is intended to insert code into the editor. Traditionally, code generators are only found in Java documents but, from NetBeans 6.1 onwards, they can also be found in all other types of documents.

Via the Code Generator SPI and the accompanying Code Generator wizard, you can quickly and easily extend the code generator popup for a specific MIME type with new entries.

5.7.1.4 How to Create a Code Generator

A code generator is an item added to the popup that appears in an editor when Alt-Insert is pressed. For more information, see Section 5.7.1.3, "About Code Generators".

By default, for example, when you press Alt-Insert in a Java class, a constructor can be generated.

To create a new code generator:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Code Generator under the Module Development category.

  2. In the Code Generator page, set the following:

    • Class Name. Specifies the name of the new code generator.

    • MimeType. Specifies a unique Multipurpose Internet Mail Extension (MIME) type that enables the code generator to be registered in the layer.xml file.

    • Generate Code Generator Context Provider. Specifies that a class should be created, and registered in the layer.xml file, for adding new objects to the code generator's lookup.

  3. Click Finish.

5.7.1.5 About File Types

Many file types are recognized by default by the IDE. For example, JSP files, Java source files, and HTML files are recognized as such and the IDE provides functionality specific to the file type. For example—for JSP and HTML files, the IDE provides special syntax highlighting that is different from the syntax highlighting provided for Java source files. In addition, the menu items provided for JSP files are different from those provided for HTML files. For example, you can compile a JSP file but not an HTML file.

Recognition of a file type is generally made possible via its extension. All JSP files have a .jsp extension, while all Java source files have a .java extension. On the basis of this distinction, the IDE provides distinct functionality for these file types. You can use the New File Type wizard to let the IDE recognize additional file types, i.e., file types that are not recognized by the IDE by default. For example, if you have a file type with the file extension .xyz, you can let the IDE recognize all files with this extension and then provide functionality specifically for this file type.

But you can also let the IDE distinguish between XML files. Whether an XML file has an .xml extension, you can let the IDE provide different functionality for abc.xml than for def.xml, based on the namespace defined for the XML file in question. If the namespace of each distinguishable XML file is distinct, the namespace is used to distinguish the file types in this case.

When you use the New File Type wizard, the IDE creates the following files for you:

File Purpose
xxxDataObject.java A class that extends Class MultiDataObject.
xxxResolver.xml Declarative resolution of MIME-type.
xxxTemplate.xxx Dummy template, registered in the layer.xml file as a file template.

5.7.1.6 How to Create a File Type

The New File Type wizard creates a new file type. For more information, see Section 5.7.1.5, "About File Types".

To create a new file type:

  1. Right-click a module project and choose New > File Type.

  2. In the File Recognition page, set the following:

    • MIME Type. Specifies a unique Multipurpose Internet Mail Extension (MIME) type that enables the file type to be registered in the layer.xml file. Together, the MIME type and the filename extension or XML root element enable the IDE to distinguish one file type from another.

    • by

      • Filename Extension. Specifies one or more file extensions that the IDE will recognize as belonging to the specified MIME type. The file extension can optionally be preceded by a dot. Separators are commas, spaces, or both. Therefore, all of the following are valid:

        .abc,.def

        .abc .def

        abc def

        abc,.def ghi, .wow

      • XML Root Element. Specifies a unique namespace that distinguishes the XML file type from all other XML file types.

        The value that you specify is the namespace associated with the root element of your XML document. Note that this is not the same thing as the name of the root element. For example, in the following example XML document, the namespace is "sample":

        <mydata xmlns="sample"></mydata>

  3. In the Name, Icon, and Location page, set the following:

    • Class Name. Specifies the name of the new files that will be generated.

    • Icon. Specifies the icon that will accompany the new file type. For example, when you see the new file type in the Projects window, Files window, or Favorites window, it will be identified by the icon specified here. (Optional)

    • Use MultiView. Specifies that additional files should be generated as the starting point of an extensible multiview editor.

    • Package. Specifies the name of the package where the class will be housed.

  4. After completing the wizard, you can do one or more of the following:

    • Tweak the layer.xml file to change the icon or to rearrange the position of the action within the actions provided by the available modules. For more information, see Section 5.9.2, "About XML Layer Files".

    • Add properties to the default property sheet used by the new file type.

    • Use the New Action wizard to add actions to the new file type's pop-up menu. When you do so, select Conditionally Enabled in the first page of the New Action wizard.

    • Use the New Wizard wizard to create a New File wizard that the user will use to create new files of the new type defined in the New File Type wizard.

    • Use the New Project Template wizard to add a sample project containing example files of the new file type to the New Project wizard.

    • Add advanced support for the file type, such as syntax highlighting.

5.7.1.7 About Module Installers

A module installer is a Java class that provides hooks for running code on startup or when a module is loaded. It can also run cleanup code when a module is uninstalled or disabled.

Note: In general, using a module installer is not recommended, because it slows down startup time. Before using a module installer, make sure that there is no declarative way of doing what you are trying to do. The main declarative way of installing items is to use the org.openide.util.lookup.ServiceProvider annotation or create an XML layer file that declares information about the items your module is installing. For more information, see Section 5.9.2, "About XML Layer Files".

Then, when they are needed to do actual work, your items will be instantiated.

In addition to providing a module installer class, you need to add an entry to the MANIFEST file. The Module Installer Wizard creates a skeleton implementation of a module installer, adds the entry to the MANIFEST file, as well as entries to the project.xml file, which provides the module's metadata. For more information, see Section 5.7.1.9, "How to Create a Module Installer/Activator".

5.7.1.8 Installing Modules

Applications can install modules dynamically. Any application can include the Update Center module, to allow users of that application to download digitally-signed upgrades and new features via the web, directly into the running application. Installing an upgrade or a new release does not force users to download the entire application again. And in an application with multiple modules, upgrades of specific functionality can be incremental, further improving customer response time and time-to-market.

5.7.1.9 How to Create a Module Installer/Activator

A module installer (for a NetBeans module) or activator (for an OSGi bundle) is a Java class that provides hooks for running code on startup or when a module is loaded. It can also run cleanup code when a module is uninstalled or disabled.

To create a new installer/activator:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Installer/Activator under the Module Development category.

  2. In the New Installer/Activator page, you have to set Package. This specifies the name of the package where the module installer will be housed. The module installer will always be named Installer.

5.7.1.10 About Options Panels

An Options panel is a category of the Options window. The Options window is where the user defines settings, such as the location of the web browser used by the IDE. The category can be displayed as a primary panel (such as the "General" panel in the IDE) or as an addition to one of the other panels, for example, the Miscellaneous panel (such as the "Ant" or "GUI Builder" panel in the IDE's Miscellaneous panel).

You use the Options Panel wizard to create options panels.

5.7.1.11 How to Create an Options Panel

An Options panel adds a category to the IDE's Options window. For more information, see Section 5.7.1.10, "About Options Panels".

The category can be displayed as a primary panel (such as the "General" panel in the IDE) or as an addition to an existing panel, for example, the Miscellaneous panel (such as the "Ant" or "GUI Builder" panel in the IDE's Miscellaneous panel).

To create a new Options panel:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Options Panel under the Module Development category.

  2. In the Choose Panel Type page, choose one of the following:

    • Create Secondary Panel. Specifies that the category will be displayed as an addition to an existing panel, for example, the Miscellaneous panel (such as the "Ant" or "GUI Builder" panel in the IDE's Miscellaneous panel).

    • Create Primary Panel. Specifies that the category will be displayed as a primary panel (such as the "General" panel in the IDE).

  3. In the Location page, you have to set the following:

    • Class Prefix. Specifies the prefix of the source files generated by the wizard.

    • Package. Specifies the name of the package where the source files will be housed.

  4. After completing the wizard, you can do one or more of the following:

    • Add a titled border to make the Options panel resemble other NetBeans Options categories.

    • Use the GUI Builder to add items such as checkboxes and textfields to the generated panel.

5.7.1.12 About Quick Search Providers

A quick search provider is a Java class that lets you plug new items into the Quick Search feature in the IDE or any other application on top of the NetBeans Platform.

Quick search providers are registered in the layer.xml file. You can let the IDE create and register them by means of the Quick Search Provider wizard.

5.7.1.13 How to Create Quick Search Providers

A quick search provider is a Java class that lets you plug new items into the Quick Search feature in the IDE or any other application on top of the NetBeans Platform.

To create a new quick search provider:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Quick Search Provider under the Module Development category.

  2. In the File Recognition page, you have to set the following:

    • Provider Class Name. Specifies the class name of the stub that the wizard will generate.

    • Package. Specifies the package where the stub class will be generated.

    • Category Display Name. Specifies the display name of the category that the stub will create.

    • Command Prefix. Specifies prefix for narrowing the search to the category that the stub will create.

    • Position in Popup. Specifies the position of the new item in the within the Quick Search feature.

5.7.1.14 About Windows

A window component creates a window (also known as 'view') for a module. For example, the IDE's Projects window is a 'window', just as the Navigator, Output window, Palette, and Debugger. The main class in each of the modules that define these windows subclasses Class TopComponent.

Understanding and working with the TopComponent class is the key to creating useful and reliable windows in the IDE. By using the Window wizard, you can be sure of the success of the initial development phase. This is because when you use the New Window wizard, the IDE creates a Matisse GUI Builder form that extends the TopComponent class.

5.7.1.15 How to Create a Window

A window component creates a window (also known as 'view') for a module. For more information, see Section 5.7.1.14, "About Windows".

The IDE provides the Window wizard to simplify the initial creation process.

To create a new window component:

  1. Right-click a module project and choose New > Window.

  2. In the Basic Settings page, you set the following:

    • Window Position. Specifies the location of the window component when open in the IDE. Depending on the modules installed in the platform that forms the basis of your application, you're able to choose from several window positions, including the following:

      • bottomSlidingSide. The window component will be available as a button on the bottom bar of the IDE.

      • commonpalette. The default position of the IDE's Palette for HTML/JSP code snippets.

      • debugger. The default position of the IDE's Debugger.

      • editor. The default position of the IDE's Source Editor.

      • explorer. The default position of the IDE's Projects window.

      • leftSlidingSide. The window component will be available as a button on the left sidebar of the IDE.

      • navigator. The default position of the IDE's Navigator.

      • output. The default position of the IDE's Output window.

      • properties. The default position of the IDE's Properties window.

      • rightSlidingSide. The window component will be available as a button on the right side of the Source Editor.

    • Open on Application Start. Specifies whether the window component is open by default or not.

    • Keep preferred size when slided-in. Specifies that the size of the window when minimized will be determined by the preferred size property of the window. When selected, the following line is added to the TopComponent's constructor: putClientProperty("netbeans.winsys.tc.keep_preferred_size_when_slided_in", Boolean.TRUE);

    • Sliding not allowed.

      Closing not allowed.

      Undocking not allowed.

      Dragging not allowed.

      Maximization not allowed. Specify that the window should not have one or more features that it has by default.

  3. In the Name, Icon, and Location page, you have to set the following:

    • Class Name. Specifies the name of the new Action and TopComponent classes.

    • Icon. Specifies the icon that will accompany the window component. For example, you will see the icon in the label of the window component. (Optional)

    • Package. Specifies the name of the package where the class will be housed.

  4. After completing the wizard, you can do one or more of the following:

    • Use the Form editor to design the window.

    • Place the window component in a different position. In the layer.xml file, tweak the Modes section.

    • Add your own code to componentOpened() and componentClosed() to specify what will happen when the window opens and closes.

5.7.1.16 About Wizards

Wizards are defined by the Wizard Descriptor API.

The Wizard API lets you create wizard panels that have steps, graphics, left side-bar text, and a user panel on the right. The Wizard wizard in the IDE helps you by creating several of the basic Java source files, containing sample code, for you.

Depending on the selections you make in the Wizard Type panel in the New Wizard wizard, the IDE creates the following Java source files for you:

  • Registration Type: Custom

    Wizard Step Sequence: Static

    Created files:

    • SampleAction.java

    • VisualPanel.java (for each wizard step)

    • WizardPanel.java (for each wizard step)

    These files are ideal for uncomplicated wizards that progress sequentially from panel to panel without divergences or reversals. A menu item or toolbar button invokes the wizard and subsequent steps are generally linear and forward-directed.

  • Registration Type: Custom

    Wizard Step Sequence: Dynamic

    Created files:

    • WizardIterator.java

    • VisualPanel.java (for each wizard step)

    • WizardPanel.java (for each wizard step)

    These files are for wizards that provide more flexibility to the user. A WizardDescriptor.Iterator class guides progress from one panel to the next. The developer has a lot more freedom in coding the wizard, but has a more complex task since there are many more possibilities to consider. Even though the Custom/Simple wizard type can also be extended to provide support for panel skipping and reversals, the Custom/Dynamic type was made for this purpose. For example, the Add Server Instance wizard offers different panels depending on the type of server that the user wants to register.

  • Registration Type: New File

    Created files:

    • WizardIterator.java

    • VisualPanel.java (for each wizard step)

    • WizardPanel.java (for each wizard step)

    • .HTML file (for the description area in the New File wizard)

    These files are for wizards that are used to create new files. This wizard is registered in the New File wizard via the layer.xml file. All the necessary entries in the layer.xml file are created for you by the Wizard wizard. In addition, when you make this choice, the Wizard wizard creates a WizardDescriptor.Iterator.

    The iterator lets you provide the direction and sequence of the wizard. The New File wizard can be as simple or as complex as your needs dictate. An HTML file is created by the Wizard wizard so that you can provide a description for your new wizard in the New File wizard.

5.7.1.17 How to Create A Wizard

The Wizard wizard helps you by creating several of a wizard's basic Java source files, containing sample code, for you. For more information, see Section 5.7.1.16, "About Wizards".

When you want to create a wizard, you do not always need to use the Wizard wizard. The table below helps you to chose.

When you want to create a... Use a...
New Project wizard New Project Template wizard
New Sample wizard New Project Template wizard
New File wizard 'New File' registration type in the New Wizard wizard
Any other type of wizard 'Custom' registration type in the New Wizard wizard

Depending on the type of wizard you want to create, do the following:

To create a New File wizard or a custom wizard:

  1. Right-click a module project and choose New > Project Template.

  2. In the Wizard Type page, you have to set the following:

    • Registration Type. Specifies where the user will be able to find the wizard in the IDE. For more information, see Section 5.7.1.16, "About Wizards".

    • Wizard Step Sequence. Specifies whether the Wizard wizard will create an implementation of this NetBeans API class: WizardDescriptor.Iterator.

      If you choose Static, an implementation of this NetBeans API class will not be created. The default progression from panel to panel will then be supported by your wizard, sequential progression without divergences or reversals.

      If you choose Dynamic, the Wizard wizard will create an implementation of the WizardDescriptor.Iterator class. This class guides progress from one panel to the next. The developer has a lot more freedom in coding the wizard, but has a more complex task since there are many more possibilities to consider. When you choose "Static", you can also extend the wizard to provide support for panel skipping and reversals, but the "Dynamic" type was made for this purpose. For example, the Add Server Instance wizard offers different panels depending on the type of server that the user wants to register.

    • Number of Wizard Panels. For each panel, the IDE creates two files—a visual panel (called xxxVisualPanel.java) and a wizard panel (called xxxWizardPanel) for retrieving the current values from the visual panel. Only if you enter an integer greater than 0, will you be able to progress to the next panel in the Wizard wizard.

    In the Name, Icon, and Location page, you have to set the following:

    • Class Name Prefix. Specifies the name of the new panels and action class.

    • Package. Specifies the name of the package where the class will be housed.

  3. Only if the wizard will be registered as a New File wizard can you set the following items:

    • Display Name. Specifies the display name for the new wizard in the New File wizard.

    • Category. Specifies the New File wizard category where the new file wizard will be located.

    • Icon. Specifies the icon that will be displayed in the New File wizard.

  4. Click Finish.

After completing the wizard, you can do one or more of the following:

  • Tweak the layer.xml file to change the icon or rearrange the position of the template in the New Project wizard.

  • Change the description that will appear in the New Project wizard's Description box.

To create a new project template or a sample wizard:

  1. Right-click a module project and choose New > Project Template.

  2. In the Select Project page, you have to specify the project that you want to make available as a project template or sample. You can use the Project drop-down list to select an open project or you can click Browse to browse to a project in your filesystem.

    Click Next.

  3. In the Name, Icon, and Location page, you have to set the following:

    • Template Name. Specifies the name of the new project template.

    • Display Name. Specifies the template's label. For example, you will see this label in the Plugins manager. (Optional)

    • Category. Specifies the template's category. For example, this will enable the user to find the template more easily in the New Project wizard. (Optional)

    • Package. Specifies the name of the package where the classes will be housed.

  4. Click Finish.

After completing the wizard, you can do one or more of the following:

  • Tweak the layer.xml file to change the icon or rearrange the position of the template in the New Project wizard.

  • Change the description that will appear in the New Project wizard's Description box.

5.7.2 Extending Skeleton API Implementations

Once you have used the NetBeans API wizards, you extend the generated code by using the NetBeans APIs. For more information, see Section 5.7.1, "Generating Skeleton API Implementations". Several tools are provided specifically to help you at this stage of your development cycle. Among them are the following:

5.7.3 How to Register the NetBeans Sources and Javadoc

The NetBeans Platform Manager is a tool for registering different NetBeans platforms with the IDE. A NetBeans platform can be an installation of the NetBeans Platform (see Section 5.2, "About the NetBeans Platform" for details) or an installation of the NetBeans IDE. The default platform is always configured, and is the running IDE. Even in the case that a target platform is the complete IDE, you can easily create an application based only on the platform subset, so that there is little need to download the NetBeans Platform separately. The NetBeans Platform Manager lists all your registered NetBeans platforms in the left pane and lists the platform that the IDE currently deploys to as the default.

You can open the NetBeans Platform Manager by choosing Tools > NetBeans Platform Manager.

Using the NetBeans Platform Manager, you can:

  • Register a new platform.

  • View a registered platform's available modules.

  • Register source code for a platform in the Sources tab. If you register the sources, you do not need to register Javadoc separately, because Javadoc is included in the sources. Either the ZIP file containing the sources or the unpacked root folder can be registered in the Sources tab. You can download the NetBeans sources from https://netbeans.org/community/sources/.

  • Register Javadoc documentation for a platform in the Javadoc tab. Javadoc is available from the Plugins manager as "NetBeans API Documentation". Choose Tools > Plugins to access the Plugins manager.

Once you have registered a platform, you can configure a module project to use that platform for deployment. Go to the project's Project Properties dialog box, select the Libraries node, and choose the appropriate platform in the NetBeans Platform drop-down list.

5.7.4 How to Use the NetBeans Sources and Javadoc

Once you have registered the NetBeans Sources and Javadoc (see Section 5.7.3, "How to Register the NetBeans Sources and Javadoc" for details), you can use them as follows:

  • In the Source Editor, when you use code completion (Ctrl-Space), Javadoc for the related NetBeans API class is shown in the code completion window.

    You do not need to register Javadoc for this feature to work. Just registering the NetBeans sources suffices.

  • In the Source Editor, right-click on a class identifier that belongs to the NetBeans APIs and choose Show Javadoc (Alt-F1). Javadoc for the related NetBeans API class is shown in a separate pane in the Source Editor.

  • In the Source Editor, hold down the Ctrl key and move the mouse over a class identifier belonging to the NetBeans APIs. A hyperlink appears. Click on the hyperlink and the cursor jumps to the related NetBeans API class.

5.7.5 How to Search for NetBeans APIs

When using the NetBeans APIs, you may know the class that you need to use, but not the API (or non-API module) to which it belongs. Until you make the API available to your module, you are unable to make use of its classes.

To search for a NetBeans API:

  1. Right-click the Libraries node and choose Add Module Dependency.

    The Add Module Dependency dialog box appears

  2. In the Add Module Dependency dialog box, in the Filter textbox, start typing the name of the class that you need to use. The Module list narrows, showing only the modules that satisfy the filter.

    If the Show Non-API Modules checkbox is unchecked (default), the IDE excludes any module for which the current module cannot access any packages without an implementation dependency. These are known as "non-API modules". In other words, only modules with public packages are included, or friend packages where this module is a friend.

  3. When you find the module that you need to use, click OK. The IDE adds an entry to the project.xml file.

5.7.6 Code Templates for NetBeans APIs

In the Java editor in the IDE, type an abbreviation listed below, press the expansion key (which is Tab, by default), and then the expanded text shown below will be generated.

  • Abbreviation: 2do

    Description: Convert FileObject to DataObject

    Expands to:

    try {
        ${dobType type="org.openide.loaders.DataObject" editable="false" 
         default="DataObject"}  
        ${dob newVarName default="dob"} = ${dobType}.find(${fo    
         instanceof="org.openide.filesystems.FileObject" default="fo"}); 
        ${cursor}
          {catch (${etype type="org.openide.loaders.DataObjectNotFoundException"  
          default="DataObjectNotFoundException" editable="false"}    
        ${exName newVarName default="ex" editable="false"}) {    
        ${exctype type="org.openide.util.Exceptions" editable="false"   
          default=""}.printStackTrace(${exName}); 
        }
    

    Example:

    try {    DataObject dataObject = DataObject.find(myFo);
    } catch (DataObjectNotFoundException dataObjectNotFoundException) {  
      Exceptions.printStackTrace(dataObjectNotFoundException);       
    }
    
  • Abbreviation: 2f

    Description: Convert FileObject to java.io.File

    Expands to:

    ${fileType type="java.io.File" default="File" editable="false"}
    ${file newVarName default="f"} =
    ${FileUtilType type="org.openide.filesystems.FileUtil"
    editable="false")}.toFile(${fo 
    instanceof="org.openide.filesystems.FileObject"
    default="fo"});
    ${cursor}
    

    Example:

    File file = FileUtil.toFile(myFo);
    
  • Abbreviation: 2fo

    Description: Convert java.io.File to FileObject

    Expands to:

    ${fileType type="org.openide.filesystems.FileObject"
    default="FileObject" editable="false"}
    ${file newVarName default="f"} 
    = ${FileUtilType type="org.openide.filesystems.FileUtil"
    editable="false")}.toFileObject(${FileUtilType}.normalizeFile
    (${f instanceof="java.io.File" default="f"})); ${cursor} 
    

    Example:

    FileObject fileObject = FileUtil.toFileObject(FileUtil.normalizeFile(myFile));
    
  • Abbreviation: Lka

    Description: Find all implementations of a certain type registered in META-INF/services.

    Expands to:

    ${coltype type="java.util.Collection" default="Collection" editable="false"}  ${obj newVarName default="obj"} = 
    ${lkptype editable="false" default="Lookup" type="org.openide.util.Lookup"}.getDefault().lookupAll(${Type}.class);       ${cursor}
    

    Example:

    Collection<? extends Type> collection = Lookup.getDefault().lookupAll(Type.class);
    
  • Variation: lka (i.e., the first character is lowercase)

    Description: Find all implementations of a certain type from a local lookup, e.g., TopComponent, Node, or DataObject.

    Example:

    Collection<? extends Type> collection = myNode.lookupAll(Type.class);
    
  • Abbreviation: Lkp

    Description: Find a single typed implementation registered in META-INF/services.

    Expands to:

    ${Type} ${obj newVarName default="obj"} = ${lkptype editable="false" default="Lookup" type="org.openide.util.Lookup"}.getDefault().lookup(${Type}.class);       ${cursor}
    

    Example:

    Type type = Lookup.getDefault().lookup(Type.class);
    

    Variation: lkp (i.e., the first character is lowercase)

    Description: Find a single implementation of a certain type from a local lookup, e.g., TopComponent, Node, or DataObject.

    Example:

    Type type = myNode.lookup(Type.class);
    
  • Abbreviation: Lkr

    Description: Assign a single typed instance from META-INF/services to a Result object, to which you can listen for changes.

    Expands to:

    ${coltype type="org.openide.util.Lookup.Result" default="Lookup.Result" editable="false"}  ${obj newVarName default="res"} = ${lkptype editable="false" default="Lookup" type="org.openide.util.Lookup"}.getDefault().lookupResult(${Type}.class);       ${cursor}
    

    Example:

    Lookup.Result<? extends Type> res = Lookup.getDefault().lookupResult(Type.class);
    

    Variation: lkr (i.e., the first character is lowercase)

    Description: Assign a single typed instance from a local lookup to a Result object, to which you can listen for changes.

    Example:

    Result<? extends Type> all = myNode.lookupResult(Type.class);
    
  • Abbreviation: lko

    Description: Create a lookup for a local object, e.g., TopComponent, Node, or DataObject.

    Expands to:

    ${Type} ${obj newVarName default="obj"} = ${prov instanceof="org.openide.util.Lookup.Provider"}.getLookup().lookup(${Type}.class);       ${cursor}
    

    Example:

    Type type = myNode.getLookup().lookup(Type.class);
    
  • Abbreviation: stat

    Description: Create code for writing text obtained from a Bundle.properties file into the status bar.

    Expands to:

    ${coltype type="org.openide.awt.StatusDisplayer" default="StatusDisplayer" editable="false"}.getDefault().setStatusText(${bundletype type="org.openide.util.NbBundle" default="NbBundle" editable="false"}.getMessage(getClass(), "${KEY}"));${cursor}
    

    Example

    StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(getClass(), "KEY"));
    
  • Abbreviation: nb

    Description: Get a text from a Bundle.properties file.

    Expands to:

    ${coltype type="org.openide.util.NbBundle" default="NbBundle" editable="false"}.getMessage(${classVar editable="false" currClassName default="getClass()"}.class, "${KEY}")
    

    Example:

    NbBundle.getMessage(DemoAction.class, "KEY")
    

    Variation: nbb (i.e., add an additional 'b' character)

    Description: Pass in parameters for formatting the text.

    Example:

    NbBundle.getMessage(DemoAction.class, "KEY", params)
    

5.8 Bundling Supporting Items

The IDE provides wizards for bundling various supporting items with your module. Using these wizards means you can simply point-and-click at the items you want to include, and then the IDE does all the work for you.

You can use wizards to quickly and easily bundle the following items with your module:

  • Libraries. External JARs can be included in your NetBeans Platform modules in various ways:

    • If you are extending the IDE, you can add a new library to the Ant Library manager, which enables the user to add the library to the classpath of their application. For this you need a Java SE library descriptor, which the IDE can create for you.

    • If you are creating extensions to the IDE or are creating your own applications on the NetBeans Platform, you can include external JARs, NetBeans modules, and OSGi bundles. You can also include groups and combinations of these items. The IDE provides support for all of these scenarios.

    For details, see Section 5.8.1, "How to Bundle a Library".

  • Project Templates. Project templates are used when users begin to create their own project. For example, in the IDE a user chooses the 'Web Application' project template in the New Project wizard, then the IDE creates a project consisting of a JSP file, a web.xml file, a server-specific deployment file, and project metadata within a specific structure that is useful for web application projects.

    For details, see Section 5.8.2, "How to Bundle a Project Template or Sample".

  • Project Samples. Project samples that illustrate some aspect of project functionality are often provided by modules that inject a new technology into the IDE. For example, in the Samples directory within the New Project wizard, an Anagram Game is included to demonstrate Java SE functionality. A sample is a kind of project template; it has the same behavior as a project template, but it is used for a different purpose.

    For details, see Section 5.8.2, "How to Bundle a Project Template or Sample".

  • Update Center URLs. When you bundle the URL to a update center, you help your users, because they will not need to register your update center manually. For more information, see Section 5.13.1, "About Update Centers".

    Instead, when they install your module, your update center will automatically be accessible via the Plugins manager. As a result, when your users go to Tools > Plugins manager, they will immediately see your update center in the 'Select Update Center(s) to connect' list. An update center declaration consists of the URL to the autoupdate descriptor and a display name. For more information, see Section 5.8.3, "How to Bundle an Update Center's URL".

  • JavaHelp Help Sets. The IDE provides a number of JavaHelp help sets. You can add your own, or, if you are creating an application on top of the NetBeans Platform, you can provide a help set specifically for your application. (You can also hide help sets provided by other modules.) The files required for a JavaHelp help set can be generated for you by the IDE. Registration of the help set in the IDE can also be automated. As a result, you do not need to think about these infrastructural matters, so that you can focus your time and energy on the content of your help set.

    For more information, see Section 5.8.4, "How to Bundle a JavaHelp Help Set".

  • License. With the creation of any software, there is often a need for that software to have a software license. The IDE's support for creating modules allows you to add a license to the module that is under creation.

    For more information, see Section 5.8.5, "How to Bundle a License".

5.8.1 How to Bundle a Library

You bundle libraries with your module by using the New Java SE Library Descriptor wizard. This wizard creates a new Java SE library descriptor, which registers the library in the Ant Library Manager. For more information, see Section 5.8, "Bundling Supporting Items".

Java SE Library Descriptor

A Java SE library descriptor is an XML file that, when registered in the layer.xml file, adds a new class library to the IDE's Ant Library Manager. Whenever the module containing the library descriptor is enabled, the library is present in the Ant Library Manager. For example, Struts support provides the Struts libraries in the Ant Library Manager.

To create a new Java SE Library Descriptor:

  1. Right-click a module project and choose New > Java SE Library Descriptor.

  2. In the Select Library page, you have to specify the library that you want to make available in the Ant Library Manager via the module. You can select a library that is available in the Ant Library Manager or you can click Manage Libraries to use the Ant Library Manager to add the library that you want to make available via the module.

  3. Click Next.

  4. In the Name, Icon, and Location page, set the following:

    • Library Name. Specifies the name of the new library descriptor.

    • Display Name. Specifies the descriptor's label.

  5. Click Finish.

5.8.2 How to Bundle a Project Template or Sample

The New Project Template wizard creates a new project template or project sample. For more information, see Section 5.8, "Bundling Supporting Items".

You can create an NBM file that contains your template or sample. For more information, see Section 5.11.1, "About NBM Files".

When the user installs the NBM file, the template or sample will be available in the New Project wizard.

To create a new project template or sample:

  1. Right-click a module project and choose New > Project Template.

  2. In the Select Project page, you have to specify the project that you want to make available as a project template or sample. You can use the Project drop-down list to select an open project or you can click Browse to browse to a project in your filesystem.

  3. Click Next.

  4. In the Name, Icon, and Location page, you have to set the following:

    • Template Name. Specifies the name of the new project template.

    • Display Name. Specifies the template's label. For example, you will see this label in the Plugins manager. (Optional)

    • Category. Specifies the template's category. For example, this will enable the user to find the template more easily in the New Project wizard. (Optional)

    • Package. Specifies the name of the package where the classes will be housed.

  5. Click Finish.

  6. After completing the wizard, you can do one or more of the following:

    • Tweak the layer.xml file to change the icon or rearrange the position of the template in the New Project wizard.

    • Change the description that will appear in the New Project wizard's Description box.

5.8.3 How to Bundle an Update Center's URL

The New Update Center wizard lets you create a module that registers a update center in the user's Plugins manager. For more information, see Section 5.13.1, "About Update Centers".

In effect, the module bundles the URL to the update center so that the user does not need to register the URL manually. For more information, see Section 5.13.4, "Manually Registering an Update Center URL".

To bundle an update center's URL:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Update Center from the Module Development category. Click Next.

  2. In the Update Center Declaration page, you have to set the following:

    • URL to Update Descriptor. Specifies the URL to the autoupdate descriptor.

      You can let the IDE generate the autoupdate descriptor for you. For more information, see Section 5.13.2, "How to Generate an Autoupdate Descriptor".

    • Display Name. Specifies the name that you would like the user to see in their Plugins manager.

  3. Click Finish.

5.8.4 How to Bundle a JavaHelp Help Set

A JavaHelp help set provides help files that explain the features and functionality of your module. For more information, see Section 5.8, "Bundling Supporting Items".

To create a new JavaHelp help set:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose JavaHelp Help Set under the Module Development category.

  2. In the Location page, note the files that will be created and also note that they will be housed in a new folder called docs:

    • -about.html. A sample HTML file that is registered in the idx.xml file, map.xml file, and toc.xml file.

    • -hs.xml. Helpset file.

    • -idx.xml. Index file. Using the map ID created in the map.xml file, you add items to the idx.xml file, with the name of the topic that you want displayed in the index.

    • -map.xml. Map file. Each HTML file must be registered in the map file. The map ID that you create for the HTML file is used in the toc.xml file and idx.xml file.

    • -toc.html. Table of contents file. Using the map ID created in the map.xml file, you add items to the toc.xml file, with the name of the topic that you want displayed in the table of contents.

    • -helpset.xml. The reference file that is registered in the layer.xml file.

    Note: Each of the names above is prefixed by the name of the project. For example, if the project name is myproject, the files above would be myproject-about.html, myproject-hs.xml, etc.

Optionally, if you do not want to include the IDE's default JavaHelp help sets with your module, you can hide them. Particularly when you are creating a rich-client application on top of the NetBeans Platform, it is unlikely that you will want the IDE's JavaHelp help sets to be included with your application.

To hide a JavaHelp help set:

  1. In the Projects window, expand the Important Files node.

  2. In the Important Files node, expand the XML Layer node, and then wait a moment while the subnodes are loaded.

  3. Expand the <this layer in context> node.

  4. Within the Services/JavaHelp node, select the nodes of the JavaHelp sets that you want to delete. Choose Delete.

In the layer.xml file, notice that tags have been added, each with a _hidden flag. When your module is installed, the _hidden flag tells the IDE, or the application built on the NetBeans Platform, to exclude the specified items.

5.8.5 How to Bundle a License

Especially when you want to distribute a module, bundling a license is standard procedure. For more information, see Section 5.8, "Bundling Supporting Items".

A license is typically a plain text file.

To bundle a license:

  1. Right-click the module project node and choose Properties.

  2. In the Project Properties dialog box, click Packaging.

  3. Specify the packaging information, which includes the license.

5.9 Registering Modules

5.9.1 About the System Filesystem

The system filesystem is the central repository for configuration data in NetBeans. It is composed at runtime of a stack of XML layer files supplied by modules in the system. For more information, see Section 5.9.2, "About XML Layer Files".

It is a virtual filesystem that contains configuration information. NetBeans stores a wide variety of configuration information in the system filesystem. For example, the system filesystem contains a folder called Menu, which contains subfolders with names such as File and Edit. These subfolders contain files that represent Java classes which implement the actions that appear in the File and Edit menus.

When you create a module, you are free to create your own folders in the system filesystem to store data that relate to your module. You can also add objects to existing folders. One of the reasons to use the system filesystem is that it enables an application to be constructed piecemeal from pluggable components (modules) without requiring the use of a monolithic "master controller" that knows about everything.

One important aspect of a NetBeans virtual filesystem is that it can fire events to notify the rest of the system when something in it changes. NetBeans listens for changes in the system filesystem, and if, for example, something creates a new object in one of the menu folders, that new item will appear in the menu.

5.9.2 About XML Layer Files

Layer files (layer.xml) are small XML files provided by modules, which define a virtual filesystem. The layer file defines folders and files that will be merged into the system filesystem that makes up the runtime configuration information that the NetBeans Platform and its derivatives (such as the IDE) use. For more information, see Section 5.9.1, "About the System Filesystem".Layer files help to make it possible for modules to be dynamically installed. The components of the IDE whose content is composed from folders in the system filesystem listen for changes in folders and files in a filesystem. If a module is added at runtime, the system filesystem fires changes; the user interface notices that the contents of the folder has changed and updates the user interface to reflect the changes. New modules created using a module project template (for details, see Section 5.6.2, "How to Create a Module Project") do not have an XML layer, but you can add one with the New XML Layer wizard in the New File dialog. You can then expand the node for it under Important Files in your module project to see and modify its contents. The way it is declared is simple:

  • In your jar, provide the layer file, for example, com/foo/mymodule/resources/layer.xml

  • In your module's manifest, include the following line somewhere in the top section:

    OpenIDE-Module-Layer: com/foo/mymodule/resources/layer.xml

Just as the New XML Layer wizard creates an empty layer.xml file, so some module file templates may add entries, creating a new layer if necessary (for details, see Section 5.7.1, "Generating Skeleton API Implementations"). Other templates just add Java annotations and so do not need an XML layer.

You can use the System Filesystem Browser to tweak the layer.xml file, or you can do so manually using code completion in the Source Editor.

5.9.3 How to Edit an XML Layer File

When editing an XML layer file, you can use code completion (Ctr-Space) in the Source Editor. Alternatively, you can use nodes in a tree view—each node represents an item that a module makes available to the system.

To edit an XML layer file:

  1. In the Projects window, expand the Important Files node.

  2. Expand the XML Layer node. After a moment, two subnodes appear:

    • <this layer>. The folders and files provided by the current module project's layer file.

    • <this layer in context>. All the folders and files provided by all the layer files in all modules available in the system.

  3. Expand a subnode to explore the folders and files within it. When you right-click a subnode, you can, for example, rename it. You can also use actions such as "Cut", "Copy", and "Paste". In addition, you can drag a subnode and drop it elsewhere, to reorder a folder or a file. All of these actions will result in XML entries being added to your module project's layer file.

5.9.4 How to View the System Filesystem

The system filesystem is the general registry for publicly accessible data and objects. For more information, see Section 5.9.1, "About the System Filesystem". It is a virtual filesystem that contains configuration information. Layer files (layer.xml) define folders and files that will be merged into the system filesystem. For more information, see Section 5.9.2, "About XML Layer Files".

To view the system filesystem:

  1. Create a module project. For more information, see Section 5.6.2, "How to Create a Module Project".

  2. In the Projects window, expand the Important Files node.

  3. Expand the XML Layer node. After a moment, two subnodes appear:

    • <this layer>. The folders and files provided by the current module project's layer file.

    • <this layer in context>. All the folders and files provided by all the layer files in all modules available in the system.

  4. Expand a subnode to explore the folders and files within it.

    When you right-click a subnode, you can, for example, rename it. You can also use actions such as "Cut", "Copy", and "Paste". In addition, you can drag a subnode and drop it elsewhere, to reorder a folder or a file. All of these actions will result in XML entries being added to your module project's layer file.

5.10 Communicating Between Modules

For registration and discovery of any kind of interface or class, in any module within the system, the NetBeans Platform supports two uniformly suitable solutions:

  • Lookup. One of the most fundamental classes in the NetBeans APIs is org.openide.util.Lookup.

  • ServiceLoader. This is the new java.util.ServiceLoader class, introduced in JDK 1.6. For more information, see Section 5.10.1, "About Service Providers".

Factors that might determine which approach to take:

  • Lookup is available in versions for older JDKs and thus you can use it as a replacement of ServiceLoader when running on JDKs older than 1.6.

  • Lookup is ready to work inside of the NetBeans runtime container. It knows how to discover all the modules in the system, how to effectively read its defined services, etc.

  • Lookup supports listeners. Client code can attach a listener and observe changes in lookup content. This is a necessary improvement to adapt to the dynamic environment created by the NetBeans runtime container, where modules can be enabled or disabled at runtime, which in turn can affect the set of registered service providers.

  • Lookup is extensible and replaceable. While the ServiceLoader class in JDK 1.6 is a final class with hard-coded behavior, the NetBeans Lookup is an extensible class that allows various implementations. This can be useful while writing unit tests. Or you can write an enhanced version of lookup that not only reads META-INF/services but, for example, finds the requested service providers around the Internet, etc.

  • Lookup is a general purpose abstraction. While the JDK's ServiceLoader can de-facto have just one instance per classloader, there can be thousands of independent Lookup instances, each representing a single place to query services and interfaces. In fact this is exactly the way Lookup is used in NetBeans—it represents the context of each dialog, window element, node in a tree, etc.

For a four-part tutorial series that covers Lookup, see NetBeans Selection Management Tutorial I—Using a TopComponent's Lookup.

5.10.1 About Service Providers

In version 1.3, the JDK started to use a concept called service providers. This concept introduces a completely declarative style of registration, which is based just on the current classpath of a Java virtual machine and nothing else. This has an important advantage greatly contributing to the ease of use of this registration style: in order to change the set of registered providers, just pick up a JAR file that offers such a provider and include it in application classpath. Immediately its provider will be accessible to all code that searches for it.

The basic idea is that each JAR file (in NetBeans terminology, each module) that wishes to provide an implementation of some interface, for example javax.xml.parsers.DocumentBuilderFactory, can create its own implementation of the interface, say org.sakson.MyFactory, and expose it to the system as a service by creating a META-INF/services/javax.xml.parsers.DocumentBuilderFactory file inside of its own JAR file. The file then contains a name of the implementation class per line. In this example it would contain one line registering the sakson factory: org.sakson.MyFactory.

The DocumentBuilderFactory.newInstance method then searches for all META-INF/services/javax.xml.parsers.DocumentBuilderFactory files by using ClassLoader.getResources("META-INF/services/javax.xml.parsers.DocumentBuilderFactory"), reads their content, and instantiates the class(es) found there by calling their default constructors. The first implementation of the DocumentBuilderFactory is then returned from the newInstance method.

While you can manually create the registration of a service in your module, usually you will use the org.openide.util.lookup.ServiceProvider annotation, which creates such a registration for you automatically.

As already mentioned, this style has been in place since JDK 1.3 and is a standard way to deal with service providers. Not only has NetBeans adopted this style, it is also gaining in popularity among other Java developers. As a result, JDK 1.6 has introduced the new utility class java.util.ServiceLoader.

5.11 Building Modules

The IDE uses an Ant build script to build your modules. The IDE generates the build script based on the options you enter in the project's Project Properties dialog box. You can set the module's dependencies, versioning, and packaging information in the Project Properties dialog box. You can further customize program execution by editing the Ant script and Ant properties for the project.

You can customize the build process by doing any of the following:

  • Enter basic options, like module dependencies, packaging settings and versioning information in the Project Properties dialog box.

  • Customize the IDE-generated Ant targets or create new targets in build.xml.

To build a module:

  1. In the Projects window, right-click the node of the module project you want to build.

  2. Choose Build Project.

To build all the modules belonging to a module suite project, right-click the module suite project and choose Build All.

If the IDE does not support your desired build process, see the harness/README file. This README file contains detailed descriptions of various file layouts and how to edit them.

5.11.1 About NBM Files

An NBM file is a NetBeans module packaged for delivery via the web. For more information, see Section 5.1, "About NetBeans Modules". The principal differences between NBM files and module JAR files are:

  • An NBM file can contain more than one JAR file—modules can package any libraries they use into their NBM file.

  • An NBM file contains metadata that NetBeans will use to display information about it in the Plugins manager, such as the manifest contents, the license, etc.

  • An NBM file may be signed for security purposes.

  • NBM files are just ZIP files with a special extension. They use the JDK's mechanism for signing JAR files. Unless you are doing something unusual, you need not worry about the contents of an NBM file—just let the standard Ant build script for NBM creation take care of it for you.

5.11.2 How to Build an NBM File

An NBM file is a NetBeans module in binary format, packaged for delivery via the web. For more information, see Section 5.11.1, "About NBM Files".

To build an NBM file:

  1. In the Projects window, right-click the node of the module project you want to build.

  2. Choose Create NBM.

To build all NBM files in a module suite:

  1. In the Projects window, right-click the node of the module suite project you want to build.

  2. Choose Create NBMs.

    When you choose Create NBMs in a module suite's contextual menu, an autoupdate descriptor is generated by the IDE. The autoupdate descriptor describes all the NBM files. When you put the autoupdate descriptor on a server, your users can access it and retrieve your NBM files via the autoupdate descriptor. For more information, see Section 5.13.2, "How to Generate an Autoupdate Descriptor".

5.12 Trying Out a Module

When you test your module, it is advisable to deploy it to a different instance of the IDE. This way, if there are problems with your module that cause the IDE to crash, you will not lose unsaved work or need to restart the IDE.

However, if you are confident of your module or if you are demonstrating module development, you may want to see the effect of your module more quickly. In these cases, it is worth taking the risk that you will lose unsaved files and have the inconvenience of being required to restart the IDE, if bugs in your module cause the IDE to crash.

To install a module project in a new instance of the IDE:

  1. Choose a target platform. For more information, see Section 5.7.3, "How to Register the NetBeans Sources and Javadoc".

  2. Right-click the module project and choose Run.

    The target platform starts up and installs the module project. By default, the target platform is the IDE in which you are developing your module project.

  3. If you wish to test changes to the module without restarting the target platform, right-click the module project and choose Reload in Target Platform.

To install a module project in the current instance of the IDE:

  1. Save your work.

  2. Right-click the module project and choose Install/Reload in Development IDE.

5.12.1 Deploying Modules

When an application based on a NetBeans Platform is run, the NetBeans Platform's Main class is run. It then finds the available modules and builds an in-memory registry of them, and performs any tasks they specify for startup. Generally, a module's code is loaded into memory as it is needed.

5.13 About Distributing Modules

You can distribute a module in one or more of the following ways:

  • Contribute to the Plugin Portal. This is the central location where you can upload your NetBeans modules so that they may be easily found, all in the same place. For more information, see http://plugins.netbeans.org/PluginPortal/.

  • Create your own update center. With your own update center, you can distribute modules that are specific to your application, as well as modules that are not appropriate for distribution via the Plugin Portal. For more information, see Section 5.13.1, "About Update Centers".

    For quick updates to your modules or for making modules available to a smaller subset of end users, creating your own update center might be a good idea.

  • Other. You can simply zip up a module's sources and transfer them via e-mail or upload them onto a server. Alternatively, you can use the IDE to create a binary NBM file, which you can then transfer via e-mail or upload to a server, instead of transferring the sources.

5.13.1 About Update Centers

An update center is nothing more than an XML file that is known as the ”autoupdate descriptor”, together with the modules that it describes. The autoupdate descriptor lists all the modules that you would like to make available. For each module, the autoupdate descriptor provides information such as a name, a description, and a list of modules that it depends on.

Most importantly, the autoupdate descriptor specifies a URL for each module that it describes. Each module, in binary NBM file format, must live on a server. For more information, see Section 5.11.1, "About NBM Files".

The autoupdate descriptor itself must also live on a server. The server where the autoupdate descriptor lives need not be the same server as where the modules live. The modules can live together on the same server or be spread across different servers.

After the autoupdate descriptor and its associated modules are on a server, you must let your end users know that they are there. The URL to the autoupdate descriptor must be registered in the end users' IDEs. This can be done in one of two ways:

  • Automatically. You can provide a module that registers the URL to the update center for them. This module can be generated in the IDE, without any coding on your part.

  • Manually. You must tell your end user what the URL to your autoupdate descriptor is. Then, the end users need to register the URL to your autoupdate descriptor. They must then do so manually in the Plugins manager.

Once the URL to the update center is registered, your end users can access your modules via the Plugins manager, which they can find under the Tools menu. Not only new modules, but new versions of existing modules can be distributed in this way.

5.13.2 How to Generate an Autoupdate Descriptor

An autoupdate descriptor is an XML file that describes the NBM files that you want to make available to your users. For more information, see Section 5.11.1, "About NBM Files".

For example, an autoupdate descriptor specifies a name, a description, and a URL for each module that it describes.

When you put an autoupdate descriptor on a server, and make its URL available to your users, your users are able to register the URL in your IDE. After registering the URL, they can access your NBM files via the Plugins manager, under the Tools menu.

To generate an autoupdate descriptor:

  1. If you have not already done so, create a module suite project. For more information, see Section 5.6.4, "How to Create a Module Suite Project".

  2. In the Projects window, right-click the node of the module suite project you want to build.

  3. Choose Create NBMs.

    The IDE builds the NBM files in the module suite project. The IDE also creates a file called updates.xml, which is the autoupdate descriptor. To see it, look in the Files window (Ctrl-2).

  4. Tweak the autoupdate descriptor, if needed. For example, customize the distribution element for each module, so that the URL to the NBM file is correct.

5.13.3 How to Bundle an Update Center's URL

The New Update Center wizard lets you create a module that registers a update center in the user's Plugins manager. For more information, see Section 5.13.1, "About Update Centers". In effect, the module bundles the URL to the update center so that the user does not need to register the URL manually. For more information, see Section 5.13.4, "Manually Registering an Update Center URL".

To bundle an update center's URL:

  1. Right-click a module project and choose New > Other. In the New File wizard, choose Update Center from the Module Development category. Click Next.

  2. In the Update Center Declaration page, you have to set the following:

    • URL to Update Descriptor. Specifies the URL to the autoupdate descriptor.

      You can let the IDE generate the autoupdate descriptor for you; for details, see Section 5.13.2, "How to Generate an Autoupdate Descriptor".

    • Display Name. Specifies the name that you would like the user to see in their Plugins manager.

  3. Click Finish.

5.13.4 Manually Registering an Update Center URL

If you have not been provided with a module that bundles an update center's URL, you need to register the update center manually. For more information, see Section 5.8.3, "How to Bundle an Update Center's URL".

Once you have registered the update center, you can access its modules via the Plugins manager, which you can access under the Tools menu.

To manually register an update center's URL:

  1. Choose Tools > Plugins.

    The Plugins manager opens.

  2. Click the Settings tab at the top of the Plugins manager.

  3. Click Add.

  4. Type the name and URL of the autoupdate center. The name can be anything you want it to be. Click Finish.

  5. Click Close.

You have now manually registered the update center's URL.

5.14 Branding a Rich-Client Application

Once the functionality of an application built on top of the NetBeans Platform is complete, the appearance of the application still closely resembles the default NetBeans Platform. You can use the IDE to personalize your application. In particular, you can do the following:

  • Replace the application's splash screen.

  • Replace the strings in the NetBeans Platform's bundle files.

  • Define a progress bar.

  • Define the application's title bar.

  • Disable one or more of the window system's default features.

To brand a rich client application:

  1. Right-click the application project in the Projects window and choose Branding.

  2. In the Branding editor, click the tab related to your branding needs:

    • Basic. Brand the title bar and the application icons.

    • Splash Screen. Brand the splash screen and progress bar.

    • Window System. Remove features from the window system.

    • Resource Bundles. Customize the strings provided by the NetBeans Platform.

  3. Click OK to confirm your changes and exit the editor.

5.14.1 How to Brand the Window System

You can brand an application's window system by disabling the following of its default features:

  • Window Drag and Drop. The ability to reorganize the window layout by dragging windows to new positions.

  • Floating Windows. The ability for windows to be undocked into a standalone frames.

  • Sliding Windows. The ability to minimize (slide out) a window.

  • Maximized Windows. The ability to maximize a window by clicking its header.

  • Closing Windows. The ability to close a document/non-document window.

  • Window Resizing. The ability to adjust the width and height of windows by dragging splitter bars.

  • Respect Minimum Size When Resizing Windows. The ability to resize internal windows to zero width/height using splitter bars.

To brand the window system:

  1. Right-click the application project in the Projects window and choose Branding.

  2. In the Branding editor, click Window System.

  3. Deselect the items listed above, depending on your needs.

  4. Click OK to confirm your choices and exit the Branding editor.

5.14.2 How to Add a Splash Screen

  1. Right-click the application project in the Projects window and choose Properties.

  2. In the Project Properties dialog box, click Splash Screen. Do the following:

    • Define the progress bar.

    • Choose a splash screen.

  3. Click OK to confirm your choices and exit the Project Properties dialog box.

5.14.3 How to Remove Unwanted Modules

You can exclude unwanted modules from a standalone application, leaving only those you really need. By default, all the modules that the IDE uses are included.

To remove unwanted modules:

  1. Right-click a module-suite project and choose Properties.

  2. In the Project Properties dialog box, click Libraries.

  3. Uncheck all the clusters that you want to exclude from the standalone application. The only cluster that all standalone applications need is platformNNN.

  4. Expand the nodes of the clusters that you want to keep, and uncheck any module that you want to exclude from the cluster.

  5. Click OK.

When you brand a standalone application (for details, see Section 5.14, "Branding a Rich-Client Application"), the IDE asks you whether it should exclude IDE-related modules for you. If you do not let the IDE exclude IDE-related modules, you can do so manually using the steps above.

5.15 Distributing Rich-Client Applications

Rich-client applications are complete, functioning, standalone Swing applications. The Swing libraries provide a rich collection of user interface elements. However, the Swing libraries do not provide a mechanism for joining the user interface elements together into an application. For this purpose, NetBeans provides the NetBeans Platform, which is the application framework on top of which you build your application. For more information, see Section 5.2, "About the NetBeans Platform".

Each distinct part of a rich-client application is provided by a separate module, several of which serve to provide the user interface elements from the Swing libraries. For example, if your rich-client application is an editor, you might have one module that provides syntax highlighting, while another provides file templates.

Branding

Before you distribute a rich-client application, you need to consider whether you want to leave it resembling NetBeans. For example, your rich-client application uses the NetBeans splash screen by default. Branding, the final stage before creating distribution packages, involves making decisions such as what the splash screen should look like and whether the application will include a progress bar during startup. In the module suite project's Project Properties dialog box, you define such settings. For more information, see Section 5.14, "Branding a Rich-Client Application".

While branding, also consider whether your rich-client application needs all the modules that the IDE uses. For example, if your rich-client application is not an editor, you will not need the modules that relate to editor functionality. Similarly, it is unlikely that all of the IDE's menu items and toolbar buttons are needed by your application.

Releasing

Once a rich-client application is branded, you can distribute it over the web as a web-startable JNLP application. Alternatively, you can distribute the ZIP file. See Section 5.15.2, "How to Build a JNLP Application" and Section 5.15.1, "How to Build a ZIP Distribution" for details. Updates to the modules that make up a rich-client application can be distributed via the Update Center.

5.15.1 How to Build a ZIP Distribution

Once your rich-client application is complete, one way to distribute it is via a ZIP file. The IDE can create the ZIP file for you, containing the application.

To build a ZIP distribution:

  1. In the Projects window, right-click the node of the application.

  2. Choose Package as | ZIP Distribution.

5.15.2 How to Build a JNLP Application

Java Web Start is a helper application that becomes associated with a Web browser. When a user clicks on a link that points to a special launch file (JNLP file), it causes the browser to launch Java Web Start, which then automatically downloads, caches, and runs the given Java Technology-based application. The entire process is typically completed without requiring any user interaction, except for the initial single click.

To build a JNLP application:

  1. In the Projects window, right-click the node of the module suite project you want to build.

  2. Choose JNLP | Build.

  3. Depending on whether you have set up the module suite project as a standalone application, do the following:

    • If you have already set up the module suite project as a standalone project, the IDE builds a jnlp folder in your build folder and adds a master.jnlp file in your main project folder. Open the Files window to see the JNLP file and the folder within the build folder.

    • If you have not set up the module suite project as a standalone application, the IDE will not be able to build the JNLP application. The IDE will tell you this by means of a dialog box.

      • Click Configure Application in the dialog box. The Project Properties dialog box opens. Click Build.

      • Select the Create Standalone Application radio button. Click OK.

      • In the Projects window, right-click the node of the module suite project you want to build.

      • Choose Build JNLP Application.

        The IDE builds a jnlp folder in your build folder and adds a master.jnlp file in your main project folder. Open the Files window to see the JNLP file and the folder within the build folder.

5.15.3 How to Run a Rich-Client Application

Unless your NetBeans modules are designed to be deployed as standalone modules, you should always deploy them by deploying the application (the module suite project) that contains them. If you run the Run Project command on an individual module that is part of an application built on top of the NetBeans Platform, the IDE only deploys that module itself.

To deploy a standalone application:

  • In the Projects window, right-click the module suite project and choose one of the following:

    • Run Project. Starts the target platform, undeploys the standalone application if it is already deployed, deploys the standalone application to the target platform, starts the platform and loads the application as one unit.

    • Run JNLP Applications. Builds and runs the application as a JNLP application. For more information, see Section 5.15.2, "How to Build a JNLP Application".

5.15.4 How to Use the NetBeans Shared JNLP Repository

By default, the JNLP application generated for a module suite project always contains all the module suite project's modules as well as all the modules that the module suite project depends on. This may be useful for intranet usage, but it is a bit less practical for wide internet use. When on the internet, it is much better if all the applications built on the NetBeans Platform refer to one repository of NetBeans modules, which means that such modules are shared and do not need to be downloaded more than once.

There is such a repository for NetBeans modules. It does not contain all the modules that NetBeans IDE has, such as, for example, the ant module, which is not JNLP-ready, but it contains enough to make many JNLP applications possible.

To use the shared JNLP repository:

  1. In the Projects window, expand the Important Files node.

  2. Double-click NetBeans Platform Config.

  3. Add the jnlp.platform.codebase property with, as its value, the URL of the 5.0 JNLP Repository:

    jnlp.platform.codebase=http://www.netbeans.org/download/5_0/jnlp