NetBeans IDE is an open-source software which is intended for development in JAVA (at the first versions) but also supports the others languages such as C/C++, PHP, HTML5/CSS3 and Javascript. NetBeans IDE is a cross-platform softwareand runs on Microsoft Windows, Mac OS, Linux, Solaris. NetBeans IDE supports PHP since version 6.5 and more and more features are included in its PHP bundle:
- Syntax highlighting, code completion
- PHP code debugging with xdebug
- Testing with PHPUnit
- Support PHP frameworks: Symfony 1/2, Zend, Yii
This tutorial is built on the version 8.2. If you are using an older version, try to update to the latest version to avoid the errors while going through the tutorial. There are the bundles separated for the programming languages particular but to build a plugin, it requires the NetBeans Platform SDK so we suggest you to download the bundle « all ». You can disable the unused features in the installation.
Create a Module project
We start by creating an empty module project in NetBeans Platforms SDK.
- Choose File → New Project.
- Name and Location:
- Basic Module Configuration:
- Type “fr.adfab.magebeans” in Code Name Base field. This is the unique string identifying the module. The code name base is also used as the main package of the module.
- We use the default NetBeans module system so do not need to check the “Generate OSGi Bundle”.
- The source code will be created after clicking the “Finish” button.
Implementing the module
We will create some Java packages in the main package created within previous step to make our source code well structured:
- fr.adfab.magebeans.actions: Will contain all the Actions. An Action is a piece of code which handles the event invoked by the user to do something in the NetBeans IDE. An Action can be invoked from a click on menu item, toolbar icon, context menu item or by keyboard shortcut.
- fr.adfab.magebeans.guis: This package contains all the GUI Java form design. These form allow the module to get user data to create a module, a model or other class.
- fr.adfab.magebeans.processes: Where we store all the Java classes which are the main processes. Ex: the process of creating the folder structure for a module, the process of generating the configuration files, etc. These Java classes are independent with NetBeans Platform SDK so we can reuse these classes to create a plugin of other PHP IDE like PhpStorm or Eclipse.
Our source code structure like this
Create the Action
- Right click on package fr.adfab.magebeans.actions, choose New → Action.
- Action Type panel:
- GUI Registration
- In Category: Enter “MageBeans” to create new category action group. We will use this category for the further actions.
- Select Global Menu Item → Menu: Source → Position: Here – Format. A menu item will be created in the main menu Source.
- Select Global Toolbar Button → Toolbar: File → Position: Save All – Here. A button will be added to the toolbar menu.
- Name, Icon and Location
- The Class Name will be used to create the Java class source so it requires a unique name. Here, we choose “CreateModuleAction”.
- The Display Name is the text will be displayed in Main menu.
- Because we already chose “Global Toolbar Button” so an icon image is required. Icon image need to have size of 16×16. You can add also an additional icon with size of 24×24 for a big toolbar by put another image file with name ended by 24 in same folder. You can find this image in the list of created files below.
- The Project & Package are already filled but if you can change the package where the Java class file will be created.
A Java class source file will be created
@ActionID(
category = "MageBeans",
id = "fr.adfab.magebeans.actions.CreateModuleAction"
)
@ActionRegistration(
iconBase = "fr/adfab/magebeans/actions/magebeans.png",
displayName = "Create Magento Module"
)
@ActionReferences({
@ActionReference(path = "Menu/Source", position = 200, separatorAfter = 250),
@ActionReference(path = "Toolbars/File", position = 500)
})
public final class CreateModuleAction implements ActionListener {
private final Project context;
public CreateModuleAction(Project context) {
this.context = context;
}
@Override
public void actionPerformed(ActionEvent ev) {
// TODO use context
}
}
The most important function is actionPerformed. This function will be called when the menu item or toolbar button is clicked.
In the next tutorial, we will implement this function to display an input form which allows user to choose the location of module, the name of module and some other additions feature.