Java tutorial
/* * 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.dialogos; import com.personal.utiles.FormularioUtil; import com.biosis.biosislite.controladores.AreaEmpleadoControlador; import com.biosis.biosislite.controladores.ContratoControlador; import com.biosis.biosislite.entidades.escalafon.AreaEmpleado; import com.biosis.biosislite.entidades.escalafon.Contrato; import com.biosis.biosislite.entidades.escalafon.Empleado; import java.util.Date; import java.util.List; import javax.swing.JDialog; import javax.swing.JInternalFrame; import javax.swing.JOptionPane; import org.apache.commons.beanutils.BeanUtils; /** * * @author fesquivelc */ public class DlgDatosEmpleado extends javax.swing.JDialog { /** * Creates new form DlgDatosEmpleado */ private Empleado empleado; public Empleado getEmpleado() { return empleado; } public void setEmpleado(Empleado empleado) { this.empleado = empleado; actualizarControles(); } public DlgDatosEmpleado(JInternalFrame parent, boolean modal) { super(JOptionPane.getFrameForComponent(parent), modal); initComponents(); this.setLocationRelativeTo(parent); FormularioUtil.activarComponente(dtFechaNacimiento, false); FormularioUtil.activarComponente(dtFechaContrato, false); dtFechaNacimiento.getCalendarButton().setVisible(false); dtFechaContrato.getCalendarButton().setVisible(false); dtFechaNacimiento.setDate(new Date()); } public DlgDatosEmpleado(JDialog parent, boolean modal) { super(JOptionPane.getFrameForComponent(parent), modal); initComponents(); this.setLocationRelativeTo(parent); FormularioUtil.activarComponente(dtFechaNacimiento, false); FormularioUtil.activarComponente(dtFechaContrato, false); dtFechaNacimiento.getCalendarButton().setVisible(false); dtFechaContrato.getCalendarButton().setVisible(false); dtFechaNacimiento.setDate(new Date()); } /** * 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; jPanel2 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); txtTipoDoc = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txtNroDoc = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); txtApellidoMaterno = new javax.swing.JTextField(); txtApellidoPaterno = new javax.swing.JTextField(); txtNombre = new javax.swing.JTextField(); dtFechaNacimiento = new com.toedter.calendar.JDateChooser(); jPanel4 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jLabel11 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); txtArea = new javax.swing.JTextField(); txtRegimenLaboral = new javax.swing.JTextField(); dtFechaContrato = new com.toedter.calendar.JDateChooser(); jLabel14 = new javax.swing.JLabel(); txtCodigoModular = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Datos del empleado"); getContentPane().setLayout(new java.awt.GridBagLayout()); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos generales")); jPanel1.setLayout(new java.awt.GridBagLayout()); jLabel1.setText("Tipo de doc.:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel1, gridBagConstraints); txtTipoDoc.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(txtTipoDoc, gridBagConstraints); jLabel2.setText("Nmero de doc.:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel2, gridBagConstraints); txtNroDoc.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(txtNroDoc, gridBagConstraints); jLabel3.setText("Apellido paterno:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel3, gridBagConstraints); jLabel4.setText("Apellido materno:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel4, gridBagConstraints); jLabel5.setText("Nombre:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel5, gridBagConstraints); jLabel6.setText("Fecha de nac.:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(jLabel6, gridBagConstraints); txtApellidoMaterno.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(txtApellidoMaterno, gridBagConstraints); txtApellidoPaterno.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(txtApellidoPaterno, gridBagConstraints); txtNombre.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(txtNombre, gridBagConstraints); dtFechaNacimiento.setDateFormatString("dd-MM-yyyy"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); jPanel1.add(dtFechaNacimiento, gridBagConstraints); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(81, Short.MAX_VALUE))); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 223; gridBagConstraints.ipady = 70; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(jPanel2, gridBagConstraints); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos laborales")); java.awt.GridBagLayout jPanel3Layout = new java.awt.GridBagLayout(); jPanel3Layout.columnWidths = new int[] { 0, 8, 0 }; jPanel3Layout.rowHeights = new int[] { 0, 8, 0, 8, 0, 8, 0 }; jPanel3.setLayout(jPanel3Layout); jLabel11.setText("Rgimen laboral:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; jPanel3.add(jLabel11, gridBagConstraints); jLabel10.setText("?rea / Oficina / Departamento:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; jPanel3.add(jLabel10, gridBagConstraints); jLabel12.setText("Fecha de inicio de contrato:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; jPanel3.add(jLabel12, gridBagConstraints); txtArea.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; jPanel3.add(txtArea, gridBagConstraints); txtRegimenLaboral.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; jPanel3.add(txtRegimenLaboral, gridBagConstraints); dtFechaContrato.setDateFormatString("dd-MM-yyyy"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 0.1; jPanel3.add(dtFechaContrato, gridBagConstraints); jLabel14.setText("Cdigo modular:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; jPanel3.add(jLabel14, gridBagConstraints); txtCodigoModular.setEditable(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 6; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; jPanel3.add(txtCodigoModular, gridBagConstraints); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout .setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE) .addContainerGap())); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap() .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 353; gridBagConstraints.ipady = 134; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); getContentPane().add(jPanel4, gridBagConstraints); pack(); }// </editor-fold>//GEN-END:initComponents /** * @param args the command line arguments */ // Variables declaration - do not modify//GEN-BEGIN:variables private com.toedter.calendar.JDateChooser dtFechaContrato; private com.toedter.calendar.JDateChooser dtFechaNacimiento; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel14; 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.JPanel jPanel4; private javax.swing.JTextField txtApellidoMaterno; private javax.swing.JTextField txtApellidoPaterno; private javax.swing.JTextField txtArea; private javax.swing.JTextField txtCodigoModular; private javax.swing.JTextField txtNombre; private javax.swing.JTextField txtNroDoc; private javax.swing.JTextField txtRegimenLaboral; private javax.swing.JTextField txtTipoDoc; // End of variables declaration//GEN-END:variables ContratoControlador cc = ContratoControlador.getInstance(); AreaEmpleadoControlador ae = new AreaEmpleadoControlador(); private void actualizarControles() { txtNroDoc.setText(empleado.getNroDocumento()); txtTipoDoc.setText(empleado.getTipoDocumento().getNombre()); txtApellidoPaterno.setText(empleado.getPaterno()); txtApellidoMaterno.setText(empleado.getMaterno()); txtNombre.setText(empleado.getNombre()); dtFechaNacimiento.setDate(empleado.getFechaNacimiento()); Contrato contratoVigente = new Contrato(); List<Contrato> contratos = cc.buscarXNombrexFechaASC(empleado); if (!contratos.isEmpty()) { contratoVigente = contratos.get(0); dtFechaContrato.setDate(contratos.get(0).getFechaInicio()); } txtRegimenLaboral.setText( contratoVigente.getRegimenLaboral() == null ? "" : contratoVigente.getRegimenLaboral().getNombre()); txtCodigoModular.setText(empleado.getFichaLaboral().getCodigoTrabajador()); AreaEmpleado areaVigente = new AreaEmpleado(); List<AreaEmpleado> areas = ae.buscarXNombrexFechaASC(empleado); if (!areas.isEmpty()) { areaVigente = areas.get(0); } txtArea.setText(areaVigente.getDepartamento() == null ? "" : areaVigente.getDepartamento().getNombre()); } }