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

/*
 * jfrmObjetivos.java
 *
 * Created on 11-ene-2012, 13:58:05
 */

package vista;

import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import modelo.DocumentoReq;
import modelo.Objetivos;

/**
 *
 * @author Ruben
 */
public class jfrmObjetivos extends javax.swing.JFrame {
    DocumentoReq auxDocPpal;
    jfrmPrincipal jfaux;
    MutableTreeNode auxinsertNode;
    int auxinsertIndex;

    
    public jfrmObjetivos(jfrmPrincipal jf, DocumentoReq docPpal, MutableTreeNode insertNode, int insertIndex) {
        auxinsertNode=insertNode;
        auxinsertIndex=insertIndex;
        jfaux=jf;
        auxDocPpal=docPpal;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtabObjetivos = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtxtAutores = new javax.swing.JTextField();
        jtxtFuentes = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jpanDescripcion = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtxaDescripcion = new javax.swing.JTextArea();
        jpanPrioridad = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jtxtimportancia = new javax.swing.JTextField();
        jtxturgencia = new javax.swing.JTextField();
        jtxtestadoDesarrollo = new javax.swing.JTextField();
        jtxtestabilidad = new javax.swing.JTextField();
        jpanComentarios = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxpComentarios = new javax.swing.JTextPane();
        jbtnAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jLabel2.setText("Autores:");

        jLabel3.setText("Fuentes:");

        javax.swing.GroupLayout jpanGeneralLayout = new javax.swing.GroupLayout(jpanGeneral);
        jpanGeneral.setLayout(jpanGeneralLayout);
        jpanGeneralLayout.setHorizontalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(12, 12, 12)
                        .addComponent(jtxtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtAutores, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtFuentes, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jpanGeneralLayout.setVerticalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtAutores, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jtxtFuentes, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jtabObjetivos.addTab("General", jpanGeneral);

        jLabel5.setText("El sistema debera...");

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

        javax.swing.GroupLayout jpanDescripcionLayout = new javax.swing.GroupLayout(jpanDescripcion);
        jpanDescripcion.setLayout(jpanDescripcionLayout);
        jpanDescripcionLayout.setHorizontalGroup(
            jpanDescripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDescripcionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanDescripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jLabel5))
                .addContainerGap())
        );
        jpanDescripcionLayout.setVerticalGroup(
            jpanDescripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanDescripcionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                .addContainerGap())
        );

        jtabObjetivos.addTab("Descripción", jpanDescripcion);

        jLabel7.setText("Importancia:");

        jLabel8.setText("Urgencia:");

        jLabel9.setText("Estado de desarrollo:");

        jLabel10.setText("Estabilidad:");

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

        javax.swing.GroupLayout jpanPrioridadLayout = new javax.swing.GroupLayout(jpanPrioridad);
        jpanPrioridad.setLayout(jpanPrioridadLayout);
        jpanPrioridadLayout.setHorizontalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrioridadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addGap(22, 22, 22)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtxtestabilidad)
                    .addComponent(jtxtestadoDesarrollo)
                    .addComponent(jtxturgencia)
                    .addComponent(jtxtimportancia, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                .addContainerGap(62, Short.MAX_VALUE))
        );
        jpanPrioridadLayout.setVerticalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrioridadLayout.createSequentialGroup()
                .addGap(49, 49, 49)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtxtimportancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jtxturgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jtxtestadoDesarrollo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jtxtestabilidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(118, Short.MAX_VALUE))
        );

        jtabObjetivos.addTab("Prioridad", jpanPrioridad);

        jLabel6.setText("Comentarios: ");

        jScrollPane1.setViewportView(jtxpComentarios);

        javax.swing.GroupLayout jpanComentariosLayout = new javax.swing.GroupLayout(jpanComentarios);
        jpanComentarios.setLayout(jpanComentariosLayout);
        jpanComentariosLayout.setHorizontalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );
        jpanComentariosLayout.setVerticalGroup(
            jpanComentariosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanComentariosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                .addContainerGap())
        );

        jtabObjetivos.addTab("Comentarios", jpanComentarios);

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(165, 165, 165)
                .addComponent(jbtnAceptar)
                .addContainerGap(185, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jtabObjetivos, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(329, Short.MAX_VALUE)
                .addComponent(jbtnAceptar)
                .addGap(21, 21, 21))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jtabObjetivos, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(69, Short.MAX_VALUE)))
        );

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

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

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        jfaux.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_formWindowClosed

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        if(comprobarTexto())
        {
            Objetivos newObj= auxDocPpal.nuevoObjetivo(jtxtNombre.getText(),jtxtAutores.getText(),jtxtFuentes.getText(),jtxaDescripcion.getText(),jtxpComentarios.getText(),jtxtimportancia.getText(),jtxturgencia.getText(),jtxtestadoDesarrollo.getText(),jtxtestabilidad.getText());
            MutableTreeNode node=new DefaultMutableTreeNode("Obj " + newObj.getNombre());
            DefaultTreeModel model =(DefaultTreeModel) jfaux.getJtreDocumento().getModel();
            model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
            mostrarmensaje("Insertado el Objetivo "+newObj.getNombre());
            jfaux.setEnabled(true);
            jfaux.update(null, evt);
            this.dispose();
        }
        else
        {
            mostrarmensaje("Debes rellenar todos los campos!!");
        }
    }//GEN-LAST:event_jbtnAceptarActionPerformed


    private boolean comprobarTexto()
    {
        if(jtxtNombre.getText().equals("") ||
                jtxtAutores.getText().equals("") ||
                jtxtFuentes.getText().equals("") ||
                jtxaDescripcion.getText().equals("") ||
                jtxtimportancia.getText().equals("") ||
                jtxturgencia.getText().equals("") ||
                jtxtestadoDesarrollo.getText().equals("") ||
                jtxtestabilidad.getText().equals("") ||
                jtxpComentarios.getText().equals(""))
        {
            return false;
        }
        return true;
    }
    /**
    * @param args the command line arguments
    */
  /*  public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jfrmObjetivos().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JPanel jpanComentarios;
    private javax.swing.JPanel jpanDescripcion;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JPanel jpanPrioridad;
    private javax.swing.JTabbedPane jtabObjetivos;
    private javax.swing.JTextArea jtxaDescripcion;
    private javax.swing.JTextPane jtxpComentarios;
    private javax.swing.JTextField jtxtAutores;
    private javax.swing.JTextField jtxtFuentes;
    private javax.swing.JTextField jtxtNombre;
    private javax.swing.JTextField jtxtestabilidad;
    private javax.swing.JTextField jtxtestadoDesarrollo;
    private javax.swing.JTextField jtxtimportancia;
    private javax.swing.JTextField jtxturgencia;
    // End of variables declaration//GEN-END:variables

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