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

/*
 * jfrmObjetivo.java
 *
 * Created on 08-ene-2012, 18:01:00
 */

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.Objetivo;

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

    /** Creates new form jfrmObjetivo */

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

    }

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

        jTabReqInf = new javax.swing.JTabbedPane();
        jpanGeneral = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtNombre = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxaConcepto = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jpanPrioridad = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jcboxImportancia = new javax.swing.JComboBox();
        jcboxUrgencia = new javax.swing.JComboBox();
        jcboxEstadoDesarrollo = new javax.swing.JComboBox();
        jcboxEstabilidad = new javax.swing.JComboBox();
        jbtnAceptar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Objetivo");
        setResizable(false);

        jLabel1.setText("Nombre:");

        jtxaConcepto.setColumns(20);
        jtxaConcepto.setRows(5);
        jtxaConcepto.setText("PD");
        jScrollPane1.setViewportView(jtxaConcepto);

        jLabel2.setText("El sistema deberá...");

        javax.swing.GroupLayout jpanGeneralLayout = new javax.swing.GroupLayout(jpanGeneral);
        jpanGeneral.setLayout(jpanGeneralLayout);
        jpanGeneralLayout.setHorizontalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jpanGeneralLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jpanGeneralLayout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                                .addGroup(jpanGeneralLayout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtxtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)))))
                    .addGroup(jpanGeneralLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jpanGeneralLayout.setVerticalGroup(
            jpanGeneralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanGeneralLayout.createSequentialGroup()
                .addContainerGap()
                .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.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabReqInf.addTab("General", jpanGeneral);

        jLabel9.setText("Importancia");

        jLabel10.setText("Urgencia");

        jLabel11.setText("Estado desarrollo");

        jLabel12.setText("Estabilidad");

        jcboxImportancia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PD", "esencial", "importante", "quedaría bien" }));

        jcboxUrgencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PD", "inmediatamente", "pronto", "se puede demorar" }));

        jcboxEstadoDesarrollo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PD", "en construcción", "pendiente de verificación", "pendiente de validación", "validado" }));

        jcboxEstabilidad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PD", "alta", "media", "baja" }));
        jcboxEstabilidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcboxEstabilidadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpanPrioridadLayout = new javax.swing.GroupLayout(jpanPrioridad);
        jpanPrioridad.setLayout(jpanPrioridadLayout);
        jpanPrioridadLayout.setHorizontalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanPrioridadLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jcboxEstabilidad, javax.swing.GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
                    .addComponent(jcboxImportancia, javax.swing.GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcboxUrgencia, javax.swing.GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE)
                    .addComponent(jcboxEstadoDesarrollo, javax.swing.GroupLayout.Alignment.LEADING, 0, 286, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpanPrioridadLayout.setVerticalGroup(
            jpanPrioridadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanPrioridadLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboxImportancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboxUrgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboxEstadoDesarrollo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcboxEstabilidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jTabReqInf.addTab("Prioridad", jpanPrioridad);

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

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

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabReqInf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(90, Short.MAX_VALUE)
                .addComponent(jbtnAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnCancelar)
                .addGap(89, 89, 89))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabReqInf, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAceptar)
                    .addComponent(jbtnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    private void jcboxEstabilidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcboxEstabilidadActionPerformed

}//GEN-LAST:event_jcboxEstabilidadActionPerformed

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

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        Objetivo newObj= auxDocPpal.newObj(jtxtNombre.getText(), jtxaConcepto.getText(), String.valueOf(jcboxImportancia.getSelectedItem()), String.valueOf(jcboxUrgencia.getSelectedItem()), String.valueOf(jcboxEstadoDesarrollo.getSelectedItem()), String.valueOf(jcboxEstabilidad.getSelectedItem()));
        MutableTreeNode node = new DefaultMutableTreeNode("[OBJ]-"+ newObj.getNumero_id()+" "+ newObj.getNombre());
        DefaultTreeModel model = (DefaultTreeModel) jfaux.getJtreDocumento().getModel();
        jfaux.getJtreDocumento().setCellRenderer(new RendererArbol());
        model.insertNodeInto(node, auxinsertNode, auxinsertIndex);
        mostrarmensaje("Insertado el Objetivo " + newObj.getNombre() + " correctamente.");
        auxDocPpal.actualizar();
        jfaux.setEnabled(true);
        this.dispose();
    }//GEN-LAST:event_jbtnAceptarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabReqInf;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JComboBox jcboxEstabilidad;
    private javax.swing.JComboBox jcboxEstadoDesarrollo;
    private javax.swing.JComboBox jcboxImportancia;
    private javax.swing.JComboBox jcboxUrgencia;
    private javax.swing.JPanel jpanGeneral;
    private javax.swing.JPanel jpanPrioridad;
    private javax.swing.JTextArea jtxaConcepto;
    private javax.swing.JTextField jtxtNombre;
    // End of variables declaration//GEN-END:variables

}
