com.proyecto.vista.MantenimientoEmpleado.java Source code

Java tutorial

Introduction

Here is the source code for com.proyecto.vista.MantenimientoEmpleado.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.proyecto.vista;

import com.proyecto.beans.Empleado;
import com.proyecto.control.Controlador;
import com.proyecto.control.EmpleadoControlador;
import java.awt.Image;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.apache.commons.beanutils.BeanUtils;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.observablecollections.ObservableCollections;
import org.jdesktop.swingbinding.JTableBinding;
import org.jdesktop.swingbinding.SwingBindings;

/**
 *
 * @author Documentos
 */
public class MantenimientoEmpleado extends javax.swing.JInternalFrame {

    /**
     * Creates new form MantenimientoArea
     */
    private static MantenimientoEmpleado instancia;

    public MantenimientoEmpleado() {
        initComponents();
        icono();
        listar();
        FormularioUtil.activarComponente(panelDatos, false);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
    }

    public static MantenimientoEmpleado getInstancia() {
        if (instancia == null) {
            instancia = new MantenimientoEmpleado();
        }
        return instancia;
    }

    /**
     * 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() {

        jLabel1 = new javax.swing.JLabel();
        txtbuscar = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblempleado = new javax.swing.JTable();
        panelDatos = new javax.swing.JPanel();
        idLabel = new javax.swing.JLabel();
        idField = new javax.swing.JTextField();
        nombreLabel = new javax.swing.JLabel();
        nombreField = new javax.swing.JTextField();
        apellidoPField = new javax.swing.JTextField();
        nombreLabel1 = new javax.swing.JLabel();
        nombreLabel2 = new javax.swing.JLabel();
        telefonoField = new javax.swing.JFormattedTextField();
        nombreLabel3 = new javax.swing.JLabel();
        apellidoMField = new javax.swing.JTextField();
        panelOpciones = new javax.swing.JPanel();
        btnnuevo = new javax.swing.JButton();
        btnmodificar = new javax.swing.JButton();
        btneliminar = new javax.swing.JButton();
        panelGuardar = new javax.swing.JPanel();
        btnguardar = new javax.swing.JButton();
        btncancelar = new javax.swing.JButton();
        lblIcono = new javax.swing.JLabel();

        setClosable(true);
        setTitle("Mantenimiento Empleado");

        jLabel1.setText("Buscar: ");

        jButton1.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png"));
        jButton1.setText("Buscar");

        jLabel2.setText("Lista de empleados:");

        tblempleado
                .setModel(new javax.swing.table.DefaultTableModel(
                        new Object[][] { { null, null, null, null }, { null, null, null, null },
                                { null, null, null, null }, { null, null, null, null } },
                        new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
        jScrollPane1.setViewportView(tblempleado);

        panelDatos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N
        panelDatos.setToolTipText("");

        idLabel.setText("DNI:");

        nombreLabel.setText("Apellido Paterno: ");

        nombreLabel1.setText("Nombres:");

        nombreLabel2.setText("Telfono");

        nombreLabel3.setText("Apellido Materno: ");

        javax.swing.GroupLayout panelDatosLayout = new javax.swing.GroupLayout(panelDatos);
        panelDatos.setLayout(panelDatosLayout);
        panelDatosLayout.setHorizontalGroup(panelDatosLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelDatosLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(nombreLabel3, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 102,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nombreLabel2, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 102,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nombreLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 102,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nombreLabel1, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 102,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(idLabel, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 102,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelDatosLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(apellidoMField, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                                .addComponent(apellidoPField, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(nombreField, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(idField, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(telefonoField))
                        .addContainerGap()));
        panelDatosLayout.setVerticalGroup(panelDatosLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelDatosLayout.createSequentialGroup().addContainerGap()
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(idLabel).addComponent(idField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nombreLabel1)
                                .addComponent(nombreField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nombreLabel).addComponent(apellidoPField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nombreLabel3).addComponent(apellidoMField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(8, 8, 8)
                        .addGroup(panelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nombreLabel2).addComponent(telefonoField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        panelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N
        panelOpciones.setToolTipText("");

        btnnuevo.setIcon(new javax.swing.ImageIcon("img/iconos/Add.png"));
        btnnuevo.setText("Nuevo");
        btnnuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnnuevoActionPerformed(evt);
            }
        });

        btnmodificar.setIcon(new javax.swing.ImageIcon("img/iconos/modificar.png"));
        btnmodificar.setText("Modificar");
        btnmodificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnmodificarActionPerformed(evt);
            }
        });

        btneliminar.setIcon(new javax.swing.ImageIcon("img/iconos/eliminar.png"));
        btneliminar.setText("Eliminar");
        btneliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btneliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelOpcionesLayout = new javax.swing.GroupLayout(panelOpciones);
        panelOpciones.setLayout(panelOpcionesLayout);
        panelOpcionesLayout.setHorizontalGroup(panelOpcionesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelOpcionesLayout.createSequentialGroup().addContainerGap(12, Short.MAX_VALUE)
                        .addGroup(panelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelOpcionesLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(btnmodificar, javax.swing.GroupLayout.DEFAULT_SIZE, 100,
                                                Short.MAX_VALUE)
                                        .addComponent(btneliminar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(btnnuevo, javax.swing.GroupLayout.Alignment.TRAILING,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));
        panelOpcionesLayout
                .setVerticalGroup(panelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                panelOpcionesLayout.createSequentialGroup().addContainerGap().addComponent(btnnuevo)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnmodificar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btneliminar).addContainerGap()));

        panelGuardar.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Acciones",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N

        btnguardar.setIcon(new javax.swing.ImageIcon("img/iconos/Save.png"));
        btnguardar.setText("Guardar");
        btnguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnguardarActionPerformed(evt);
            }
        });

        btncancelar.setIcon(new javax.swing.ImageIcon("img/iconos/Delete.png"));
        btncancelar.setText("Cancelar");
        btncancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btncancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelGuardarLayout = new javax.swing.GroupLayout(panelGuardar);
        panelGuardar.setLayout(panelGuardarLayout);
        panelGuardarLayout.setHorizontalGroup(panelGuardarLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelGuardarLayout.createSequentialGroup().addGap(20, 20, 20)
                        .addGroup(panelGuardarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnguardar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btncancelar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        panelGuardarLayout.setVerticalGroup(panelGuardarLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelGuardarLayout.createSequentialGroup().addContainerGap().addComponent(btnguardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btncancelar)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel1).addGap(18, 18, 18)
                                        .addComponent(txtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 403,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 158, Short.MAX_VALUE))
                        .addComponent(jScrollPane1)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(jButton1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 95,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(lblIcono, javax.swing.GroupLayout.PREFERRED_SIZE, 129,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(panelDatos, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(panelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup()
                                                .addComponent(panelGuardar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGap(1, 1, 1)))))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                        .addComponent(txtbuscar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton1)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(panelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(panelGuardar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(panelDatos, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup().addGap(16, 16, 16).addComponent(lblIcono,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 129,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

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

    private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed
        // TODO add your handling code here:
        accion = Controlador.NUEVO;
        empleadoControlador.prepararCrear();
        FormularioUtil.activarComponente(panelOpciones, false);
        FormularioUtil.activarComponente(panelGuardar, true);
        FormularioUtil.activarComponente(panelDatos, true);
        idField.requestFocusInWindow();
    }//GEN-LAST:event_btnnuevoActionPerformed

    private void icono() {
        ImageIcon fot = new ImageIcon("img/iconos/personal 128x128.png");
        //        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblIcono.getWidth(), lblIcono.getHeight(), Image.SCALE_DEFAULT));
        lblIcono.setIcon(fot);
    }

    private void btnmodificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnmodificarActionPerformed
        // TODO add your handling code here:
        accion = Controlador.MODIFICAR;

        int fila = this.tblempleado.getSelectedRow();
        if (fila != -1) {
            FormularioUtil.activarComponente(panelDatos, true);
            FormularioUtil.activarComponente(panelOpciones, false);
            FormularioUtil.activarComponente(panelGuardar, true);

            accion = Controlador.MODIFICAR;
            empleadoControlador.setSeleccionado(lista.get(fila));
            Empleado empleado = empleadoControlador.getSeleccionado();
            try {
                idField.setText(BeanUtils.getProperty(empleado, "dni"));
                nombreField.setText(BeanUtils.getProperty(empleado, "nombres"));
                apellidoPField.setText(BeanUtils.getProperty(empleado, "apellidoPaterno"));
                apellidoMField.setText(BeanUtils.getProperty(empleado, "apellidoMaterno"));
                telefonoField.setText(BeanUtils.getProperty(empleado, "telefono"));
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe seleccionar una Clase", "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnmodificarActionPerformed

    private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed
        // TODO add your handling code here:
        accion = Controlador.ELIMINAR;
        if (tblempleado.getSelectedRow() != -1) {

            Integer codigo = tblempleado.getSelectedRow();

            Empleado empleado = empleadoControlador.buscarPorId(lista.get(codigo).getDni());

            if (empleado != null) {
                if (JOptionPane.showConfirmDialog(null, "Desea Eliminar el Empleado?", "Mensaje del Sistema",
                        JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                    int[] filas = tblempleado.getSelectedRows();
                    for (int i = 0; i < filas.length; i++) {
                        Empleado empleado2 = lista.get(filas[0]);
                        lista.remove(empleado2);
                        empleadoControlador.setSeleccionado(empleado2);
                        empleadoControlador.accion(accion);
                    }
                    if (empleadoControlador.accion(accion) == 3) {
                        JOptionPane.showMessageDialog(null, "Empleado eliminado correctamente",
                                "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                    } else {
                        JOptionPane.showMessageDialog(null, "Empleado no eliminada", "Mensaje del Sistema",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Empleado no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe seleccionar un Empleado", "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btneliminarActionPerformed

    private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed
        // TODO add your handling code here:
        List<Integer> array = new ArrayList();

        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.telefonoField, "telefono"));
        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoMField,
                "apellido materno"));
        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.apellidoPField,
                "apellido paterno"));
        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.NUMERO, this.nombreField, "nombre"));
        array.add(FormularioUtil.Validar(FormularioUtil.TipoValidacion.LETRA, this.idField, "DNI"));

        FormularioUtil.validar2(array);

        if (FormularioUtil.error) {
            JOptionPane.showMessageDialog(null, FormularioUtil.mensaje, "Mensaje del Sistema",
                    JOptionPane.ERROR_MESSAGE);
            FormularioUtil.mensaje = "";
            FormularioUtil.error = false;
        } else {
            String palabra = "";
            String palabra2 = "";
            if (accion == 1) {
                palabra = "registrar";
                palabra2 = "registrado";

                if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?",
                        "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado()
                            .setApellidoPaterno(apellidoPField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado()
                            .setApellidoMaterno(apellidoMField.getText().toUpperCase());
                    empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());

                    empleadoControlador.accion(accion);
                    lista.add(empleadoControlador.getSeleccionado());

                    if (accion == 1) {
                        JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente",
                                "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);
                        FormularioUtil.limpiarComponente(panelDatos);
                    } else {
                        JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    FormularioUtil.limpiarComponente(panelDatos);
                    JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else if (accion == 2) {
                palabra = "modificar";
                palabra2 = "modificado";

                if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " el Empleado?",
                        "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                    if (accion == 2) {
                        JOptionPane.showMessageDialog(null, "Empleado " + palabra2 + " correctamente",
                                "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE);

                        lista.clear();
                        empleadoControlador.getSeleccionado().setDni(idField.getText().toUpperCase());
                        empleadoControlador.getSeleccionado().setNombres(nombreField.getText().toUpperCase());
                        empleadoControlador.getSeleccionado()
                                .setApellidoPaterno(apellidoPField.getText().toUpperCase());
                        empleadoControlador.getSeleccionado()
                                .setApellidoMaterno(apellidoMField.getText().toUpperCase());
                        empleadoControlador.getSeleccionado().setTelefono(telefonoField.getText().toUpperCase());
                        empleadoControlador.accion(accion);
                        listar();

                        FormularioUtil.limpiarComponente(panelDatos);

                    } else {
                        JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    FormularioUtil.limpiarComponente(panelDatos);
                    JOptionPane.showMessageDialog(null, "Empleado no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            }

            FormularioUtil.limpiarComponente(panelDatos);
            FormularioUtil.activarComponente(panelOpciones, true);
            FormularioUtil.activarComponente(panelGuardar, false);
            FormularioUtil.activarComponente(panelDatos, false);
        }
    }//GEN-LAST:event_btnguardarActionPerformed

    private void btncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncancelarActionPerformed
        // TODO add your handling code here:
        FormularioUtil.activarComponente(panelDatos, false);
        FormularioUtil.limpiarComponente(panelDatos);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
    }//GEN-LAST:event_btncancelarActionPerformed

    private int accion;
    private List<Empleado> lista;
    private final EmpleadoControlador empleadoControlador = new EmpleadoControlador();

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField apellidoMField;
    private javax.swing.JTextField apellidoPField;
    private javax.swing.JButton btncancelar;
    private javax.swing.JButton btneliminar;
    private javax.swing.JButton btnguardar;
    private javax.swing.JButton btnmodificar;
    private javax.swing.JButton btnnuevo;
    private javax.swing.JTextField idField;
    private javax.swing.JLabel idLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblIcono;
    private javax.swing.JTextField nombreField;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JLabel nombreLabel1;
    private javax.swing.JLabel nombreLabel2;
    private javax.swing.JLabel nombreLabel3;
    private javax.swing.JPanel panelDatos;
    private javax.swing.JPanel panelGuardar;
    private javax.swing.JPanel panelOpciones;
    private javax.swing.JTable tblempleado;
    private javax.swing.JFormattedTextField telefonoField;
    private javax.swing.JTextField txtbuscar;
    // End of variables declaration//GEN-END:variables

    private void listar() {
        lista = empleadoControlador.buscarTodos();
        lista = ObservableCollections.observableList(lista);
        JTableBinding binding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, lista,
                tblempleado);

        BeanProperty bNombre = BeanProperty.create("nombres");
        BeanProperty bApellidoP = BeanProperty.create("apellidoPaterno");
        BeanProperty bApellidoM = BeanProperty.create("apellidoMaterno");
        BeanProperty bDni = BeanProperty.create("dni");
        BeanProperty bTelefono = BeanProperty.create("telefono");

        binding.addColumnBinding(bNombre).setColumnName("NOMBRES").setEditable(false);
        binding.addColumnBinding(bApellidoP).setColumnName("APELLIDO_PATERNO").setEditable(false);
        binding.addColumnBinding(bApellidoM).setColumnName("APELLIDO_MATERNO").setEditable(false);
        binding.addColumnBinding(bDni).setColumnName("DNI").setEditable(false);
        binding.addColumnBinding(bTelefono).setColumnName("TELEFONO").setEditable(false);

        binding.bind();

    }
}