/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jfrmCasodeUso.java
 *
 * Created on 22-nov-2011, 17:05:03
 */

package vista;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.*;


/**
 *
 * @author acc_local
 */
public class jfrmParticipantes extends javax.swing.JFrame {
    DocumentoReq auxDocPpal;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;
    Participante auxParticipantes;

    /** Creates new form jfrmCasodeUso */
    public jfrmParticipantes(jfrmPrincipal jf, DocumentoReq docPpal, MutableTreeNode insertNode, int insertIndex) {
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxDocPpal=docPpal;

        SimpleDateFormat sdf = new SimpleDateFormat("dd - MM - yyyy");
        Calendar cal = Calendar.getInstance(); // hoy
        //System.out.println("Hoy es " + sdf.format(cal.getTime()));

        initComponents();
    }

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

        jTabParticipantes = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtNombreParticipante = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jDateParti = new com.toedter.calendar.JDateChooser();
        jpanDetalle = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jtxtRol = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jchbesCliente = new javax.swing.JCheckBox();
        jchbesDesarrollador = new javax.swing.JCheckBox();
        jchbesUsuario = new javax.swing.JCheckBox();
        jtxtOrganizacion = new javax.swing.JTextField();
        jpanComentarios = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jtxtComentarios = new javax.swing.JTextField();
        jbtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Nombre:");

        jtxtNombreParticipante.setText("Nuevo participante");
        jtxtNombreParticipante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtNombreParticipanteActionPerformed(evt);
            }
        });

        jLabel11.setText("Fecha");

        javax.swing.GroupLayout jpanGeneralLayout = new javax.swing.GroupLayout(jpanGeneral);
        jpanGeneral.setLayout(jpanGeneralLayout);
        jpanGeneralLayout.setHorizontalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jDateParti, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtNombreParticipante, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(64, 64, 64))
        );
        jpanGeneralLayout.setVerticalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtNombreParticipante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jDateParti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addContainerGap(163, Short.MAX_VALUE))
        );

        jTabParticipantes.addTab("General", jpanGeneral);

        jLabel5.setText("Rol");

        jLabel6.setText("Organizacion");

        jtxtRol.setText("PD");
        jtxtRol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtRolActionPerformed(evt);
            }
        });

        jLabel2.setText("Tipo Participante");

        jchbesCliente.setText("El participante es un cliente");
        jchbesCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchbesClienteActionPerformed(evt);
            }
        });

        jchbesDesarrollador.setText("El participante es un desarrolador");
        jchbesDesarrollador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchbesDesarrolladorActionPerformed(evt);
            }
        });

        jchbesUsuario.setText("El participante es un usuario");

        jtxtOrganizacion.setText("PD");
        jtxtOrganizacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtOrganizacionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpanDetalleLayout = new javax.swing.GroupLayout(jpanDetalle);
        jpanDetalle.setLayout(jpanDetalleLayout);
        jpanDetalleLayout.setHorizontalGroup(
            jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetalleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jtxtRol, javax.swing.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .addComponent(jLabel6)
                    .addGroup(jpanDetalleLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jchbesDesarrollador)
                            .addComponent(jchbesCliente)
                            .addComponent(jchbesUsuario)))
                    .addComponent(jtxtOrganizacion))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jpanDetalleLayout.setVerticalGroup(
            jpanDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDetalleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtxtRol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtxtOrganizacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jchbesCliente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jchbesDesarrollador)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jchbesUsuario)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jTabParticipantes.addTab("Detalle", jpanDetalle);

        jLabel7.setText("Importancia:");

        jtxtComentarios.setText("PD");

        javax.swing.GroupLayout jpanComentariosLayout = new javax.swing.GroupLayout(jpanComentarios);
        jpanComentarios.setLayout(jpanComentariosLayout);
        jpanComentariosLayout.setHorizontalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtComentarios, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jLabel7))
                .addContainerGap())
        );
        jpanComentariosLayout.setVerticalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtxtComentarios, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabParticipantes.addTab("Comentarios", jpanComentarios);

        jbtnAceptar.setText("Aceptar");
        jbtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(jbtnAceptar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabParticipantes, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .addComponent(jTabParticipantes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnAceptar)
                .addContainerGap())
        );

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        MutableTreeNode node=new DefaultMutableTreeNode("Participantes "+jtxtNombreParticipante.getText());
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        Participante nuevoPA= auxDocPpal.nuevoPA(jDateParti.getDate(),jtxtNombreParticipante.getText(),jtxtRol.getText(),jtxtOrganizacion.getText(),jchbesCliente.isSelected(),jchbesUsuario.isSelected(),jtxtComentarios.getText(),jchbesDesarrollador.isSelected());

        //mostrarmensaje("Insertado el CU "+newCU.getNombre());
        //this.setEnabled(false);
        jfaux.setEnabled(true);
        this.dispose();

    }//GEN-LAST:event_jbtnAceptarActionPerformed

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

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

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

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

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

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new jfrmCasodeUso().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser jDateParti;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTabbedPane jTabParticipantes;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JCheckBox jchbesCliente;
    private javax.swing.JCheckBox jchbesDesarrollador;
    private javax.swing.JCheckBox jchbesUsuario;
    private javax.swing.JPanel jpanComentarios;
    private javax.swing.JPanel jpanDetalle;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JTextField jtxtComentarios;
    private javax.swing.JTextField jtxtNombreParticipante;
    private javax.swing.JTextField jtxtOrganizacion;
    private javax.swing.JTextField jtxtRol;
    // End of variables declaration//GEN-END:variables


    private void mostrarmensaje(String mensaje) {
         JOptionPane.showMessageDialog(this, mensaje, "Advertencia",
                                JOptionPane.WARNING_MESSAGE);
    }
}
