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

/*
 * jfrmAñadirPaso.java
 *
 * Created on 26/11/2011, 05:27:45 PM
 */

package vista;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.CasodeUso;
import modelo.DocumentoReq;
import modelo.PasoCU;

/**
 *
 * @author Administrador
 */
public class jfrmPaso extends javax.swing.JFrame {
    DocumentoReq auxDocPpal;
    CasodeUso auxCU;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;
    
    /** Creates new form jfrmAñadirPaso */
    jfrmPaso(jfrmPrincipal jf, CasodeUso CU, MutableTreeNode insertNode, int insertIndex, DocumentoReq DocPpal) {
        initComponents();
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxCU=CU;
        auxDocPpal=DocPpal;
        
    }
    
    

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

        jTabPaso = new javax.swing.JTabbedPane();
        jpanCondicion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jchbesCondicional = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaCondicion = new javax.swing.JTextArea();
        jpanAccion = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jradSistema = new javax.swing.JRadioButton();
        jradActor = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaAccion = new javax.swing.JTextArea();
        jcomActor = new javax.swing.JComboBox();
        jbtnAceptar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Añadir Paso");
        setResizable(false);

        jLabel1.setText("Tipo de paso:");

        jchbesCondicional.setText("Este paso es condicional.");
        jchbesCondicional.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchbesCondicionalActionPerformed(evt);
            }
        });

        jLabel2.setText("Condición:");

        jtxaCondicion.setColumns(20);
        jtxaCondicion.setRows(5);
        jScrollPane1.setViewportView(jtxaCondicion);

        javax.swing.GroupLayout jpanCondicionLayout = new javax.swing.GroupLayout(jpanCondicion);
        jpanCondicion.setLayout(jpanCondicionLayout);
        jpanCondicionLayout.setHorizontalGroup(
            jpanCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanCondicionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jchbesCondicional)
                    .addComponent(jLabel1))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jpanCondicionLayout.setVerticalGroup(
            jpanCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanCondicionLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jchbesCondicional)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jTabPaso.addTab("Condicion", jpanCondicion);

        jLabel3.setText("Tipo de Accion:");

        jradSistema.setText("Accion del Sistema.");
        jradSistema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jradSistemaActionPerformed(evt);
            }
        });

        jradActor.setText("Accion de un Actor.");

        jLabel4.setText("Accion realizada por el sistema/el actor:");

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

        jcomActor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Actor 1", "Actor 2", "Actor 3", "Actor 4" }));
        jcomActor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcomActorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpanAccionLayout = new javax.swing.GroupLayout(jpanAccion);
        jpanAccion.setLayout(jpanAccionLayout);
        jpanAccionLayout.setHorizontalGroup(
            jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanAccionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanAccionLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addContainerGap(276, Short.MAX_VALUE))
                    .addGroup(jpanAccionLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpanAccionLayout.createSequentialGroup()
                                .addComponent(jradSistema)
                                .addContainerGap())
                            .addGroup(jpanAccionLayout.createSequentialGroup()
                                .addComponent(jradActor)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                                .addComponent(jcomActor, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(34, 34, 34))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanAccionLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(162, 162, 162))
                    .addGroup(jpanAccionLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jpanAccionLayout.setVerticalGroup(
            jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanAccionLayout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jradSistema)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jradActor)
                    .addComponent(jcomActor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabPaso.addTab("Accion", jpanAccion);

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

        jbtnCancelar.setText("Cancelar");
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(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()
                .addGap(119, 119, 119)
                .addComponent(jbtnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnCancelar)
                .addGap(113, 113, 113))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabPaso, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jTabPaso, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAceptar)
                    .addComponent(jbtnCancelar)))
        );

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

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

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        PasoCU newPaso=auxCU.nuevoPaso(jchbesCondicional.isSelected(), jtxaCondicion.getText(), jradSistema.isSelected(), jradActor.isSelected(), jtxaAccion.getText());
        MutableTreeNode node=new DefaultMutableTreeNode("[PAS]-"+ newPaso.getNumero_id()+" Paso");
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        jfaux.getJtreDocumento().setCellRenderer(new RendererArbol());
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        mostrarmensaje("Insertado el Paso correctamente");
        auxDocPpal.actualizar();
        jfaux.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnAceptarActionPerformed

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        jfaux.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarActionPerformed

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

    private void mostrarmensaje(String mensaje) {
         JOptionPane.showMessageDialog(this, mensaje, "Información",
                                JOptionPane.INFORMATION_MESSAGE);
    }
    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new jfrmAñadirPaso().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabPaso;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JCheckBox jchbesCondicional;
    private javax.swing.JComboBox jcomActor;
    private javax.swing.JPanel jpanAccion;
    private javax.swing.JPanel jpanCondicion;
    private javax.swing.JRadioButton jradActor;
    private javax.swing.JRadioButton jradSistema;
    private javax.swing.JTextArea jtxaAccion;
    private javax.swing.JTextArea jtxaCondicion;
    // End of variables declaration//GEN-END:variables

}
