com.iucosoft.eavertizare.gui.ConfiguratiJDialog.java Source code

Java tutorial

Introduction

Here is the source code for com.iucosoft.eavertizare.gui.ConfiguratiJDialog.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iucosoft.eavertizare.gui;

import com.iucosoft.eavertizare.dao.ConfiguratiiDaoIntf;
import com.iucosoft.eavertizare.model.Configuratii;
import javax.swing.JOptionPane;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author valera_
 */
public class ConfiguratiJDialog extends javax.swing.JDialog {

    private final MainJFrame parent;
    private final Configuratii configuratii;
    private final ConfiguratiiDaoIntf configuratiiDao;

    public ConfiguratiJDialog(MainJFrame parent, boolean modal, Configuratii configuratii) {
        setTitle("Adauga sau editeaza configuratie");
        this.parent = parent;
        this.configuratii = configuratii;
        configuratiiDao = (ConfiguratiiDaoIntf) new ClassPathXmlApplicationContext("spring-dao.xml")
                .getBean("configuratiiDao");

        setModal(modal);
        initComponents();
        fillForm();
        setLocationRelativeTo(parent);
    }

    private void fillForm() {
        if (configuratii.getUsername() != "") {
            jTextFieldDriver.setText(configuratii.getDriver());
            jTextFieldUrl.setText(configuratii.getUrlDb());
            jTextFieldUsername.setText(configuratii.getUsername());
            jTextFieldPassword.setText(configuratii.getPassword());
            jTextFieldTabelaClienti.setText(configuratii.getTabelaClienti());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelConfiguratiDriver = new javax.swing.JLabel();
        jLabelConfiguratiUrl = new javax.swing.JLabel();
        jLabelConfiguratiUsername = new javax.swing.JLabel();
        jLabelConfiguratiPassword = new javax.swing.JLabel();
        jLabelConfiguratiTabelaClienti = new javax.swing.JLabel();
        jTextFieldUrl = new javax.swing.JTextField();
        jTextFieldUsername = new javax.swing.JTextField();
        jTextFieldPassword = new javax.swing.JTextField();
        jTextFieldTabelaClienti = new javax.swing.JTextField();
        jButtonSaveConfigurati = new javax.swing.JButton();
        jTextFieldDriver = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabelConfiguratiDriver.setText("Driver:");

        jLabelConfiguratiUrl.setText("URL:");

        jLabelConfiguratiUsername.setText("Username:");

        jLabelConfiguratiPassword.setText("Password:");

        jLabelConfiguratiTabelaClienti.setText("Tabela clienti:");

        jTextFieldUrl.setToolTipText("jdbc:mysql://localhost:3306/company4");
        jTextFieldUrl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldUrlActionPerformed(evt);
            }
        });

        jTextFieldUsername.setToolTipText("root");

        jTextFieldPassword.setToolTipText("free");

        jTextFieldTabelaClienti.setToolTipText("clienti");

        jButtonSaveConfigurati.setText("Save");
        jButtonSaveConfigurati.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveConfiguratiActionPerformed(evt);
            }
        });

        jTextFieldDriver.setToolTipText("com.mysql.jdbc.Driver");
        jTextFieldDriver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldDriverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabelConfiguratiUsername, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelConfiguratiUrl, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelConfiguratiDriver, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelConfiguratiPassword, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelConfiguratiTabelaClienti,
                                        javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTextFieldPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 310,
                                        Short.MAX_VALUE)
                                .addComponent(jTextFieldUsername).addComponent(jTextFieldTabelaClienti)
                                .addComponent(jTextFieldUrl).addComponent(jTextFieldDriver))
                        .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE).addComponent(jButtonSaveConfigurati).addGap(10, 10, 10)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(30, 30, 30).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabelConfiguratiDriver).addComponent(jTextFieldDriver,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabelConfiguratiUrl).addComponent(jTextFieldUrl,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabelConfiguratiUsername)
                                        .addComponent(jTextFieldUsername, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18).addComponent(jLabelConfiguratiPassword))
                        .addComponent(jTextFieldPassword, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabelConfiguratiTabelaClienti)
                                .addComponent(jTextFieldTabelaClienti, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonSaveConfigurati).addGap(30, 30, 30)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonSaveConfiguratiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveConfiguratiActionPerformed
        getDataConfiguratii();
        String word = "";
        if (configuratii.getId() < 1) { //save
            configuratiiDao.save(configuratii);
            word = "adaugata";
        } else {// update
            configuratiiDao.update(configuratii);
            word = "editata";
        }
        JOptionPane.showMessageDialog(this, "Configuratie " + word + " cu success", "Info",
                JOptionPane.INFORMATION_MESSAGE);

        parent.sincronizare();
        parent.refreshFrame();
        this.dispose();
    }//GEN-LAST:event_jButtonSaveConfiguratiActionPerformed

    private void jTextFieldDriverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldDriverActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldDriverActionPerformed

    private void jTextFieldUrlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldUrlActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldUrlActionPerformed

    private void getDataConfiguratii() {
        configuratii.setDriver(jTextFieldDriver.getText());
        configuratii.setUrlDb(jTextFieldUrl.getText());
        configuratii.setUsername(jTextFieldUsername.getText());
        configuratii.setPassword(jTextFieldPassword.getText());
        configuratii.setTabelaClienti(jTextFieldTabelaClienti.getText());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonSaveConfigurati;
    private javax.swing.JLabel jLabelConfiguratiDriver;
    private javax.swing.JLabel jLabelConfiguratiPassword;
    private javax.swing.JLabel jLabelConfiguratiTabelaClienti;
    private javax.swing.JLabel jLabelConfiguratiUrl;
    private javax.swing.JLabel jLabelConfiguratiUsername;
    private javax.swing.JTextField jTextFieldDriver;
    private javax.swing.JTextField jTextFieldPassword;
    private javax.swing.JTextField jTextFieldTabelaClienti;
    private javax.swing.JTextField jTextFieldUrl;
    private javax.swing.JTextField jTextFieldUsername;
    // End of variables declaration//GEN-END:variables

}