Introduction to netbeans module development

Source: Internet
Author: User
Tags netbeans
Official Chinese Tutorial:

This document introduces the basic knowledge of using netbeans ide To develop the netbeans plug-in module. You can develop the netbeans plug-in module for one of the following reasons:

  • Expand netbeans IDE.You can use the new features to easily extend ide functions. For example, by writing some plug-in modules, you can use your favorite cutting-edge technologies in netbeans IDE. For more information about the features provided by the release version of netbeans ide 5.x, see the release version page of netbeans ide 5.x.
  • Build applications on the netbeans platform.You can use the netbeans core as a platform for developing client applications with rich functions. By reusing the ready-made functions provided by the platform, you can save a lot of development time. For more information, see the netbeans platform homepage.

This Getting Started Guide describes the first case, but the principles described here also apply to the second case. However, please note that if you want to learn more about developing applications on the netbeans platform, the client application development tutorials with rich functions are more suitable for you.

This tutorial aims to help you get started as soon as possible. In this tutorial, you will create and install a simple netbeans plug-in module. The plug-in module adds a single menu item and a toolbar button to the IDE. When this menu item or toolbar button is selected,Dialogdisplayer, Which contains the text "I'm plugged in! ".

The following topics are introduced:

  • Set the plug-in Module Project
  • Create menu items and toolbar buttons
  • Install and use the plug-in Module

You can finish this tutorial within 20 minutes.

For more information about the netbeans plug-in module, see the netbeans Development Project homepage on the netbeans web site. If you have any questions, visit the netbeans developer FAQ or use the feedback link at the top of the page.


Set the plug-in Module Project

Before writing the plug-in module, make sure that all necessary software is installed and the project is correctly set. Netbeans provides a wizard to set all the basic files required by the plug-in module.

Install software

Before you start, install the following software on your computer:

  • Netbeans ide 5.x( download)
  • Java standard development kit (JDK) version 1.4.2 (download) or version 5.0 (download)
Create a netbeans plug-in Module Project
  1. Select "file"> "new project ". Under "category", select "netbeans plug-in module ".

    The netbeans plug-in module supports three types of projects:

    • Module Project.Create a template for a separate plug-in module.
    • Library packaging module project.Creates a plug-in module for an external JAR file required by one or more plug-ins.
    • Module suite project.Create a template for a set of plug-in modules and library packaging modules (which you want to deploy together) that are mutually dependent on each other.
  2. Select "Module Project ". Click "Next ".
  3. In the project name on the "name and location" Panel, TypeMyfirstmodule. Change the "Project location" to any directory on the computer, as shown in figureC:/mymodules. Select the "independent module" radio button and the "set as main project" check box to be selected. Click "Next ".
  4. In the "Basic module configuration" panelYourorghereReplaceMyorgTo make the complete code name libraryOrg. myorg. myfirstmodule. Note that the localization package and XML layer are stored inOrg. myorg. myfirstmodulePackage. These files perform the following operations:
    • Localization package.Specifies a language-specific string for internationalization.
    • XML layer.Register the menu and toolbar buttons in the netbeans system file system.

    Click Finish ". IDE will createMyfirstmoduleProject. This project contains all source code and project metadata, such as the ant generation script of the project. In this case, the project is opened in IDE. You can view its logical structure in the projects window (Ctrl-1) and view its file structure in the files window (Ctrl-2:

    In addition to the localization package and XML layer, the project also contains the following important files:

    • Module list.Declare that this project belongs to the plug-in module. In addition, it also sets some module-specific settings, such as the location of the XML layer, the location of the localization package, and the module version.
    • Generate scripts.Provides a location where you can create your own ant target and overwriteNbproject/build-impl.xml.
    • Project metadata.Contains some information, such as the project type, content, platform, class path, dependency, and ing between project commands and ant script targets.
    • Netbeans platform configuration.Contains the attributes used by the IDE or platform.
    • Netbeans platform configuration for each user.Contains attributes specific to ide installation. For example, if a project is shared through VCs, no attributes set in this file will be checked into the library. You can copy the attributes in "netbeans platform configuration" to this file and specify different definitions for the attributes in each file. The definitions in this file take precedence over those in "netbeans platform configuration.

    During this tutorial, you do not need to modify any files. Note that the important files listed above are the logical views of the following files in the "Files" window:Manifest. MF,Build. xml,Nbproject/Project. xml,Nbproject/platform. PropertiesAndNbproject/private/platform-private.properties.


Create menu items and toolbar buttons

You can use the netbeans plug-in module file template to create basic module functions. When you use a file template, IDELayer. xmlFile. After using the Wizard to create a file template, you can use the netbeans API list to continue the development module.

Use the "operation" Wizard
  1. In the "project" window, right-click the project node and choose "New"> "file/folder ". Select "netbeans module development" under "category" in the "New File" wizard, and then select "operations" under "file type ". Click "Next ".
  2. On the "Operation Type" Panel, accept the default settings. Click "Next ".
  3. On the "Gui registration" Panel, select "global menu item" and select "Global toolbar button ". Set the following values:

    • Category:Tools
    • Menu:Tools
    • Location:Tool-here-<separator>
    • Toolbar:Generate
    • Location:Run the main project-here-debug the main project

    In the global menu item section, select "separator before" and "separator after ".

    Now you will see the following:

    Note the following information about the GUI registration panel:

    • Category.Specifies the position of the operation in the "shortcut key ing" section of the "options" window.
    • Global menu item.Specifies the menu for registering an operation as a menu item. You can also set the position of the menu item in the existing menu item here.
    • Global toolbar button.Register the operation as the toolbar of the button. You can also set the position of the toolbar button in the existing toolbar button here.
    • Global shortcut key.Specifies the key to call this operation.
    • File context menu item.Specifies the MIME type of the file type of the menu item to be displayed. You can also set the position of the menu item in the existing menu item and its separator here. For more information about using this field, see the netbeans dataloader module tutorial.
    • Editor context menu item.Specifies the MIME type of the editor that displays the menu items. You can also set the position of the menu item in the existing menu item and its separator here. For more information about using this field, see the netbeans editor extension module tutorial.

    Click "Next ".

  4. On the "name, icon, and position" Panel, type "class name"MyfirstactionAnd then type "display name"My first action. In the "icon", find a 16x16 pixel icon in the file system. For example, you can find some 16x16 pixel icons in the netbeans ide 5.x installation directory:
       enterprise2/jakarta-tomcat-5.5.9/server/webapps/admin/images
  5. Click Finish ".

    IDE willOrg. myorg. myfirstmoduleCreateMyfirstaction. JavaAnd open it in the source code editor. You can see the following content (click the link to view the relevant netbeans API javadoc ):

       package org.myorg.myfirstmodule;

    import org.openide.util.HelpCtx;
    import org.openide.util.actions.CallableSystemAction;

    public final class MyFirstAction extends CallableSystemAction {

    public void performAction() {
    // TODO implement action body
    }

    public String getName() {
    return "My First Action";
    }

    protected String iconResource() {
    return "org/myorg/myfirstmodule/Groups.gif";
    }

    public HelpCtx getHelpCtx() {
    return HelpCtx.DEFAULT_HELP;
    }

    protected boolean asynchronous() {
    return false;
    }
    }

    As specified in the "Gui registration" Panel, the IDE willLayer. xmlIn the file, register the operation class as a menu item and a toolbar button:

    <filesystem>

    <folder name="Actions">
    <folder name="Tools">
    <file name="org-myorg-myfirstmodule-MyFirstAction.instance">
    <attr name="instanceClass"
    stringvalue="org.myorg.myfirstmodule.MyFirstAction"/>
    </file>
    </folder>
    </folder>

    <folder name="Menu">
    <folder name="Tools">
    <attr name="org-openide-actions-ToolsAction.instance
    /org-myorg-myfirstmodule-MyFirstAction.shadow"
    boolvalue="true"/>
    <file name="org-myorg-myfirstmodule-MyFirstAction.shadow">
    <attr name="originalFile"
    stringvalue="Actions/Tools/org-myorg-myfirstmodule-MyFirstAction.instance"/>
    </file>
    <attr name="org-myorg-myfirstmodule-MyFirstAction.shadow/Separator1.instance"
    boolvalue="true"/>
    </folder>
    </folder>

    <folder name="Toolbars">
    <folder name="Build">
    <attr name="org-netbeans-modules-project-ui-RunMainProject.shadow
    /org-myorg-myfirstmodule-MyFirstAction.shadow"
    boolvalue="true"/>
    <file name="org-myorg-myfirstmodule-MyFirstAction.shadow">
    <attr name="originalFile"
    stringvalue="Actions/Tools/org-myorg-myfirstmodule-MyFirstAction.instance"/>
    </file>
    <attr name="org-myorg-myfirstmodule-MyFirstAction.shadow
    /org-netbeans-modules-project-ui-DebugMainProject.shadow"
    boolvalue="true"/>
    </folder>
    </folder>

    </filesystem>
  6. In the source code editor, fill in as follows:Invalid maction ()Method:
       public void performAction() {
    String msg = "I'm plugged in!";
    NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
    DialogDisplayer.getDefault().notify(d);
    }

    The rows that call policydescriptor and dialogdisplaye are underlined and marked as errors, similar. This is because related packages have not been declared. We will declare them in the next step.

  7. In the project window, right-clickMyfirstmoduleProject node, and then select "properties ". In the libraries pane, click Add ". TypeNotifyd, Please note that the returned list will narrow until the display containsNotifydescriptor.

    Click OK ". The dialog box API is added to the "module dependency" list. Click OK to confirm, and then exit the Project Properties dialog box.

  8. In the source code editor, press Alt-shift-f. At this time, two new import statements are added to the top of the source file, and the red underline disappears. The following is a new Import Statement (click the link to view the relevant netbeans API javadoc ):
       import org.openide.DialogDisplayer;
    import org.openide.NotifyDescriptor;

The compilation of the plug-in module is now complete. Next, you need to install and use it.

Install and use the plug-in Module

IDE uses the ant generate script to generate and install the plug-in module. This script is created when you create a plug-in Module Project.

Install plug-in Module
  • In the project window, right-clickMyfirstmoduleProject, and then select "Install/reload on the Target Platform ".

    The plug-in module will be generated and installed on the target platform. The target platform is set in tools> netbeans platform manager. The target platform will open to try out the new plug-in module. The default target ide or platform is the installation of the current ide instance.

Use the netbeans plug-in Module
  1. In the newly opened ide menu bar, you will see the new menu and menu items and the icons specified in the "operation" Wizard:

  2. Select for callMyfirstaction. JavaInInvalid mactionMethod. You will seeJoptionpaneAnd its message:

  3. Click the toolbar button. Because it calls the same operation, it has the same results. It should be as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.