Ciclo.editaCiclo.java Source code

Java tutorial

Introduction

Here is the source code for Ciclo.editaCiclo.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 Ciclo;

import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Ciclo;
import Hibernate.entidades.Usuario;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import Integral.DefaultTableHeaderCellRenderer;
import Integral.Herramientas;
import Integral.Render1;
import Integral.VerticalTableHeaderCellRenderer;

/**
 *
 * @author ESPECIALIZADO TOLUCA
 */
public class editaCiclo extends javax.swing.JPanel {

    //private Session session;
    DefaultTableModel model;
    Usuario usr;
    String sessionPrograma = "";
    Herramientas h;
    private Ciclo actor;
    String ic = "";
    String[] columnas = new String[] { "Clave", "Descripcin" };

    /**
     * Creates new form EditaCiclo
     */
    public editaCiclo(Usuario usuario, String ses) {
        initComponents();
        sessionPrograma = ses;
        usr = usuario;
        formatoTabla();
        buscaDato();
    }

    DefaultTableModel ModeloTablaReporte(int renglones, String columnas[]) {
        model = new DefaultTableModel(new Object[renglones][2], columnas) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false };

            public void setValueAt(Object value, int row, int col) {
                Vector vector = (Vector) this.dataVector.elementAt(row);
                Object celda = ((Vector) this.dataVector.elementAt(row)).elementAt(col);
                switch (col) {
                case 0:
                    vector.setElementAt(value, col);
                    this.dataVector.setElementAt(vector, row);
                    fireTableCellUpdated(row, col);
                    break;
                default:
                    vector.setElementAt(value, col);
                    this.dataVector.setElementAt(vector, row);
                    fireTableCellUpdated(row, col);
                    break;
                }
            }

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };
        return model;
    }

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

        jPanel2 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        t_datos = new javax.swing.JTable();
        Selecciona2 = new javax.swing.JButton();
        Eliminar1 = new javax.swing.JButton();
        Selecciona1 = new javax.swing.JButton();
        bt_actualiza1 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        t_ciclo = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        t_descripcion = new javax.swing.JTextField();
        b_cancelar = new javax.swing.JButton();
        b_guardar = new javax.swing.JButton();

        setBackground(new java.awt.Color(254, 254, 254));

        jPanel2.setBackground(new java.awt.Color(254, 254, 254));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Edita Ciclo",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 12))); // NOI18N

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Lista",
                javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 11))); // NOI18N

        jScrollPane1.setBackground(new java.awt.Color(254, 254, 254));

        t_datos.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Clave", "Descripcin" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.Object.class };
            boolean[] canEdit = new boolean[] { false, true };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        t_datos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        t_datos.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(t_datos);

        Selecciona2.setBackground(new java.awt.Color(2, 135, 242));
        Selecciona2.setForeground(new java.awt.Color(254, 254, 254));
        Selecciona2.setIcon(new ImageIcon("imagenes/add-user.png"));
        Selecciona2.setText("Nuevo");
        Selecciona2.setToolTipText("Agregar un registo actual");
        Selecciona2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Selecciona2.setMaximumSize(new java.awt.Dimension(87, 23));
        Selecciona2.setMinimumSize(new java.awt.Dimension(87, 23));
        Selecciona2.setNextFocusableComponent(b_cancelar);
        Selecciona2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Selecciona2ActionPerformed(evt);
            }
        });

        Eliminar1.setBackground(new java.awt.Color(2, 135, 242));
        Eliminar1.setForeground(new java.awt.Color(254, 254, 254));
        Eliminar1.setIcon(new ImageIcon("imagenes/del-user.png"));
        Eliminar1.setText("Eliminar");
        Eliminar1.setToolTipText("Eliminar el registro actual");
        Eliminar1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Eliminar1.setMaximumSize(new java.awt.Dimension(87, 23));
        Eliminar1.setMinimumSize(new java.awt.Dimension(87, 23));
        Eliminar1.setNextFocusableComponent(Selecciona2);
        Eliminar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Eliminar1ActionPerformed(evt);
            }
        });

        Selecciona1.setBackground(new java.awt.Color(2, 135, 242));
        Selecciona1.setForeground(new java.awt.Color(254, 254, 254));
        Selecciona1.setIcon(new ImageIcon("imagenes/update-user.png"));
        Selecciona1.setText("Seleccionar");
        Selecciona1.setToolTipText("Seleccionar un registro de la tabla para editar");
        Selecciona1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Selecciona1.setNextFocusableComponent(Eliminar1);
        Selecciona1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Selecciona1ActionPerformed(evt);
            }
        });

        bt_actualiza1.setBackground(new java.awt.Color(2, 135, 242));
        bt_actualiza1.setForeground(new java.awt.Color(254, 254, 254));
        bt_actualiza1.setIcon(new ImageIcon("imagenes/tabla.png"));
        bt_actualiza1.setText("Actualizar");
        bt_actualiza1.setToolTipText("Actualizar los datos de la tabla");
        bt_actualiza1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        bt_actualiza1.setMaximumSize(new java.awt.Dimension(87, 23));
        bt_actualiza1.setMinimumSize(new java.awt.Dimension(87, 23));
        bt_actualiza1.setNextFocusableComponent(Selecciona1);
        bt_actualiza1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_actualiza1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap(116, Short.MAX_VALUE)
                        .addComponent(bt_actualiza1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18).addComponent(Selecciona1).addGap(18, 18, 18)
                        .addComponent(Eliminar1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(Selecciona2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout
                                .createSequentialGroup().addContainerGap().addComponent(jScrollPane1,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                .addContainerGap())));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(Selecciona2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Eliminar1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Selecciona1).addComponent(bt_actualiza1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 340,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(40, Short.MAX_VALUE))));

        jPanel4.setBackground(new java.awt.Color(254, 254, 254));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Actualizar",
                javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 11))); // NOI18N

        jLabel8.setText("Ciclo:");

        t_ciclo.setNextFocusableComponent(t_descripcion);
        t_ciclo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_cicloActionPerformed(evt);
            }
        });
        t_ciclo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_cicloKeyTyped(evt);
            }
        });

        jLabel9.setText("Descripcin:");

        t_descripcion.setNextFocusableComponent(b_guardar);
        t_descripcion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_descripcionActionPerformed(evt);
            }
        });
        t_descripcion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_descripcionKeyTyped(evt);
            }
        });

        b_cancelar.setBackground(new java.awt.Color(2, 135, 242));
        b_cancelar.setForeground(new java.awt.Color(254, 254, 254));
        b_cancelar.setIcon(new ImageIcon("imagenes/cancelar.png"));
        b_cancelar.setText("Cancelar");
        b_cancelar.setEnabled(false);
        b_cancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_cancelar.setMaximumSize(new java.awt.Dimension(87, 23));
        b_cancelar.setMinimumSize(new java.awt.Dimension(87, 23));
        b_cancelar.setNextFocusableComponent(t_ciclo);
        b_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_cancelarActionPerformed(evt);
            }
        });

        b_guardar.setBackground(new java.awt.Color(2, 135, 242));
        b_guardar.setForeground(new java.awt.Color(254, 254, 254));
        b_guardar.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_guardar.setText("Actualizar");
        b_guardar.setEnabled(false);
        b_guardar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_guardar.setMaximumSize(new java.awt.Dimension(87, 23));
        b_guardar.setMinimumSize(new java.awt.Dimension(87, 23));
        b_guardar.setNextFocusableComponent(bt_actualiza1);
        b_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_guardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(b_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(b_guardar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                .addGroup(jPanel4Layout.createSequentialGroup().addGap(32, 32, 32)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel8).addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(t_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 270,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_ciclo, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(24, Short.MAX_VALUE)));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addGap(127, 127, 127)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(t_ciclo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(38, 38, 38)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(t_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(134, 134, 134)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(b_guardar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(b_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout
                .setHorizontalGroup(
                        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(44, 44, 44)
                                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(32, 32, 32)));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jPanel1,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jPanel1,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 996, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                        .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 491, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                        .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))));
    }// </editor-fold>//GEN-END:initComponents

    private void Selecciona2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Selecciona2ActionPerformed
        b_cancelar.requestFocus();
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getEditarCiclo() == true) {
            altaCiclo obj = new altaCiclo(new javax.swing.JFrame(), true, usr, sessionPrograma);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
            obj.setVisible(true);
            obj.t_ciclo.requestFocus();
            borra_cajas();
            cajas(false, false, false, false);
            buscaDato();
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Selecciona2ActionPerformed

    private void Eliminar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Eliminar1ActionPerformed
        Selecciona2.requestFocus();
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        /*if(usr.getEditaCiclo()==true)
        {*/
        if (this.t_datos.getSelectedRow() >= 0) {
            DefaultTableModel model = (DefaultTableModel) t_datos.getModel();
            int a = t_datos.getSelectedRow();
            int opt = JOptionPane.showConfirmDialog(this, "Los datos capturados se eliminarn!");
            if (JOptionPane.YES_OPTION == opt) {
                boolean respuesta = eliminar(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString());
                if (respuesta == true) {
                    JOptionPane.showMessageDialog(null, "El ciclo ha sido eliminado");
                    model.removeRow(a);
                    borra_cajas();
                    cajas(false, false, false, false);
                    buscaDato();
                }
            }
        } else
            cajas(false, false, false, false);
        /*}
        else
        JOptionPane.showMessageDialog(null, "Acceso denegado");*/
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Eliminar1ActionPerformed

    private void Selecciona1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Selecciona1ActionPerformed
        Eliminar1.requestFocus();
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getEditarCiclo() == true) {
            if (t_datos.getSelectedRow() >= 0) {
                this.borra_cajas();
                t_ciclo.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString());
                ic = t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString();
                t_descripcion.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString());
                this.cajas(true, true, true, true);
            } else
                JOptionPane.showMessageDialog(null, "No hay un ciclo seleccionado!");
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Selecciona1ActionPerformed

    private void bt_actualiza1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza1ActionPerformed
        Selecciona1.requestFocus();
        borra_cajas();
        cajas(false, false, false, false);
        buscaDato();
    }//GEN-LAST:event_bt_actualiza1ActionPerformed

    private void t_cicloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_cicloActionPerformed
        t_descripcion.requestFocus();
    }//GEN-LAST:event_t_cicloActionPerformed

    private void t_cicloKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_cicloKeyTyped
        char car = evt.getKeyChar();
        if (this.t_ciclo.getText().length() >= 2)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_t_cicloKeyTyped

    private void t_descripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_descripcionActionPerformed
        b_guardar.requestFocus();
    }//GEN-LAST:event_t_descripcionActionPerformed

    private void t_descripcionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_descripcionKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        char car = evt.getKeyChar();
        if (t_descripcion.getText().length() >= 200)
            evt.consume();
    }//GEN-LAST:event_t_descripcionKeyTyped

    private void b_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_cancelarActionPerformed
        t_ciclo.requestFocus();
        int opt = JOptionPane.showConfirmDialog(this, "Los datos capturados se eliminarn!");
        if (opt == 0) {
            borra_cajas();
            cajas(false, false, false, false);
            t_ciclo.requestFocus();
        }
    }//GEN-LAST:event_b_cancelarActionPerformed

    private void b_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_guardarActionPerformed
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        bt_actualiza1.requestFocus();
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getEditarCiclo() == true) {
            if (t_ciclo.getText().compareTo("") != 0) {
                boolean respuesta = modifica();
                if (respuesta == true) {
                    this.borra_cajas();
                    cajas(false, false, false, false);
                    buscaDato();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debe introducir el ciclo que desees modificar!");
                t_ciclo.requestFocus();
            }
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_b_guardarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Eliminar1;
    private javax.swing.JButton Selecciona1;
    private javax.swing.JButton Selecciona2;
    private javax.swing.JButton b_cancelar;
    private javax.swing.JButton b_guardar;
    private javax.swing.JButton bt_actualiza1;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    public javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextField t_ciclo;
    private javax.swing.JTable t_datos;
    public javax.swing.JTextField t_descripcion;
    // End of variables declaration//GEN-END:variables

    public void borra_cajas() {
        this.t_ciclo.setText("");
        this.t_descripcion.setText("");
    }

    public void cajas(boolean ciclo, boolean descripcion, boolean cancelar, boolean guardar) {
        this.t_ciclo.setEnabled(ciclo);
        this.t_descripcion.setEnabled(descripcion);
        this.b_cancelar.setEnabled(cancelar);
        this.b_guardar.setEnabled(guardar);
    }

    private List<Object[]> executeHQLQuery(String hql) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Query q = session.createQuery(hql);
            List resultList = q.list();
            session.getTransaction().commit();
            session.disconnect();
            return resultList;
        } catch (HibernateException he) {
            he.printStackTrace();
            List lista = null;
            return lista;
        }
    }

    private boolean eliminar(String idCiclo) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            actor = (Ciclo) session.get(Ciclo.class, Integer.parseInt(idCiclo));

            if (actor.getOrdens().isEmpty() == false) {
                session.getTransaction().rollback();
                JOptionPane.showMessageDialog(null, "El ciclo esta en uso en una orden no se puede eliminar!");
                return false;
            } else {
                session.delete(actor);
                session.getTransaction().commit();
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            session.getTransaction().rollback();
            return false;
        } finally {
            if (session.isOpen())
                session.close();
        }
    }

    private boolean modifica() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Object resp = session.createQuery(
                    "from Ciclo obj where obj.idCiclo='" + t_ciclo.getText() + "' and obj.idCiclo!='" + ic + "'")
                    .uniqueResult();

            actor = (Ciclo) session.get(Ciclo.class,
                    (Integer.parseInt(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString())));
            /*if(actor.getOrdens().isEmpty()==false) 
            {
            session.getTransaction().rollback();
            JOptionPane.showMessageDialog(null, "El Ciclo esta en uso en una orden no se puede modificar!");
            borra_cajas();
            return false;
            }
            else
            {*/
            if (resp == null) {
                Query q = session.createQuery("update Ciclo obj set obj.descripcion='" + t_descripcion.getText()
                        + "', obj.idCiclo='" + t_ciclo.getText() + "'where obj.idCiclo='" + ic + "'");
                q.executeUpdate();
                session.getTransaction().commit();
                JOptionPane.showMessageDialog(null, "Registro modificado");
                return true;
            } else {
                JOptionPane.showMessageDialog(null, "No se pueden guardar claves duplicadas");
                return false;
            }
            //}
        } catch (HibernateException he) {
            he.printStackTrace();
            System.out.println(he.hashCode());
            session.getTransaction().rollback();
            return false;
        } finally {
            if (session.isOpen())
                session.close();
        }
    }

    private void buscaDato() {
        String consulta = "from Ciclo";
        List<Object[]> resultList = executeHQLQuery(consulta);
        if (resultList.size() > 0) {
            t_datos.setModel(ModeloTablaReporte(resultList.size(), columnas));
            int i = 0;
            for (Object o : resultList) {
                actor = (Ciclo) o;
                model.setValueAt(actor.getIdCiclo(), i, 0);
                model.setValueAt(actor.getDescripcion(), i, 1);
                i++;
            }
        } else
            t_datos.setModel(ModeloTablaReporte(0, columnas));
        formatoTabla();
    }

public void formatoTabla()
{
    Color c1 = new java.awt.Color(2, 135, 242);   
    for(int x=0; x<t_datos.getColumnModel().getColumnCount(); x++)
        t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1(c1));
    tabla_tamaos();
    t_datos.setShowVerticalLines(true);
    t_datos.setShowHorizontalLines(true);
}

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    for (int i=0; i<t_datos.getColumnCount(); i++)
    {
       TableColumn column = col_model.getColumn(i);
          switch(i)
          {
              case 0:
                  column.setPreferredWidth(10);
                  break;
              case 1:
                  column.setPreferredWidth(150);
                  break;
              default:
                  column.setPreferredWidth(40);
                  break; 
          }
    }
    JTableHeader header = t_datos.getTableHeader();
    header.setForeground(Color.white);
}
}