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

/*
 * jfrmAñadirExcepcion.java
 *
 * Created on 26/11/2011, 06:04:54 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.DocumentoReq;
import modelo.ExcepcionCU;
import modelo.PasoCU;

/**
 *
 * @author Administrador
 */
public class jfrmExcepcion extends javax.swing.JFrame {
    PasoCU auxPaso;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;
    /** Creates new form jfrmAñadirExcepcion */
    
    jfrmExcepcion(jfrmPrincipal jf, PasoCU Paso, MutableTreeNode insertNode, int insertIndex) {
        initComponents();
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxPaso=Paso;
    }

    private void mostrarmensaje(String mensaje) {
         JOptionPane.showMessageDialog(this, mensaje, "Información",
                                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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

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

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);

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

        jradSistema.setText("Accion del Sistema.");

        jradActor.setText("Accion de un Actor.");
        jradActor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jradActorActionPerformed(evt);
            }
        });

        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);
            }
        });

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

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

        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)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addGroup(jpanAccionLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpanAccionLayout.createSequentialGroup()
                                .addComponent(jradActor)
                                .addGap(18, 18, 18)
                                .addComponent(jcomActor, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jradSistema)))
                    .addComponent(jLabel4))
                .addContainerGap())
        );
        jpanAccionLayout.setVerticalGroup(
            jpanAccionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanAccionLayout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .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.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Accion", jpanAccion);

        jLabel1.setText("Condicion de la Excepcion:");

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

        jLabel2.setText("Terminacion de la Excepcion:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "continúa", "queda sin efecto" }));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jtxaAccion, org.jdesktop.beansbinding.ObjectProperty.create(), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        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(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox1, 0, 380, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpanCondicionLayout.setVerticalGroup(
            jpanCondicionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanCondicionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                .addGap(23, 23, 23)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(58, 58, 58))
        );

        jTabbedPane1.addTab("Condicion/Terminacion", jpanCondicion);

        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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(jbtnAceptar)
                        .addGap(44, 44, 44)
                        .addComponent(jbtnCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAceptar)
                    .addComponent(jbtnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

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

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

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        ExcepcionCU newExcepcion= auxPaso.nuevoExcepcion(jtxaAccion.getText(), jtxaCondicionEx.getText(), jradSistema.isSelected(), jradActor.isSelected());
        MutableTreeNode node=new DefaultMutableTreeNode("[EXC]-"+ newExcepcion.getNumero_id()+" Excepcion");
        DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        jfaux.getJtreDocumento().setCellRenderer(new RendererArbol());
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        mostrarmensaje("Insertada la Excepcion correctamente");
        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 jradActorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jradActorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jradActorActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox1;
    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 jTabbedPane1;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    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 jtxaCondicionEx;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
