com.biosis.biosislite.vistas.inventario.MantenimientoBien.java Source code

Java tutorial

Introduction

Here is the source code for com.biosis.biosislite.vistas.inventario.MantenimientoBien.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.biosis.biosislite.vistas.inventario;

import com.biosis.biosislite.vistas.dialogos.inventario.DlgClaseBusqueda;
import com.biosis.biosislite.entidades.inventario.Bien;
import com.biosis.biosislite.entidades.inventario.Campo;
import com.biosis.biosislite.entidades.inventario.Clase;
import com.biosis.biosislite.entidades.inventario.DetalleBienCampo;
import com.biosis.biosislite.controladores.inventario.AbstractControlador;
import com.biosis.biosislite.controladores.inventario.BienControlador;
import com.biosis.biosislite.controladores.inventario.CampoControlador;
import com.biosis.biosislite.controladores.inventario.DetalleBienCampoControlador;
import java.awt.Color;
import java.awt.Dimension;
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 javax.swing.JTable;
import javax.swing.SpinnerNumberModel;
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 MantenimientoBien extends javax.swing.JInternalFrame {

    /**
     * Creates new form MantenimientoBien
     */
    private static MantenimientoBien instancia;

    private boolean validar = false;

    public MantenimientoBien() {
        initComponents();
        listar();
        buscar();
        actualizarControlesNavegacion();
        lista3 = ObservableCollections.observableList(lista3);
        //        cargarCombo();

        //        cargarComboLazy();
        fotoField.setMaximumSize(new Dimension(324, 20));

        //        limite = (Integer) cmblazy.getSelectedItem();
        //        offset = 0;
        //        txtpagina.setText("1");
        //        btnAtras.setEnabled(false);
        //        btnInicio.setEnabled(false);
        //        txtpagina.setEditable(false);
        FormularioUtil.activarComponente(panelDatos, false);
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);

    }

    public static MantenimientoBien getInstancia() {
        if (instancia == null) {
            instancia = new MantenimientoBien();
        }
        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() {
        java.awt.GridBagConstraints gridBagConstraints;

        panelDatos = new javax.swing.JPanel();
        nombreLabel = new javax.swing.JLabel();
        nombreField = new javax.swing.JTextField();
        fotosLabel = new javax.swing.JLabel();
        fotoField = new javax.swing.JTextField();
        nombreLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        descripcionField = new javax.swing.JTextArea();
        nombreLabel2 = new javax.swing.JLabel();
        claseField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        spnStock = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        spnStockMax = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        lblValidar = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtbuscar = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        panelFondo = new javax.swing.JPanel();
        fotoLbl = new javax.swing.JLabel();
        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();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnPrimero = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        spPagina = new javax.swing.JSpinner();
        txtTotal = new javax.swing.JTextField();
        btnSiguiente = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        cboTamanio = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblbienes = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblDetalle = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setTitle("Mantenimiento de Bienes");
        java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
        layout.columnWidths = new int[] { 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0 };
        layout.rowHeights = new int[] { 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0 };
        getContentPane().setLayout(layout);

        panelDatos.setBackground(new java.awt.Color(213, 233, 249));
        panelDatos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 14))); // NOI18N
        panelDatos.setToolTipText("");
        java.awt.GridBagLayout panelDatosLayout = new java.awt.GridBagLayout();
        panelDatosLayout.columnWidths = new int[] { 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0 };
        panelDatosLayout.rowHeights = new int[] { 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0 };
        panelDatos.setLayout(panelDatosLayout);

        nombreLabel.setText("Nombre:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        panelDatos.add(nombreLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 13;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        panelDatos.add(nombreField, gridBagConstraints);

        fotosLabel.setText("Foto:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        panelDatos.add(fotosLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.gridwidth = 11;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.2;
        panelDatos.add(fotoField, gridBagConstraints);

        nombreLabel1.setText("Observaciones:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        panelDatos.add(nombreLabel1, gridBagConstraints);

        jButton2.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png"));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 20;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        panelDatos.add(jButton2, gridBagConstraints);

        descripcionField.setColumns(20);
        descripcionField.setRows(5);
        jScrollPane2.setViewportView(descripcionField);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 13;
        gridBagConstraints.gridheight = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.1;
        panelDatos.add(jScrollPane2, gridBagConstraints);

        nombreLabel2.setText("Clase:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        panelDatos.add(nombreLabel2, gridBagConstraints);

        claseField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                claseFieldPropertyChange(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 11;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.2;
        panelDatos.add(claseField, gridBagConstraints);

        jButton1.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png"));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 20;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        panelDatos.add(jButton1, gridBagConstraints);

        jLabel4.setText("Stock mnimo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        panelDatos.add(jLabel4, gridBagConstraints);

        spnStock.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        panelDatos.add(spnStock, gridBagConstraints);

        jLabel5.setText("Stock mximo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 16;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        panelDatos.add(jLabel5, gridBagConstraints);

        spnStockMax.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 20;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        panelDatos.add(spnStockMax, gridBagConstraints);

        jLabel6.setText("Cdigo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
        panelDatos.add(jLabel6, gridBagConstraints);

        txtCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCodigoKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 7;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        panelDatos.add(txtCodigo, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 16;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        panelDatos.add(lblValidar, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 0.1;
        getContentPane().add(panelDatos, gridBagConstraints);

        jLabel1.setText("Buscar: ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        getContentPane().add(jLabel1, gridBagConstraints);

        txtbuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtbuscarKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 0.1;
        getContentPane().add(txtbuscar, gridBagConstraints);

        jLabel2.setText("Lista de bienes:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(jLabel2, gridBagConstraints);

        jButton3.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png"));
        jButton3.setText("Buscar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 8;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(jButton3, gridBagConstraints);

        panelFondo.setBackground(new java.awt.Color(213, 233, 249));
        panelFondo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Foto",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 14))); // NOI18N

        fotoLbl.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/iconosLogin/no_disponible.png"))); // NOI18N

        javax.swing.GroupLayout panelFondoLayout = new javax.swing.GroupLayout(panelFondo);
        panelFondo.setLayout(panelFondoLayout);
        panelFondoLayout
                .setHorizontalGroup(panelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(fotoLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 339, Short.MAX_VALUE));
        panelFondoLayout
                .setVerticalGroup(panelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(fotoLbl, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 0.2;
        getContentPane().add(panelFondo, gridBagConstraints);

        panelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 14))); // NOI18N
        panelOpciones.setToolTipText("");
        panelOpciones.setLayout(new java.awt.GridLayout(1, 0));

        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);
            }
        });
        panelOpciones.add(btnnuevo);

        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);
            }
        });
        panelOpciones.add(btnmodificar);

        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);
            }
        });
        panelOpciones.add(btneliminar);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.gridwidth = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        getContentPane().add(panelOpciones, gridBagConstraints);

        panelGuardar.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Accin",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 14))); // NOI18N
        panelGuardar.setLayout(new java.awt.GridLayout(1, 0));

        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);
            }
        });
        panelGuardar.add(btnguardar);

        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);
            }
        });
        panelGuardar.add(btncancelar);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 12;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 0.1;
        getContentPane().add(panelGuardar, gridBagConstraints);

        jPanel1.setMinimumSize(new java.awt.Dimension(350, 47));
        java.awt.GridBagLayout jPanel1Layout = new java.awt.GridBagLayout();
        jPanel1Layout.columnWidths = new int[] { 0 };
        jPanel1Layout.rowHeights = new int[] { 0, 7, 0 };
        jPanel1.setLayout(jPanel1Layout);

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        btnPrimero.setText("<<");
        btnPrimero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimeroActionPerformed(evt);
            }
        });
        jPanel2.add(btnPrimero);

        btnAnterior.setText("<");
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });
        jPanel2.add(btnAnterior);

        spPagina.setModel(new javax.swing.SpinnerNumberModel(1, 1, null, 1));
        spPagina.setMinimumSize(new java.awt.Dimension(60, 20));
        spPagina.setPreferredSize(new java.awt.Dimension(60, 20));
        spPagina.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                spPaginaStateChanged(evt);
            }
        });
        jPanel2.add(spPagina);

        txtTotal.setEditable(false);
        txtTotal.setColumns(3);
        txtTotal.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTotal.setText("1");
        jPanel2.add(txtTotal);

        btnSiguiente.setText(">");
        btnSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguienteActionPerformed(evt);
            }
        });
        jPanel2.add(btnSiguiente);

        btnUltimo.setText(">>");
        btnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimoActionPerformed(evt);
            }
        });
        jPanel2.add(btnUltimo);

        cboTamanio.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "5", "10", "15", "20", "25", "40", "50" }));
        cboTamanio.setMinimumSize(new java.awt.Dimension(53, 24));
        cboTamanio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTamanioActionPerformed(evt);
            }
        });
        jPanel2.add(cboTamanio);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        jPanel1.add(jPanel2, gridBagConstraints);

        tblbienes
                .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" }));
        tblbienes.setPreferredSize(new java.awt.Dimension(270, 64));
        tblbienes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblbienesMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tblbienes);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        gridBagConstraints.weighty = 0.1;
        jPanel1.add(jScrollPane1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 9;
        gridBagConstraints.gridheight = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 0.3;
        getContentPane().add(jPanel1, gridBagConstraints);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        jLabel3.setText("Caracteristicas:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        jPanel3.add(jLabel3, gridBagConstraints);

        tblDetalle.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {} }, new String[] {

        }));
        jScrollPane3.setViewportView(tblDetalle);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 515;
        gridBagConstraints.ipady = 66;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
        jPanel3.add(jScrollPane3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 10;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 0.1;
        getContentPane().add(jPanel3, gridBagConstraints);

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

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //        JFileChooser fc = new JFileChooser();
        //        int respuesta = fc.showOpenDialog(this);
        //        if (respuesta == JFileChooser.APPROVE_OPTION) {
        //            File archivoElegido = fc.getSelectedFile();
        //            String absolute = archivoElegido.getAbsolutePath();
        //            fotoField.setText(archivoElegido.ge);
        //
        ////            fotolbl.setIcon(new ImageIcon("C:/Users/Documentos/Desktop/HS/" + fotosField.getText()));
        //            ImageIcon fot = new ImageIcon(absolute);
        //            Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT));
        //            fotoLbl.setIcon(icono);
        //
        //        }
        String foto = FormularioUtil.chooserImagen(this);

        if (!foto.equals("")) {
            fotoField.setText(foto);

            ImageIcon fot = new ImageIcon(foto);
            Icon icono = new ImageIcon(
                    fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT));
            fotoLbl.setIcon(icono);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        paginaActual = 1;
        buscar();
        actualizarControlesNavegacion();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed
        // TODO add your handling code here:
        accion = AbstractControlador.NUEVO;
        bienControlador.prepararCrear();
        FormularioUtil.activarComponente(panelOpciones, false);
        FormularioUtil.activarComponente(panelGuardar, true);
        FormularioUtil.activarComponente(panelDatos, true);
        FormularioUtil.limpiarComponente(panelDatos);
        descripcionField.setText(null);
        claseField.setEditable(false);
        fotoField.setEditable(false);
        nombreField.requestFocusInWindow();
        //        cmbClase.removeAllItems();
        //        cargarCombo();
        lista3.clear();
    }//GEN-LAST:event_btnnuevoActionPerformed

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

        //        cargarCombo();
        int fila = this.tblbienes.getSelectedRow();
        if (fila != -1) {
            FormularioUtil.activarComponente(panelDatos, true);
            FormularioUtil.activarComponente(panelOpciones, false);
            FormularioUtil.activarComponente(panelGuardar, true);
            claseField.setEditable(false);
            fotoField.setEditable(false);

            accion = AbstractControlador.MODIFICAR;
            bienControlador.setSeleccionado(lista.get(fila));

            Bien bien = bienControlador.getSeleccionado();
            try {
                nombreField.setText(BeanUtils.getProperty(bien, "nombre"));
                descripcionField.setText(BeanUtils.getProperty(bien, "descripcion"));

                this.txtCodigo.setText(bien.getCodigo());
                spnStock.setValue(bien.getStockMinimo());
                spnStockMax.setValue(bien.getStockMaximo());

                //                fotoField.setText(BeanUtils.getProperty(bien, "foto"));

                //                ImageIcon fot = new ImageIcon(fotoField.getText());
                //                Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(), Image.SCALE_DEFAULT));
                //                fotoLbl.setIcon(icono);
                //                cmbClase.setSelectedItem(bien.getClase());
                claseField.setText(bien.getClase().getNombre());
                listarCamposMod(bien);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe seleccionar un Bien", "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 = AbstractControlador.ELIMINAR;
        if (tblbienes.getSelectedRow() != -1) {

            Integer codigo = tblbienes.getSelectedRow();

            Bien bien = bienControlador.buscarPorId(lista.get(codigo).getId());

            if (bien != null) {
                if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Bien?", "Mensaje del Sistema",
                        JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {

                    int[] filas = tblbienes.getSelectedRows();
                    for (int i = 0; i < filas.length; i++) {
                        Bien bien2 = lista.get(filas[0]);
                        lista.remove(bien2);
                        bienControlador.setSeleccionado(bien2);
                        bienControlador.accion(accion);
                    }
                    if (bienControlador.accion(accion) == 3) {
                        JOptionPane.showMessageDialog(null, "Bien eliminada correctamente", "Mensaje del Sistema",
                                JOptionPane.INFORMATION_MESSAGE);

                    } else {
                        JOptionPane.showMessageDialog(null, "Bien no eliminada", "Mensaje del Sistema",
                                JOptionPane.ERROR_MESSAGE);
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Bien no eliminada", "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe seleccionar un Bien", "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:
        String palabra = "";
        String palabra2 = "";
        if (accion == 1) {
            palabra = "registrar";
            palabra2 = "registrado";

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

                bienControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());
                //                bienControlador.getSeleccionado().setCodigo(idField.getText());
                bienControlador.getSeleccionado().setDescripcion(descripcionField.getText().toUpperCase());
                bienControlador.getSeleccionado().setFoto(fotoField.getText());
                bienControlador.getSeleccionado().setStockMinimo((Integer) spnStock.getValue());
                bienControlador.getSeleccionado().setStockMaximo((Integer) spnStockMax.getValue());

                if (this.validar) {
                    bienControlador.getSeleccionado().setCodigo(this.txtCodigo.getText());
                    this.validar = false;

                }

                //                Clase clase = (Clase) cmbClase.getSelectedItem();
                //                bienControlador.getSeleccionado().setClase(clase);
                bienControlador.accion(accion);
                lista.add(bienControlador.getSeleccionado());

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

                } else {
                    JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Error en la informacin ingresada", "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else if (accion == 2) {
            palabra = "modificar";
            palabra2 = "modificado";

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

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

                    lista.clear();
                    bienControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase());
                    //                    bienControlador.getSeleccionado().setCodigo(nombreField.getText());
                    bienControlador.getSeleccionado().setDescripcion(descripcionField.getText().toUpperCase());
                    bienControlador.getSeleccionado().setFoto(fotoField.getText());
                    bienControlador.getSeleccionado().setStockMinimo((Integer) spnStock.getValue());
                    bienControlador.getSeleccionado().setStockMaximo((Integer) spnStockMax.getValue());

                    //                    Clase clase = (Clase) cmbClase.getSelectedItem();
                    //                    bienControlador.getSeleccionado().setClase(clase);
                    bienControlador.accion(accion);
                    listar();

                } else {
                    JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                            JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Bien no " + palabra2, "Mensaje del Sistema",
                        JOptionPane.ERROR_MESSAGE);
            }
        }

        for (DetalleBienCampo detalle : lista3) {
            detalle.setBien(bienControlador.getSeleccionado());
            detalleControlador.setSeleccionado(detalle);
            detalleControlador.accion(AbstractControlador.MODIFICAR);
        }

        lista3.clear();
        FormularioUtil.activarComponente(panelOpciones, true);
        FormularioUtil.activarComponente(panelGuardar, false);
        FormularioUtil.activarComponente(panelDatos, false);
        FormularioUtil.limpiarComponente(panelDatos);
        fotoLbl.setIcon(null);
        descripcionField.setText(null);

    }//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);
        fotoLbl.setIcon(null);
        descripcionField.setText(null);
        lista3.clear();
    }//GEN-LAST:event_btncancelarActionPerformed

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

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

    private void spPaginaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spPaginaStateChanged
        // TODO add your handling code here:
        this.seleccionPagina();
    }//GEN-LAST:event_spPaginaStateChanged

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

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

    private void cboTamanioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTamanioActionPerformed
        // TODO add your handling code here:
        this.paginaActual = 1;
        buscar();
        this.actualizarControlesNavegacion();
    }//GEN-LAST:event_cboTamanioActionPerformed

    private void tblbienesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblbienesMouseReleased
        // TODO add your handling code here:
        if (evt.getClickCount() == 1) {

            int fila = tblbienes.getSelectedRow();
            this.bien = lista.get(fila);

            try {
                nombreField.setText(BeanUtils.getProperty(bien, "nombre"));
                descripcionField.setText(BeanUtils.getProperty(bien, "descripcion"));
                fotoField.setText(BeanUtils.getProperty(bien, "foto"));
                spnStock.setValue(bien.getStockMinimo());
                spnStockMax.setValue(bien.getStockMaximo());
                txtCodigo.setText(bien.getCodigo());

                ImageIcon fot = new ImageIcon(fotoField.getText());
                //                if (fot.getImage().){
                //                    fot = new ImageIcon("img/no_disponible.png");
                //                }
                Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(),
                        Image.SCALE_DEFAULT));
                fotoLbl.setIcon(icono);

                System.out.println("tamao icon: " + fotoLbl.getIcon().getIconHeight());
                if (fotoLbl.getIcon().getIconHeight() == -1) {
                    fot = new ImageIcon("img/no_disponible.png");
                    icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(),
                            Image.SCALE_DEFAULT));
                    fotoLbl.setIcon(icono);
                }

                //                cmbClase.setSelectedItem(bien.getClase());
                claseField.setText(bien.getClase().getNombre());
                listarCamposMod(bien);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_tblbienesMouseReleased

    private void txtbuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtbuscarKeyReleased
        // TODO add your handling code here:
        paginaActual = 1;
        buscar();
        actualizarControlesNavegacion();
    }//GEN-LAST:event_txtbuscarKeyReleased

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        DlgClaseBusqueda claseDialogo = new DlgClaseBusqueda(this);

        claseDialogo.setVisible(true);
        listarCampos(claseDialogo.getClase());
        bienControlador.getSeleccionado().setClase(claseDialogo.getClase());
        if (bienControlador.getSeleccionado().getClase() != null) {
            this.claseField.setText(this.bienControlador.getSeleccionado().getClase().getNombre().toUpperCase());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void claseFieldPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_claseFieldPropertyChange
        // TODO add your handling code here:

    }//GEN-LAST:event_claseFieldPropertyChange

    private void txtCodigoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodigoKeyReleased
        // TODO add your handling code here:

        //        for (Bien validarCodigo : this.bienControlador.buscarXCodigo(title)) {
        //            if (validarCodigo.getCodigo().equals(this.txtCodigo.getText())) {
        //                validar = true;
        //                break;
        //            }
        //        }
        Bien bienCodigoRepetido = this.bienControlador.buscarXCodigoBien(this.txtCodigo.getText());
        if (bienCodigoRepetido == null && (this.txtCodigo.getText().length() == 5)) {
            this.lblValidar.setForeground(Color.GREEN);
            this.lblValidar.setText("Cdigo vlido");
            this.validar = true;
        } else if ((this.txtCodigo.getText().length() != 5)) {
            this.lblValidar.setForeground(Color.RED);
            this.lblValidar.setText("Cdigo invlido");

            this.validar = false;

        }
    }//GEN-LAST:event_txtCodigoKeyReleased

    Bien bien;
    private int accion;
    private List<Bien> lista;
    private List<Campo> lista2;
    private List<DetalleBienCampo> lista3 = new ArrayList();

    private final BienControlador bienControlador = new BienControlador();

    private final CampoControlador campoControlador = new CampoControlador();

    private final DetalleBienCampoControlador detalleControlador = new DetalleBienCampoControlador();

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnPrimero;
    private javax.swing.JButton btnSiguiente;
    private javax.swing.JButton btnUltimo;
    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.JComboBox cboTamanio;
    private javax.swing.JTextField claseField;
    private javax.swing.JTextArea descripcionField;
    private javax.swing.JTextField fotoField;
    private javax.swing.JLabel fotoLbl;
    private javax.swing.JLabel fotosLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblValidar;
    private javax.swing.JTextField nombreField;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JLabel nombreLabel1;
    private javax.swing.JLabel nombreLabel2;
    private javax.swing.JPanel panelDatos;
    private javax.swing.JPanel panelFondo;
    private javax.swing.JPanel panelGuardar;
    private javax.swing.JPanel panelOpciones;
    private javax.swing.JSpinner spPagina;
    private javax.swing.JSpinner spnStock;
    private javax.swing.JSpinner spnStockMax;
    private javax.swing.JTable tblDetalle;
    private javax.swing.JTable tblbienes;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtTotal;
    private javax.swing.JTextField txtbuscar;
    // End of variables declaration//GEN-END:variables

    private void listar() {
        lista = new ArrayList<>();
        lista = ObservableCollections.observableList(lista);
        JTableBinding binding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, lista,
                tblbienes);

        //        BeanProperty bCodigoId = BeanProperty.create("id");
        BeanProperty bNombre = BeanProperty.create("nombre");
        BeanProperty bClaseId = BeanProperty.create("clase");

        //        binding.addColumnBinding(bCodigoId).setColumnName("ID").setEditable(false);
        binding.addColumnBinding(bNombre).setColumnName("NOMBRE").setEditable(false);
        binding.addColumnBinding(bClaseId).setColumnName("CLASE").setEditable(false);

        binding.bind();

    }

    //    private void cargarCombo() {
    //        ClaseControlador claseControl = new ClaseControlador();
    //        List<Clase> clase = claseControl.buscarTodos();
    //        cmbClase.setModel(new DefaultComboBoxModel(clase.toArray()));
    //    }
    //    private void cargarComboLazy() {
    //        DefaultComboBoxModel modeloCombo = new DefaultComboBoxModel();
    //        int paginacion = 5;
    //        for (int i = 0; i < 4; i++) {
    //            modeloCombo.addElement(paginacion);
    //            paginacion = paginacion + 5;
    //        }
    //        cmblazy.setModel(modeloCombo);
    //    }
    List<DetalleBienCampo> listaDetalle;
    //    DetalleBienCampoControlador detalleControlador = new DetalleBienCampoControlador();

    private void listarCampos(Clase clase) {

        lista2 = campoControlador.buscarXClase(clase);
        lista3.clear();
        //        lista3 = ObservableCollections.observableList(lista3);

        //        lista2 = ObservableCollections.observableList(lista);
        if (accion == 1) {
            for (Campo campo : lista2) {
                DetalleBienCampo detalle = new DetalleBienCampo();
                detalle.setCampo(campo);
                detalle.setValor(null);
                detalle.setBien(null);
                lista3.add(detalle);
            }
        } else if (accion == 2) {
            listaDetalle = detalleControlador.buscarXBienFull(bienControlador.getSeleccionado());
            lista3.clear();
            lista3.addAll(listaDetalle);
        }
        BindTabla(lista3, tblDetalle);
    }

    private void listarCamposMod(Bien bien) {

        lista3.clear();
        lista3.addAll(detalleControlador.buscarXBienFull(bien));

        BindTabla(lista3, tblDetalle);

    }

    private void BindTabla(List<DetalleBienCampo> lista, JTable tabla) {

        JTableBinding binding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, lista, tabla);

        BeanProperty bId = BeanProperty.create("campo");
        BeanProperty bValor = BeanProperty.create("valor");

        binding.addColumnBinding(bId).setColumnName("CAMPO").setEditable(false);
        binding.addColumnBinding(bValor).setColumnName("VALOR").setEditable(true);

        binding.bind();
    }

    /*
     PARA TRABAJAR LAZY MODEL
     */
    private int paginaActual = 1;
    private int totalPaginas = 0;
    private int tamanioPagina = 0;

    private void buscar() {
        String busqueda = txtbuscar.getText().toUpperCase();
        tamanioPagina = Integer.parseInt(cboTamanio.getSelectedItem().toString());

        lista.clear();
        lista.addAll(this.listar(busqueda, paginaActual, tamanioPagina));
    }

    private List<Bien> listar(String buscar, int pagina, int tamanio) {
        int total = this.bienControlador.totalXNombre(buscar);
        if (total % tamanio == 0) {
            totalPaginas = total / tamanio;
        } else {
            totalPaginas = (total / tamanio) + 1;
        }
        return this.bienControlador.buscarLazyXNombre(buscar, (pagina - 1) * tamanio, tamanio);

    }

    private void siguiente() {
        paginaActual++;
        buscar();
        this.actualizarControlesNavegacion();
    }

    private void ultimo() {
        paginaActual = totalPaginas;
        buscar();
        this.actualizarControlesNavegacion();
    }

    private void primero() {
        paginaActual = 1;
        buscar();
        this.actualizarControlesNavegacion();
    }

    private void anterior() {
        paginaActual--;
        buscar();
        this.actualizarControlesNavegacion();
    }

    private void seleccionPagina() {
        paginaActual = (int) spPagina.getValue();
        buscar();
        this.actualizarControlesNavegacion();
    }

    private void actualizarControlesNavegacion() {
        spPagina.setValue(paginaActual);
        txtTotal.setText(totalPaginas + "");

        SpinnerNumberModel modeloSP = (SpinnerNumberModel) spPagina.getModel();
        Comparable<Integer> maximo = totalPaginas;
        modeloSP.setMaximum(maximo);

        this.btnSiguiente.setEnabled(paginaActual != totalPaginas);
        this.btnUltimo.setEnabled(paginaActual != totalPaginas);

        this.btnAnterior.setEnabled(paginaActual != 1);
        this.btnPrimero.setEnabled(paginaActual != 1);
    }
}