/*
 *      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 controlador.Utilidades;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.DefaultListModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.CasoUso;
import modelo.Organizacion;
import modelo.Participante;





public class jfCasoUso extends javax.swing.JFrame implements Observer {
    // Formulario padre
    jfHome home;
    boolean modificado = false;
    // Colores
    Color colorBlanco = new Color(255, 255, 255);
    Color colorAmarillo = new Color(255, 255, 102);
    // Fecha
    Date fecha;
    // Utilidades
    Utilidades utilidades = new Utilidades();
    // JTree
    MutableTreeNode currentNode;
    MutableTreeNode insertNode;
    int insertIndex;
    // Control del Update de Observers
    private CasoUso casoUso;
    private int vecesActualizo;

    //Crear un arraylist de Organizaciones.
    ArrayList<Organizacion> organizacion = new ArrayList<Organizacion>();
    private DefaultListModel modeloListaAutores;
    private DefaultListModel modeloListaFuentes;

    public jfCasoUso() {
        initComponents();
        organizacion = home.documentoRequisitos.getOrganizacion();
    }
    public jfCasoUso(jfHome home) {
        // Inicializo
        initComponents();
        this.home = home;
        this.insertNode = home.getInsertNode();
        this.insertIndex = home.getInsertIndex(insertNode);
        // Configura el identificador
        String ident = this.home.documentoRequisitos.getNuevoIdentificadorCasoUso ();
        this.jTextField_identificacion.setText(ident);
        // Fecha del sistema
        fecha = new Date();
        jDateChooserFecha.setDate(fecha);
        jTextField_nombre.requestFocus();
        vecesActualizo = 0;
    }

    public void inicializarModificacion (CasoUso casoUso) {
        modificado = true;

        // Pestaña General
        jTextField_identificacion.setText(utilidades.getIdentificadorNumerico(casoUso.getIdentificacion()));
        jTextField_nombre.setText(casoUso.getNombre());
        jTextField_nombre.setEditable(false);
        String version = casoUso.getVersion();
        if (!version.equals(".")) {
            String versIzq = version.substring(0, version.indexOf("."));
            String versDer = version.substring(version.indexOf(".")+1, version.length());
            jTextField_versionIzq.setText(versIzq);
            jTextField_versionDer.setText(versDer);
        }
        jDateChooserFecha.setDate(casoUso.getFecha());

        //Autores y fuentes
        //Obtengo mi lista de autores.
        ArrayList<Participante> autores = casoUso.getAutores();
        ArrayList<String> miArrayAutor = new ArrayList<String>();
        for (int j=0; j<autores.size(); j++)
            miArrayAutor.add("(" + autores.get(j).getIdentificacion() + ") " + autores.get(j).getNombre());
        utilidades.setArrayAutor(miArrayAutor);

        //Obtengo mi lista de fuentes.
        ArrayList<Participante> fuentes = casoUso.getFuentes();
        ArrayList<String> miArrayFuentes = new ArrayList<String>();
        for (int j=0; j<fuentes.size(); j++)
            miArrayFuentes.add("(" + fuentes.get(j).getIdentificacion() + ") " + fuentes.get(j).getNombre());
        utilidades.setArrayFuente(miArrayFuentes);

        // Pestaña Detalle
        jTextArea_eventoActivacion.setText(casoUso.getEventoActivacion());
        if (casoUso.getEsAbstracto()){
            jCheckBox_esAbstracto.setSelected(true);
        }
        jTextField_frecuencia.setText(Integer.toString(casoUso.getVeces()));
        jComboBox_frecuencia.setSelectedItem(casoUso.getUnidad());

         //Pestaña Prioridad
         jComboBox_importancia.setSelectedItem(casoUso.getImportancia());
         jComboBox_estadoDesarrollo.setSelectedItem(casoUso.getEstadoDesarrollo());
         jComboBox_urgencia.setSelectedItem(casoUso.getUrgencia());
         jComboBox_estabilidad.setSelectedItem(casoUso.getEstabilidad());

         //PRE/POST
         jTextArea_precondicion.setText(casoUso.getPrecondicion());
         jTextArea_postcondicion.setText(casoUso.getPostcondicion());

         //RASTREABILIDAD
         jTextArea_comentarios.setText(casoUso.getComentario());

        // Pestaña Comentarios
        jTextArea_comentarios.setText(casoUso.getComentario());
    }

    



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

        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLabel_identificador = new javax.swing.JLabel();
        jTextField_identificacion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField_nombre = new javax.swing.JTextField();
        jPanel9 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField_versionIzq = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField_versionDer = new javax.swing.JTextField();
        jDateChooserFecha = new com.toedter.calendar.JDateChooser();
        jPanel10 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList_autores = new javax.swing.JList();
        jButton_anadirAutor = new javax.swing.JButton();
        jButton_eliminarAutor = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList_fuentes = new javax.swing.JList();
        jButton_eliminarFuente = new javax.swing.JButton();
        jButton_anadirFuente = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jCheckBox_esAbstracto = new javax.swing.JCheckBox();
        jPanel13 = new javax.swing.JPanel();
        jTextField_frecuencia = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jComboBox_frecuencia = new javax.swing.JComboBox();
        jPanel14 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea_eventoActivacion = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea_precondicion = new javax.swing.JTextArea();
        jPanel16 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea_postcondicion = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jComboBox_importancia = new javax.swing.JComboBox();
        jPanel18 = new javax.swing.JPanel();
        jComboBox_urgencia = new javax.swing.JComboBox();
        jPanel19 = new javax.swing.JPanel();
        jComboBox_estadoDesarrollo = new javax.swing.JComboBox();
        jPanel20 = new javax.swing.JPanel();
        jComboBox_estabilidad = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        jPanel21 = new javax.swing.JPanel();
        jButton_eliminarTrazaOrigen = new javax.swing.JButton();
        jButton_anadirTrazaOrigen = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList_trazasOrigen = new javax.swing.JList();
        jPanel22 = new javax.swing.JPanel();
        jButton_eliminarTrazaDestino = new javax.swing.JButton();
        jButton_anadirTrazaDestino = new javax.swing.JButton();
        jScrollPane9 = new javax.swing.JScrollPane();
        jList_trazasDestino = new javax.swing.JList();
        jPanel7 = new javax.swing.JPanel();
        jPanel23 = new javax.swing.JPanel();
        jScrollPane6 = 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("Caso de uso");
        setAlwaysOnTop(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setPreferredSize(new java.awt.Dimension(563, 306));

        jTabbedPane1.setPreferredSize(new java.awt.Dimension(564, 262));

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Identificación"));
        jPanel8.setToolTipText("");
        jPanel8.setName(""); // NOI18N

        jLabel_identificador.setText("UC-");

        jTextField_identificacion.setEditable(false);
        jTextField_identificacion.setMinimumSize(new java.awt.Dimension(6, 15));
        jTextField_identificacion.setPreferredSize(new java.awt.Dimension(35, 20));

        jLabel2.setText("Nombre:");

        jTextField_nombre.setPreferredSize(new java.awt.Dimension(300, 20));

        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(jLabel_identificador)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_identificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel_identificador)
                .addComponent(jTextField_identificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2)
                .addComponent(jTextField_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Versión"));
        jPanel9.setPreferredSize(new java.awt.Dimension(525, 43));

        jLabel3.setText("Número:");

        jLabel4.setText("Fecha:");

        jTextField_versionIzq.setText("1");
        jTextField_versionIzq.setPreferredSize(new java.awt.Dimension(20, 20));

        jLabel5.setText(".");

        jTextField_versionDer.setText("0");
        jTextField_versionDer.setPreferredSize(new java.awt.Dimension(20, 20));

        jDateChooserFecha.setDateFormatString("dd/MM/yyyy");

        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(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_versionIzq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField_versionDer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(68, 68, 68)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDateChooserFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(225, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jTextField_versionIzq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jTextField_versionDer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))
                    .addComponent(jDateChooserFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Autores"));
        jPanel10.setPreferredSize(new java.awt.Dimension(265, 114));

        jList_autores.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jList_autores);

        jButton_anadirAutor.setText("Añadir");
        jButton_anadirAutor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_anadirAutorActionPerformed(evt);
            }
        });

        jButton_eliminarAutor.setText("Eliminar");
        jButton_eliminarAutor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_eliminarAutorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jButton_anadirAutor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_eliminarAutor)))
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_eliminarAutor)
                    .addComponent(jButton_anadirAutor))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder("Fuentes"));
        jPanel11.setPreferredSize(new java.awt.Dimension(265, 78));

        jList_fuentes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(jList_fuentes);

        jButton_eliminarFuente.setText("Eliminar");
        jButton_eliminarFuente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_eliminarFuenteActionPerformed(evt);
            }
        });

        jButton_anadirFuente.setText("Añadir");
        jButton_anadirFuente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_anadirFuenteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jButton_anadirFuente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_eliminarFuente)))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_eliminarFuente)
                    .addComponent(jButton_anadirFuente))
                .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(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 540, Short.MAX_VALUE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                    .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("General", jPanel2);

        jPanel12.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de caso de uso"));

        jCheckBox_esAbstracto.setText("Caso de uso abstracto");
        jCheckBox_esAbstracto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_esAbstractoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox_esAbstracto)
                .addContainerGap(56, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addComponent(jCheckBox_esAbstracto)
                .addContainerGap(8, Short.MAX_VALUE))
        );

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder("Frecuencia"));

        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 jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.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())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addGroup(jPanel13Layout.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))
        );

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder("Evento de activación"));

        jTextArea_eventoActivacion.setColumns(20);
        jTextArea_eventoActivacion.setLineWrap(true);
        jTextArea_eventoActivacion.setRows(5);
        jScrollPane3.setViewportView(jTextArea_eventoActivacion);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 167, 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(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Detalle", jPanel3);

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder("Precondición"));
        jPanel15.setPreferredSize(new java.awt.Dimension(265, 212));

        jTextArea_precondicion.setColumns(20);
        jTextArea_precondicion.setLineWrap(true);
        jTextArea_precondicion.setRows(5);
        jScrollPane4.setViewportView(jTextArea_precondicion);

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel16.setBorder(javax.swing.BorderFactory.createTitledBorder("Postcondición"));
        jPanel16.setPreferredSize(new java.awt.Dimension(265, 212));

        jTextArea_postcondicion.setColumns(20);
        jTextArea_postcondicion.setLineWrap(true);
        jTextArea_postcondicion.setRows(5);
        jScrollPane5.setViewportView(jTextArea_postcondicion);

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(jPanel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                    .addComponent(jPanel16, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Pre / Post", jPanel4);

        jPanel17.setBorder(javax.swing.BorderFactory.createTitledBorder("Importancia"));
        jPanel17.setPreferredSize(new java.awt.Dimension(265, 73));

        jComboBox_importancia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "Vital", "Importante", "Quedaría bien" }));

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_importancia, 0, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_importancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel18.setBorder(javax.swing.BorderFactory.createTitledBorder("Urgencia"));
        jPanel18.setPreferredSize(new java.awt.Dimension(265, 73));

        jComboBox_urgencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "Inmediato", "Con presión", "Puede esperar" }));

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_urgencia, 0, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_urgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel19.setBorder(javax.swing.BorderFactory.createTitledBorder("Estado de desarrollo"));
        jPanel19.setPreferredSize(new java.awt.Dimension(265, 73));

        jComboBox_estadoDesarrollo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "En construcción", "Pendiente de verificación", "Pendiente de validación", "Validado" }));

        javax.swing.GroupLayout jPanel19Layout = new javax.swing.GroupLayout(jPanel19);
        jPanel19.setLayout(jPanel19Layout);
        jPanel19Layout.setHorizontalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_estadoDesarrollo, 0, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel19Layout.setVerticalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_estadoDesarrollo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel20.setBorder(javax.swing.BorderFactory.createTitledBorder("Estabilidad"));
        jPanel20.setPreferredSize(new java.awt.Dimension(265, 73));

        jComboBox_estabilidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "Baja", "Media", "Alta" }));

        javax.swing.GroupLayout jPanel20Layout = new javax.swing.GroupLayout(jPanel20);
        jPanel20.setLayout(jPanel20Layout);
        jPanel20Layout.setHorizontalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel20Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_estabilidad, 0, 233, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel20Layout.setVerticalGroup(
            jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel20Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox_estabilidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        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)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9)
                        .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jPanel18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(71, 71, 71))
        );

        jTabbedPane1.addTab("Prioridad", jPanel5);

        jPanel21.setBorder(javax.swing.BorderFactory.createTitledBorder("Trazas origen"));
        jPanel21.setPreferredSize(new java.awt.Dimension(265, 212));

        jButton_eliminarTrazaOrigen.setText("Eliminar");

        jButton_anadirTrazaOrigen.setText("Añadir");
        jButton_anadirTrazaOrigen.setPreferredSize(new java.awt.Dimension(69, 23));

        jScrollPane8.setViewportView(jList_trazasOrigen);

        javax.swing.GroupLayout jPanel21Layout = new javax.swing.GroupLayout(jPanel21);
        jPanel21.setLayout(jPanel21Layout);
        jPanel21Layout.setHorizontalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addGroup(jPanel21Layout.createSequentialGroup()
                        .addComponent(jButton_anadirTrazaOrigen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_eliminarTrazaOrigen)))
                .addContainerGap())
        );
        jPanel21Layout.setVerticalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_eliminarTrazaOrigen)
                    .addComponent(jButton_anadirTrazaOrigen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel22.setBorder(javax.swing.BorderFactory.createTitledBorder("Trazas destino"));
        jPanel22.setPreferredSize(new java.awt.Dimension(265, 212));

        jButton_eliminarTrazaDestino.setText("Eliminar");

        jButton_anadirTrazaDestino.setText("Añadir");
        jButton_anadirTrazaDestino.setPreferredSize(new java.awt.Dimension(69, 23));

        jScrollPane9.setViewportView(jList_trazasDestino);

        javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
        jPanel22.setLayout(jPanel22Layout);
        jPanel22Layout.setHorizontalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addGroup(jPanel22Layout.createSequentialGroup()
                        .addComponent(jButton_anadirTrazaDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton_eliminarTrazaDestino)))
                .addContainerGap())
        );
        jPanel22Layout.setVerticalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_eliminarTrazaDestino)
                    .addComponent(jButton_anadirTrazaDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        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()
                .addComponent(jPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(jPanel22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel22, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Rastreabilidad", jPanel6);

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

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

        javax.swing.GroupLayout jPanel23Layout = new javax.swing.GroupLayout(jPanel23);
        jPanel23.setLayout(jPanel23Layout);
        jPanel23Layout.setHorizontalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel23Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel23Layout.setVerticalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel23Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addContainerGap())
        );

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

        jTabbedPane1.addTab("Comentarios", jPanel7);

        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 jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(399, Short.MAX_VALUE)
                .addComponent(jButton_aceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton_cancelar)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_cancelar)
                    .addComponent(jButton_aceptar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
        );

        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 formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        home.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_formWindowClosed
    private void jButton_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_aceptarActionPerformed
        casoUso = new CasoUso();
        boolean puedoCerrar = true;

        // Identificador
        casoUso.setIdentificacion(this.jLabel_identificador.getText() + this.jTextField_identificacion.getText());

        // Nombre
        if (!this.jTextField_nombre.getText().equals("")) {
            this.jTextField_nombre.setBackground(colorBlanco);
            casoUso.setNombre(this.jTextField_nombre.getText());
        } else {
            this.jTextField_nombre.setBackground(colorAmarillo);
            puedoCerrar = false;
        }
        
        casoUso.setVersion(this.jTextField_versionIzq.getText() + "." + this.jTextField_versionDer.getText());

        // Autores
        ArrayList<String> listaAutores = utilidades.getArrayAutor();

        if (!listaAutores.isEmpty()) {                                                  // SI hay autores en el formulario
            ArrayList<Participante> autores = new ArrayList<Participante>();

            for (int i = 0; i < listaAutores.size(); i++) {                              // Recorro cada autor del formulario
                ArrayList<Participante> participantes = home.documentoRequisitos.getParticipante();              // Obtengo los participantes ya introducidos en el documento requisitos
                String elemento = listaAutores.get(i);
                // Busco el autor introducido en el formulario entre los participantes ya incluídos en el documento
                for (int j = 0; j < participantes.size(); j++) {                                            // Recorro los partipantes del documento
                    if(participantes.get(j).getIdentificacion().equals(elemento.substring(1, 9))){
                        autores.add(participantes.get(j));
                        break;
                    }
                }
            }
            casoUso.setAutores(autores);
        }

        // Fuentes
        ArrayList<String> listaFuentes = utilidades.getArrayFuente();

        if (!listaFuentes.isEmpty()) {                                                  // SI hay autores en el formulario
            ArrayList<Participante> fuentes = new ArrayList<Participante>();

            for (int i = 0; i < listaFuentes.size(); i++) {                              // Recorro cada autor del formulario
                ArrayList<Participante> participantes = home.documentoRequisitos.getParticipante();              // Obtengo los participantes ya introducidos en el documento requisitos
                String elemento = listaFuentes.get(i);
                // Busco el autor introducido en el formulario entre los participantes ya incluídos en el documento
                for (int j = 0; j < participantes.size(); j++) {                                            // Recorro los partipantes del documento
                    if(participantes.get(j).getIdentificacion().equals(elemento.substring(1, 9))){
                        fuentes.add(participantes.get(j));
                        break;
                    }
                }
            }
            casoUso.setFuentes(fuentes);
        }

        casoUso.setEventoActivacion(this.jTextArea_eventoActivacion.getText());
        casoUso.setEsAbstracto(this.jCheckBox_esAbstracto.isSelected());
        if (!this.jTextField_frecuencia.getText().equals(""))
            casoUso.setVeces(Integer.parseInt(this.jTextField_frecuencia.getText()));
        casoUso.setUnidad((String)this.jComboBox_frecuencia.getSelectedItem());
        casoUso.setPrecondicion(this.jTextArea_precondicion.getText());
        casoUso.setPostcondicion(this.jTextArea_postcondicion.getText());
        casoUso.setImportancia((String)this.jComboBox_importancia.getSelectedItem());
        casoUso.setEstadoDesarrollo((String)this.jComboBox_estadoDesarrollo.getSelectedItem());
        casoUso.setUrgencia((String)this.jComboBox_urgencia.getSelectedItem());
        casoUso.setEstabilidad((String)this.jComboBox_estabilidad.getSelectedItem());

        //Insertamos la fecha.
        fecha = jDateChooserFecha.getDate();
        if(fecha == null)
            fecha = new Date(); //sino metemos ninguna fecha que se guarde la del sistema
        casoUso.setFecha(fecha);

        casoUso.setComentario(this.jTextArea_comentarios.getText());

        // Fin de la captura de los datos desde el formulario
        if (puedoCerrar) {
            if (modificado)
                home.documentoRequisitos.modifyCasoUso(casoUso);
            else
                home.documentoRequisitos.addCasoUso(casoUso);

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

    private void actualizarJTree (CasoUso casoUso) {
        if(casoUso != null){
            MutableTreeNode node = new DefaultMutableTreeNode(casoUso.getNombre() + " (" + casoUso.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 jCheckBox_esAbstractoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_esAbstractoActionPerformed
    }//GEN-LAST:event_jCheckBox_esAbstractoActionPerformed

    private void jButton_anadirAutorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_anadirAutorActionPerformed
            // Creo ventana
            jfAddAutor jfAddAutor = new jfAddAutor(home,this, utilidades);
            jfAddAutor.setVisible(true);
            this.setEnabled(false);
            //Centrar ventana
            jfAddAutor.setLocationRelativeTo(this);
            home.documentoRequisitos.addObserver(jfAddAutor);
    }//GEN-LAST:event_jButton_anadirAutorActionPerformed

    private void jButton_eliminarAutorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_eliminarAutorActionPerformed
        if(jList_autores.getSelectedIndex() != -1){ //Si no hay ninguno seleccionado
            utilidades.removeArrayAutor(jList_autores.getSelectedValue().toString());
            modeloListaAutores.remove(jList_autores.getSelectedIndex());
        }
    }//GEN-LAST:event_jButton_eliminarAutorActionPerformed

    private void jButton_anadirFuenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_anadirFuenteActionPerformed
            // Creo ventana
            jfAddFuente jfAddFuente = new jfAddFuente(home, this, utilidades);
            jfAddFuente.setVisible(true);
            this.setEnabled(false);
            //Centrar ventana
            jfAddFuente.setLocationRelativeTo(this);
            home.documentoRequisitos.addObserver(jfAddFuente);
    }//GEN-LAST:event_jButton_anadirFuenteActionPerformed

    private void jButton_eliminarFuenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_eliminarFuenteActionPerformed
        if(jList_fuentes.getSelectedIndex() != -1){ //Si no hay ninguno seleccionado
            utilidades.removeArrayFuente(jList_fuentes.getSelectedValue().toString());
            modeloListaFuentes.remove(jList_fuentes.getSelectedIndex());
        }
    }//GEN-LAST:event_jButton_eliminarFuenteActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        //autores
        modeloListaAutores =   new DefaultListModel();
        jList_autores.setModel(modeloListaAutores);
        ArrayList<String> arrayAutor = utilidades.getArrayAutor();
        for (int i = 0; i < arrayAutor.size(); i++){
            modeloListaAutores.addElement(arrayAutor.get(i));
        }
        
        //fuentes
        modeloListaFuentes = new DefaultListModel();
        jList_fuentes.setModel(modeloListaFuentes);
        ArrayList<String> arrayFuente = utilidades.getArrayFuente();
        for (int i = 0; i < arrayFuente.size(); i++){
            modeloListaFuentes.addElement(arrayFuente.get(i));
        }
    }//GEN-LAST:event_formWindowActivated





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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_aceptar;
    private javax.swing.JButton jButton_anadirAutor;
    private javax.swing.JButton jButton_anadirFuente;
    private javax.swing.JButton jButton_anadirTrazaDestino;
    private javax.swing.JButton jButton_anadirTrazaOrigen;
    private javax.swing.JButton jButton_cancelar;
    private javax.swing.JButton jButton_eliminarAutor;
    private javax.swing.JButton jButton_eliminarFuente;
    private javax.swing.JButton jButton_eliminarTrazaDestino;
    private javax.swing.JButton jButton_eliminarTrazaOrigen;
    private javax.swing.JCheckBox jCheckBox_esAbstracto;
    private javax.swing.JComboBox jComboBox_estabilidad;
    private javax.swing.JComboBox jComboBox_estadoDesarrollo;
    private javax.swing.JComboBox jComboBox_frecuencia;
    private javax.swing.JComboBox jComboBox_importancia;
    private javax.swing.JComboBox jComboBox_urgencia;
    private com.toedter.calendar.JDateChooser jDateChooserFecha;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel_identificador;
    private javax.swing.JList jList_autores;
    private javax.swing.JList jList_fuentes;
    private javax.swing.JList jList_trazasDestino;
    private javax.swing.JList jList_trazasOrigen;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    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.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea_comentarios;
    private javax.swing.JTextArea jTextArea_eventoActivacion;
    private javax.swing.JTextArea jTextArea_postcondicion;
    private javax.swing.JTextArea jTextArea_precondicion;
    private javax.swing.JTextField jTextField_frecuencia;
    private javax.swing.JTextField jTextField_identificacion;
    private javax.swing.JTextField jTextField_nombre;
    private javax.swing.JTextField jTextField_versionDer;
    private javax.swing.JTextField jTextField_versionIzq;
    // End of variables declaration//GEN-END:variables

    
    
    

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

    public void persist(Object object) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("AZETA_REMPU");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            em.persist(object);
            em.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
            em.getTransaction().rollback();
        } finally {
            em.close();
        }
    }
    
}
