/* * TemplatesDialog.java * * Created on 19 de mayo de 2010, 01:28 PM */ package gafetes; import javax.swing.*; import gafetes.beans.Template; import gafetes.model.TemplateModel; /** * * @author gateway */ public class TemplatesDialog extends javax.swing.JDialog { /** Creates new form TemplatesDialog */ public TemplatesDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); initWithoutNetbeans(); } private void initWithoutNetbeans(){ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); //Especificamos un modelo de tipo Empleado para posteriormente llenarlo mediante una consulta table.setModel(new TemplateModel()); table.getSelectionModel().setSelectionMode( table.getSelectionModel().SINGLE_SELECTION); bindForm(); } private void bindForm(){ gafetes.model.TemplateModel im=null; try{ boolean showTemplate = false; //Realizamos la busqueda del empleado por medio del campo especificado im = gafetes.business.SqlHelper.getAllTemplates(1); }catch(java.lang.NumberFormatException nfe ){ javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "El identificador debe ser num�rico", "Aviso", javax.swing.JOptionPane.INFORMATION_MESSAGE); } if( im != null ){ table.setModel(im); if(im.getRowCount() > 0){ table.getColumnModel().getColumn( 0 ).setPreferredWidth( 70 ); table.getColumnModel().getColumn( 1 ).setPreferredWidth( 150); table.getColumnModel().getColumn( 2 ).setPreferredWidth( 150); table.changeSelection(0, table.getModel().getColumnCount()-1, false, false); table.changeSelection(0, 0, false, false); //table.requestFocus(); table.requestFocus(); table.getSelectionModel().setLeadSelectionIndex(0); }else{ javax.swing.JOptionPane.showMessageDialog( Application.getparentFrame(), "La busqueda no devolvi� resultados con los par�metros especificados", "Mensaje de la Aplicaci�n", javax.swing.JOptionPane.INFORMATION_MESSAGE); } } } /** 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. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); EditButton = new javax.swing.JButton(); deleteButton = new javax.swing.JButton(); newButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); closeButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); getContentPane().add(jPanel2, java.awt.BorderLayout.EAST); getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH); getContentPane().add(jPanel4, java.awt.BorderLayout.WEST); jPanel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); EditButton.setBackground(new java.awt.Color(236, 227, 211)); EditButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/Edit24.gif"))); EditButton.setText("Modificar"); EditButton.setToolTipText("Modificar Datos"); EditButton.setBorder(null); EditButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { EditButtonActionPerformed(evt); } }); deleteButton.setBackground(new java.awt.Color(236, 227, 211)); deleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/basura.gif"))); deleteButton.setText("Eliminar"); deleteButton.setBorder(null); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(evt); } }); newButton.setBackground(new java.awt.Color(236, 227, 211)); newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/new24.gif"))); newButton.setText("Nuevo"); newButton.setToolTipText("Modificar Datos"); newButton.setBorder(null); newButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newButtonActionPerformed(evt); } }); jScrollPane1.setBackground(new java.awt.Color(244, 244, 240)); table.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" } )); table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tableMouseClicked(evt); } }); table.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { tableKeyPressed(evt); } public void keyTyped(java.awt.event.KeyEvent evt) { tableKeyTyped(evt); } }); jScrollPane1.setViewportView(table); closeButton.setBackground(new java.awt.Color(236, 227, 211)); closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/salir.gif"))); closeButton.setText("Cerrar"); closeButton.setBorder(null); closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout.setHorizontalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE) .addGroup(jPanel5Layout.createSequentialGroup() .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(24, 24, 24) .addComponent(EditButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(15, 15, 15) .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); jPanel5Layout.setVerticalGroup( jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup() .addGap(32, 32, 32) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(newButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(EditButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE) .addContainerGap()) ); getContentPane().add(jPanel5, java.awt.BorderLayout.CENTER); pack(); }// </editor-fold>//GEN-END:initComponents private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed // TODO add your handling code here: dispose(); }//GEN-LAST:event_closeButtonActionPerformed private void tableKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyTyped // TODO add your handling code here: }//GEN-LAST:event_tableKeyTyped private void tableKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyPressed // TODO add your handling code here: }//GEN-LAST:event_tableKeyPressed private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked // TODO add your handling code here: }//GEN-LAST:event_tableMouseClicked private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed // TODO add your handling code here: gafetes.beans.Template e = new gafetes.beans.Template(); int row = table.getSelectedRow(); if(row<0){ javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro"); table.requestFocus(); } e = ( (Template) table.getModel().getValueAt(row,1) ); gafetes.EditTemplateDialog ef = new EditTemplateDialog(Application.getparentFrame(),false); ef.setTitle("Crear nueva plantilla."); //ef.setEditMode(e); ef.setModal(true); gafetes.util.Misc.centerFrame(ef); ef.setVisible(true); bindForm(); }//GEN-LAST:event_newButtonActionPerformed private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed // TODO add your handling code here: //Eliminacion de registro int confirm = javax.swing.JOptionPane.showOptionDialog( Application.getparentFrame(), "�Desea eliminar el registro?", "Confirmaci�n", javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE, null,null,null); if ( confirm == 0 ) { gafetes.beans.Template e = new gafetes.beans.Template(); int row = table.getSelectedRow(); if(row<0){ javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro"); table.requestFocus(); } e = ( (Template) table.getModel().getValueAt(row,1) ); if(gafetes.business.SqlHelper.deleteTemplate(e) == 1) bindForm(); else javax.swing.JOptionPane.showMessageDialog(Application.getparentFrame(),"Ocurri� un error al intentar borrar el registro. Verifique que la plantilla no este asociada a un empleado"); } // findAction(); }//GEN-LAST:event_deleteButtonActionPerformed private void EditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditButtonActionPerformed // TODO add your handling code here: gafetes.beans.Template e = new gafetes.beans.Template(); int row = table.getSelectedRow(); if(row < 0 ){ javax.swing.JOptionPane.showMessageDialog(new JFrame(),"Selecccione un registro"); table.requestFocus(); return; } e = ( (Template) table.getModel().getValueAt(row,1) ); gafetes.EditTemplateDialog ef = new EditTemplateDialog(Application.getparentFrame(),false); ef.setTitle("Modificaci�n de datos de la plantilla"); ef.setEditMode(e); ef.setModal(true); gafetes.util.Misc.centerFrame(ef); ef.setVisible(true); bindForm(); }//GEN-LAST:event_EditButtonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TemplatesDialog(new javax.swing.JFrame(), true).setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton EditButton; private javax.swing.JButton closeButton; private javax.swing.JButton deleteButton; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton newButton; private javax.swing.JTable table; // End of variables declaration//GEN-END:variables }