• Home
  • Nous contacter

Le blog d'Adfab

Le blog d'Adfab

Le blog d'Adfab

Le blog d'Adfab
e-Commerce Outils

Magento plugin for NetBeans IDE (part. 2)

In the previous tutorial, we presented how to create a module project and a first part of implementation. In this tutorial, we will describe how to create an input form and use the menu item & toolbar button to display this form.

Create input form

  1. Right click on fr.adfab.magebeans.guis, choose New à Other
  2. Choose File Type:
    1. In Categories, choose Swing GUI Forms
    2. File types: choose JDialog Form.
  3. Name and Location:
    1. Class Name: CreateModuleForm

An Java class CreateModuleForm is created. This class contains a form so we can use the design mode to add the input elements to this form.

3_create_module_form

Before implement the event for the two button “Create” and “Cancel”, we need to implement a Java class in fr.adfab.magebeans.processes which is handle the process of creating folder structure for a magento module. We call it CreateModuleProcess m and we do not describe here. You can find this class in source code on github (MageBeans).

In the input form for creating a module, there are two button that we need to implement a function which handle their click event.

private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
    dispose();
}
btnCreateActionPerformed

private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {
    CreateModuleProcess createModuleProcess = new CreateModuleProcess();
    String codePool = "local";
    
    if (rbtnCommunity.isSelected()) {
        codePool = "community";
    }

    try {
        createModuleProcess.setProjectDir(this.projectDir);
        createModuleProcess.setCodePool(codePool);
        createModuleProcess.setCompany(txtCompany.getText());
        createModuleProcess.setModule(txtModule.getText());

        ...
        createModuleProcess.process();
        dispose();
    } catch (FileNotFoundException | IllegalArgumentException ex) {
        Exceptions.printStackTrace(ex);
    }
}

In the function which performed on the button Create click event, we use the variable projectDir to store the path of magento project on the hard driver. This variable is used in CreateModuleProcess to generate the module file structure in the right project. But this form is executed from the CreateModuleAction so it cannot take the Netbeans project as a context. We need to provide this value as an argument.

public void run() {
    CreateModuleForm dialog = new CreateModuleForm(new javax.swing.JFrame(), true);
    dialog.setProjectDir(args[0]);
    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
        }
    });
    dialog.setVisible(true);
}

Open input form from action

All the required elements are ready, now we need to integrate them into the Netbeans framework action to make the first version of plugin work completely. In the last tutorial, we already created an action which create a button in toolbar and an item in the source menu. A function will be called in performing the clicked event on these items.

@Override
public void actionPerformed(ActionEvent ev) {
    FileObject projectDir = project.getProjectDirectory();
    String filePath = projectDir.getPath() + "/app/Mage.php";
    File mageFile = new File(filePath);
    if (mageFile.exists() && !mageFile.isDirectory()) {
        String args[] = new String[1];
        args[0] = projectDir.getPath();
        CreateModuleForm.main(args);
    } else {
        JOptionPane.showMessageDialog(null, "Current project is not magento 1x", "MageBeans plugin", JOptionPane.ERROR_MESSAGE);
    }
}

The CreateModuleAction is conditionally enabled action type with the cookie class is Project so a Project instant is passed as the parameter in its constructor function which is used to get the project path in actionPerformed function

public final class CreateModuleAction implements ActionListener {
    private final Project project;

    public CreateModuleAction(Project context) {
        this.project = context;
    }
...

Build nbm file

A plugin can be added into a NetBeans IDE by installing from NetBeans Plugin Portal or from a nbm local file. So to deploy a plugin, you need to build a nbm file for the both ways of installation. To install a NetBeans plugin, in Tools → Plugins, choose Available Plugins tab and select the plugin to install online or choose Downloaded tab to install from a nbm local file.

Before packaging the plugin into a nbm file, you need to fill the plugin information:

  1. Right click on project in Projects view, choose Properties
  2. In Display section, fill the information form 
  3. In Build → Packaging, upload the license file 

This is very easy to build the nbm file in NetBeans:

  1. Right click on the MageBeans project in Project view
  2. Choose Create NBM
  3. The nbm file is located in folder /build

Now the 1st version of MageBeans plugin is released, you can install it into NetBeans IDE to use. You will see the button on toolbar & menu as in the figure below.

And the module folder structure created by MageBeans plugin

Conclusion

After two tutorials, a simple version of MageBeans is released which help us to understand how to create and implement a plugin for NetBeans IDE. In the next tutorial, we will discuss furthermore on the implementation of code completion which support for Magento in development.

16/06/2017 37 MIN READ TAGS: Backend Development, ecommerce, Magento, Netbeans BY: Van Thiep Nguyen 0 COMMENT
SHARE
LIRE LA SUITE

Van Thiep Nguyen

Entre design et développement frontend [2/2]

We need #BetterAds

VOUS POURRIEZ AIMER

Outils Compte rendu du Velocity Europe 2013 – Jour 2

e-Commerce L'actualité AdFab Magento : Outfit, animation de votre site e-commerce par vos clients.

e-Commerce Importer des données e-commerce avec l’ETL Talend Open Studio

e-Commerce Nouvelle règlementation e-commerce

Outils Coder en s’amusant ? C’est possible !

Outils Scout Realtime : un top amélioré

A propos d’Adfab

Nous sommes un studio de production digitales et d’innovation digitales au service des agences et des annonceurs
Nous recherchons le scintillement dans les regards et le plaisir de réalisations sur-performantes
Nous sommes techno-agnostiques
Nous sommes Adfab

Le blog d'Adfab
Copyright © 2018 Adfab Connect