/*
 *      Luis Israel Diéguez Arjona
 *      Sonia Cejas Soria
 *      Sergio Cabello García
 *      María José González Cordero
 *
 *      Ingeniería del Software de Gestión II
 *      Ingeniería Técnica Informática de Gestión
 *      Universidad de Huelva
 */

package vista;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.*;





public class jfCasoUso_Excepcion extends javax.swing.JFrame implements Observer {
    // Formulario padre
    jfHome home;
    boolean modificado = false;
    // Control del identificador
    String identCasoUsoPadre;
    String identPasoPadre;
    String identExcepcion;
    // Control del Update de Observers
    int contadorEjecuciones = 0;
    // JTree
    MutableTreeNode currentNode;
    MutableTreeNode insertNode;
    int insertIndex;
    // Control del Update de Observers
    private Excepcion excepcion;
    private int vecesActualizo;





    public jfCasoUso_Excepcion() {
        initComponents();
        this.buttonGroup.add(jRadioButton_accionSistema);
        this.buttonGroup.add(jRadioButton_accionActor);
        this.buttonGroup.add(jRadioButton_inclusionExtension);
        jRadioButton_accionSistema.setSelected(true);
    }
    public jfCasoUso_Excepcion(jfHome home, String identCasoUsoPadre, String identPasoPadre) {
        // Inicializo
        initComponents();
        this.buttonGroup.add(jRadioButton_accionSistema);
        this.buttonGroup.add(jRadioButton_accionActor);
        this.buttonGroup.add(jRadioButton_inclusionExtension);
        jRadioButton_accionSistema.setSelected(true);
        this.home = home;
        this.insertNode = home.getInsertNode();
        this.insertIndex = home.getInsertIndex(insertNode);
        this.identCasoUsoPadre = identCasoUsoPadre;
        this.identPasoPadre = identPasoPadre;

        // ComboBox de actores
        ArrayList<Actor> actores = home.documentoRequisitos.getActores();
        for (int i = 0; i < actores.size(); i++) {
            jComboBox_accionActor.addItem(actores.get(i).getNombre() + " [" + actores.get(i).getIdentificacion() + "]");
        }

        // ComboBox de inclusión/exclusión
        ArrayList<CasoUso> casosUso = home.documentoRequisitos.getCasosUso();
        for (int i = 0; i < casosUso.size(); i++) {
            jComboBox_inclusionExtension.addItem(casosUso.get(i).getNombre() + " [" + casosUso.get(i).getIdentificacion() + "]");
        }

        // Configura el identificador
        identExcepcion = this.home.documentoRequisitos.getNuevoIdentificadorExcepcion (this.identCasoUsoPadre, this.identPasoPadre);

        vecesActualizo = 0;
    }
    public void inicializarModificacion(Excepcion excepcion) {
        modificado = true;
        identExcepcion = excepcion.getIdentificacion();
        
        // Pestaña "Condición/Terminación"
        jTextArea_condicion.setText(excepcion.getCondicion());
        jComboBox_terminacion.setSelectedItem(excepcion.getTerminacion());

        // Pestaña "Acción"
        if (excepcion.getAccionSistema())
            jRadioButton_accionSistema.setSelected(true);
        else if (excepcion.getAccionActor())
            jRadioButton_accionActor.setSelected(true);
        else if (excepcion.getInclusionExtension())
            jRadioButton_inclusionExtension.setSelected(true);
        if (excepcion.getActor() == null)
            jComboBox_accionActor.setSelectedItem("");
        else
            jComboBox_accionActor.setSelectedItem(excepcion.getActor());
        if (excepcion.getCasoUso() == null)
            jComboBox_inclusionExtension.setSelectedItem("");
        else
            jComboBox_inclusionExtension.setSelectedItem(excepcion.getCasoUso());
        jTextArea_acciones.setText(excepcion.getDescripcionAccion());
        jTextField_frecuencia.setText(Integer.toString(excepcion.getValorRendimiento()));
        jComboBox_frecuencia.setSelectedItem(excepcion.getUnidadRendimiento());

        // Pestaña "Comentario"
        jTextArea_comentarios.setText(excepcion.getComentario());
    }





    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea_condicion = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jComboBox_terminacion = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jRadioButton_accionSistema = new javax.swing.JRadioButton();
        jRadioButton_accionActor = new javax.swing.JRadioButton();
        jRadioButton_inclusionExtension = new javax.swing.JRadioButton();
        jComboBox_accionActor = new javax.swing.JComboBox();
        jComboBox_inclusionExtension = new javax.swing.JComboBox();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea_acciones = new javax.swing.JTextArea();
        jPanel9 = new javax.swing.JPanel();
        jTextField_frecuencia = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jComboBox_frecuencia = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_comentarios = new javax.swing.JTextArea();
        jButton_aceptar = new javax.swing.JButton();
        jButton_cancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Excepción");
        setAlwaysOnTop(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Condición de la excepción"));

        jTextArea_condicion.setColumns(20);
        jTextArea_condicion.setLineWrap(true);
        jTextArea_condicion.setRows(5);
        jScrollPane1.setViewportView(jTextArea_condicion);

        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()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Terminación de la excepción"));
        jPanel4.setPreferredSize(new java.awt.Dimension(207, 54));

        jComboBox_terminacion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Continúa", "Queda sin efecto" }));

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        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(jComboBox_terminacion, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(162, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jComboBox_terminacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Condición / Terminación", jPanel1);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de acción"));

        jRadioButton_accionSistema.setText("Acción del sistema");
        jRadioButton_accionSistema.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButton_accionSistemaItemStateChanged(evt);
            }
        });

        jRadioButton_accionActor.setText("Acción de un actor");
        jRadioButton_accionActor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButton_accionActorItemStateChanged(evt);
            }
        });

        jRadioButton_inclusionExtension.setText("Inclusión / extensión");
        jRadioButton_inclusionExtension.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRadioButton_inclusionExtensionItemStateChanged(evt);
            }
        });

        jComboBox_accionActor.setPreferredSize(new java.awt.Dimension(215, 20));

        jComboBox_inclusionExtension.setPreferredSize(new java.awt.Dimension(215, 20));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton_accionSistema)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jRadioButton_accionActor, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton_inclusionExtension, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jComboBox_accionActor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox_inclusionExtension, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(76, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jComboBox_accionActor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox_inclusionExtension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jRadioButton_accionSistema)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton_accionActor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton_inclusionExtension)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Acciones realizadas por el sistema / un actor"));

        jTextArea_acciones.setColumns(20);
        jTextArea_acciones.setLineWrap(true);
        jScrollPane3.setViewportView(jTextArea_acciones);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Rendimiento"));
        jPanel9.setPreferredSize(new java.awt.Dimension(209, 54));

        jTextField_frecuencia.setPreferredSize(new java.awt.Dimension(30, 20));

        jLabel6.setText("veces al");

        jComboBox_frecuencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "año", "mes", "semana", "día", "hora", "minuto", "segundo" }));
        jComboBox_frecuencia.setPreferredSize(new java.awt.Dimension(100, 20));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField_frecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox_frecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField_frecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBox_frecuencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        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()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Acción", jPanel2);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Comentarios"));

        jTextArea_comentarios.setColumns(20);
        jTextArea_comentarios.setLineWrap(true);
        jTextArea_comentarios.setRows(5);
        jScrollPane2.setViewportView(jTextArea_comentarios);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Comentarios", jPanel3);

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

        jButton_cancelar.setText("Cancelar");
        jButton_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_cancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton_aceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton_cancelar)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_cancelar)
                    .addComponent(jButton_aceptar))
                .addContainerGap())
        );

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

    private void jButton_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_cancelarActionPerformed
        home.setEnabled(true);
        this.dispose();
}//GEN-LAST:event_jButton_cancelarActionPerformed
    private void jButton_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_aceptarActionPerformed
        Paso p = home.documentoRequisitos.getPaso(identCasoUsoPadre, identPasoPadre);
        excepcion = new Excepcion(p);
        boolean puedoCerrar = true;

        // Creo la excepción
        excepcion.setIdentificacion(identExcepcion);
        excepcion.setCondicion(jTextArea_condicion.getText());
        excepcion.setTerminacion(jComboBox_terminacion.getSelectedItem().toString());
        excepcion.setAccionSistema(jRadioButton_accionSistema.isSelected());
        excepcion.setAccionActor(jRadioButton_accionActor.isSelected());
        excepcion.setInclusionExtension(jRadioButton_inclusionExtension.isSelected());
        if (jComboBox_accionActor.getSelectedItem() != null)
            excepcion.setActor(jComboBox_accionActor.getSelectedItem().toString());
        if (jComboBox_inclusionExtension.getSelectedItem() != null)
            excepcion.setCasoUso(jComboBox_inclusionExtension.getSelectedItem().toString());
        excepcion.setDescripcionAccion(jTextArea_acciones.getText());
        if (!this.jTextField_frecuencia.getText().equals(""))
            excepcion.setValorRendimiento(Integer.parseInt(this.jTextField_frecuencia.getText()));
        excepcion.setUnidadRendimiento((String) jComboBox_frecuencia.getSelectedItem());    //Duda de que se haga asi.
        excepcion.setComentario(jTextArea_comentarios.getText());

        // Nombre
        excepcion.setNombre("Si ");
        if (jTextArea_condicion.getText().length() != 0) {
            excepcion.setNombre(excepcion.getNombre() + this.jTextArea_condicion.getText());
        }
        excepcion.setNombre(excepcion.getNombre() + ", ");

        if (jRadioButton_accionSistema.isSelected() == true){
            excepcion.setNombre(excepcion.getNombre() + "el sistema "
                    + this.jTextArea_acciones.getText()
                    + ". A continuación este Caso de uso "
                    + this.jComboBox_terminacion.getSelectedItem().toString());
        }
        else if (jRadioButton_accionActor.isSelected() == true){
            if (jComboBox_accionActor.getSelectedIndex() != -1){
                String nom = jComboBox_accionActor.getSelectedItem().toString().substring(0,jComboBox_accionActor.getSelectedItem().toString().length()-11);
                excepcion.setNombre(excepcion.getNombre() + "el actor "
                        + nom + this.jTextArea_acciones.getText() + " " );
            }
            else{ 
                jRadioButton_accionSistema.setSelected(true);
                JOptionPane.showMessageDialog(this, "No existe ningún actor, por favor, seleccione otra opción.", "Advertencia",JOptionPane.WARNING_MESSAGE);
                jTextArea_acciones.setText("");
                puedoCerrar = false;
            }
        }

        else if (jRadioButton_inclusionExtension.isSelected() == true){
            String nom = jComboBox_inclusionExtension.getSelectedItem().toString().substring(0,jComboBox_inclusionExtension.getSelectedItem().toString().length()-10);
            excepcion.setNombre(excepcion.getNombre() + "se realiza el Caso de uso "
                        + nom + ". A continuación este caso de uso "
                        + this.jComboBox_terminacion.getSelectedItem().toString());
        }

        // La guardo y cierro
        if (puedoCerrar) {
            if (modificado)
                home.documentoRequisitos.modifyCasoUso_Excepcion(excepcion);
            else
                home.documentoRequisitos.addCasoUso_Excepcion(excepcion);

            // Cierro la ventana
            home.setEnabled(true);
            this.dispose();
        }
    }//GEN-LAST:event_jButton_aceptarActionPerformed

    private void actualizarJTree (Excepcion excepcion) {
        if (excepcion != null) {
            MutableTreeNode node = new DefaultMutableTreeNode(excepcion.getNombre() + " (" + excepcion.getIdentificacion() + ")");
            DefaultTreeModel model = (DefaultTreeModel) home.getJTree().getModel();
            if (modificado == false)
                model.insertNodeInto(node, insertNode, insertIndex);

            // Expande el JTree
            for (int j = 0; j < home.getJTree().getSize().height; j++)
                home.getJTree().expandPath(home.getJTree().getPathForRow(j));

            home.getJTree().setSelectionPath(null);
        }
    }

    private void jRadioButton_accionSistemaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton_accionSistemaItemStateChanged
        jComboBox_accionActor.setEnabled(false);
        jComboBox_inclusionExtension.setEnabled(false);
        jTextArea_acciones.setEnabled(true);
        jTextField_frecuencia.setEnabled(true);
        jComboBox_frecuencia.setEnabled(true);
    }//GEN-LAST:event_jRadioButton_accionSistemaItemStateChanged
    private void jRadioButton_accionActorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton_accionActorItemStateChanged
        jComboBox_accionActor.setEnabled(true);
        jComboBox_inclusionExtension.setEnabled(false);
        jTextArea_acciones.setEnabled(true);
        jTextField_frecuencia.setEnabled(false);
        jComboBox_frecuencia.setEnabled(false);
    }//GEN-LAST:event_jRadioButton_accionActorItemStateChanged
    private void jRadioButton_inclusionExtensionItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton_inclusionExtensionItemStateChanged
        jComboBox_accionActor.setEnabled(false);
        jComboBox_inclusionExtension.setEnabled(true);
        jTextArea_acciones.setEnabled(false);
        jTextField_frecuencia.setEnabled(false);
        jComboBox_frecuencia.setEnabled(false);
    }//GEN-LAST:event_jRadioButton_inclusionExtensionItemStateChanged
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        home.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_formWindowClosed





    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfCasoUso_Excepcion().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JButton jButton_aceptar;
    private javax.swing.JButton jButton_cancelar;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox_accionActor;
    private javax.swing.JComboBox jComboBox_frecuencia;
    private javax.swing.JComboBox jComboBox_inclusionExtension;
    private javax.swing.JComboBox jComboBox_terminacion;
    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.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton_accionActor;
    private javax.swing.JRadioButton jRadioButton_accionSistema;
    private javax.swing.JRadioButton jRadioButton_inclusionExtension;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea_acciones;
    private javax.swing.JTextArea jTextArea_comentarios;
    private javax.swing.JTextArea jTextArea_condicion;
    private javax.swing.JTextField jTextField_frecuencia;
    // End of variables declaration//GEN-END:variables





    public void update(Observable o, Object arg) {
        if (vecesActualizo == 0) {
            actualizarJTree(excepcion);
            home.actualizarTextPane();
            vecesActualizo++;
        }
    }

}
