Package view

Source Code of view.AlunoView

/*
* EstagiarioView.java
*
* Created on 13 de Setembro de 2008, 11:48
*/

package view;

import controller.AlunoController;
import controller.operating.GerenciadorOperacional;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import model.Pessoa;
import controller.operating.Strings;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import model.Aluno;
import model.Endereco;

/**
*
* @author  Consult
*/
public class AlunoView extends javax.swing.JInternalFrame {

    private enum  Modo {Edicao, Inclusao, Navegacao};   
    private Modo modo;
   
    /** Creates new form EstagiarioView */
    public AlunoView() {
        initComponents();
        carregaTabela();
        modo = Modo.Navegacao;
    }
   
     private void habilitaCampos(Boolean pValor) {
        // TODO add your handling code here:
        Component[] c = jPanel1.getComponents();
        jTextAreaObservacao.setEnabled(pValor);
        for (int i = 0; i < c.length; i++) {
            if ((c[i] instanceof JTextField)) {
                c[i].setEnabled(pValor);
            }
            if (c[i] instanceof JComboBox){
                c[i].setEnabled(pValor);
            }
        }
    }
    
      private void limpaCampos() {
        Component[] c = jPanel1.getComponents();
        for (int i = 0; i < c.length; i++) {
            if (c[i] instanceof JTextField) {
                ((JTextField) c[i]).setText("");
            }
            if (c[i] instanceof JComboBox){
                ((JComboBox)c[i]).setSelectedItem("-");
            }
        }
        jTextAreaObservacao.setText("");
    }
     
    private void habilitaBotoes(JButton[] pBotoes, Boolean pValor) {
    // TODO add your handling code here:
        for (int i = 0; i < pBotoes.length; i++) {
            pBotoes[i].setEnabled(pValor);
        }
    }
   
    private void carregaTabela(){
        Vector<String> elementosDaTabela = new Vector<String>();
        elementosDaTabela.addElement("Código");
        elementosDaTabela.addElement("Nome");
        elementosDaTabela.addElement("E-mail");       
        elementosDaTabela.addElement("Telefone");               
        elementosDaTabela.addElement("Celular");                                     
        AlunoController alunoCtrl= new AlunoController();                      
        DefaultTableModel modeloTabela = new DefaultTableModel(elementosDaTabela,0);
        modeloTabela = alunoCtrl.getTableAlunos(modeloTabela);
        jTable1.setModel(modeloTabela);
    }   

    /** 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() {

        jToolBar1 = new javax.swing.JToolBar();
        btnNovo = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btnSalvar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        btnEditar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        btnExcluir = new javax.swing.JButton();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        btnCancelar = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        btnFechar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabelCodigo = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelCelular = new javax.swing.JLabel();
        jLabelTelefone = new javax.swing.JLabel();
        jLabelCPF = new javax.swing.JLabel();
        jLabelRG = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JFormattedTextField();
        jTextFieldCPF = new javax.swing.JFormattedTextField();
        jTextFieldRG = new javax.swing.JFormattedTextField();
        jTextFieldCodigoAluno = new javax.swing.JTextField();
        jTextFieldTelefone = new javax.swing.JFormattedTextField();
        jTextFieldCelular = new javax.swing.JFormattedTextField();
        jTextFieldEmail = new javax.swing.JFormattedTextField();
        jLabelNascimento = new javax.swing.JLabel();
        jTextFieldNascimento = new javax.swing.JFormattedTextField();
        jLabelObservacao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacao = new javax.swing.JTextArea();
        jLabelEndereco = new javax.swing.JLabel();
        jLabelBairro = new javax.swing.JLabel();
        jLabelCEP = new javax.swing.JLabel();
        jTextFieldCEP = new javax.swing.JFormattedTextField();
        jLabelCidade = new javax.swing.JLabel();
        jComboBoxCidade = new javax.swing.JComboBox();
        jLabelUF = new javax.swing.JLabel();
        jComboBoxUf = new javax.swing.JComboBox();
        jTextFieldEndereco = new javax.swing.JFormattedTextField();
        jLabelNumero = new javax.swing.JLabel();
        jTextFieldNumero = new javax.swing.JFormattedTextField();
        jTextFieldBairro = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldComplemento = new javax.swing.JTextField();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Aluno");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);

        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Novo.png"))); // NOI18N
        btnNovo.setText("Novo");
        btnNovo.setFocusable(false);
        btnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnNovo);
        jToolBar1.add(jSeparator1);

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Salvar.png"))); // NOI18N
        btnSalvar.setFocusable(false);
        btnSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnSalvar.setLabel("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnSalvar);
        jToolBar1.add(jSeparator3);

        btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Editar.png"))); // NOI18N
        btnEditar.setText("Editar");
        btnEditar.setFocusable(false);
        btnEditar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEditar);
        jToolBar1.add(jSeparator2);

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Excluir.png"))); // NOI18N
        btnExcluir.setText("Excluir");
        btnExcluir.setFocusable(false);
        btnExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(btnExcluir);
        jToolBar1.add(jSeparator5);

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setFocusable(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnCancelar);
        jToolBar1.add(jSeparator4);

        btnFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Sair.png"))); // NOI18N
        btnFechar.setText("Fechar");
        btnFechar.setFocusable(false);
        btnFechar.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
        btnFechar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnFechar.setVerifyInputWhenFocusTarget(false);
        btnFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFecharActionPerformed(evt);
            }
        });
        jToolBar1.add(btnFechar);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jLabelCodigo.setText("Código:");

        jLabelNome.setText("Nome:");

        jLabelEmail.setText("E-Mail:");

        jLabelCelular.setText("Celular:");

        jLabelTelefone.setText("Telefone:");

        jLabelCPF.setText("CPF:");

        jLabelRG.setText("RG:");

        jTextFieldNome.setName("Nome"); // NOI18N

        try {
            jTextFieldCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldCPF.setName("CPF"); // NOI18N

        jTextFieldRG.setName("RG(Registro Geral)"); // NOI18N

        jTextFieldCodigoAluno.setEditable(false);
        jTextFieldCodigoAluno.setEnabled(false);

        try {
            jTextFieldTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldTelefone.setName("Telefone"); // NOI18N

        try {
            jTextFieldCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldCelular.setName("Celular"); // NOI18N

        jTextFieldEmail.setName("E-Mail"); // NOI18N
        jTextFieldEmail.setSelectionEnd(1);

        jLabelNascimento.setText("Nascimento:");

        try {
            jTextFieldNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldNascimento.setName("Nascimento"); // NOI18N

        jLabelObservacao.setText("Observações:");

        jTextAreaObservacao.setColumns(20);
        jTextAreaObservacao.setFont(new java.awt.Font("Arial", 0, 12));
        jTextAreaObservacao.setLineWrap(true);
        jTextAreaObservacao.setRows(5);
        jTextAreaObservacao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextAreaObservacaoKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTextAreaObservacao);

        jLabelEndereco.setText("Endereço:");

        jLabelBairro.setText("Bairro:");

        jLabelCEP.setText("CEP:");

        try {
            jTextFieldCEP.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldCEP.setName("Cep"); // NOI18N

        jLabelCidade.setText("Cidade:");

        jComboBoxCidade.setModel(new javax.swing.DefaultComboBoxModel(Strings.comboCidades));

        jLabelUF.setText("UF:");

        jComboBoxUf.setModel(new javax.swing.DefaultComboBoxModel(Strings.comboUFsBrasil));

        jTextFieldEndereco.setName("Endereço"); // NOI18N

        jLabelNumero.setText("N°:");

        jTextFieldNumero.setName("Número"); // NOI18N

        jTextFieldBairro.setName("Bairro"); // NOI18N

        jLabel1.setText("Complemento:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelCodigo)
                            .addComponent(jLabelCPF)
                            .addComponent(jLabelTelefone)
                            .addComponent(jLabelCelular))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldCodigoAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabelNome)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jTextFieldCPF, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldCelular, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldTelefone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelEmail)
                                    .addComponent(jLabelRG, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(6, 6, 6)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldRG, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabelNascimento)
                                        .addGap(12, 12, 12)
                                        .addComponent(jTextFieldNascimento, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE))))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabelObservacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelEndereco)
                            .addComponent(jLabelBairro)
                            .addComponent(jLabelCEP))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldCEP, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelCidade)
                                .addGap(12, 12, 12)
                                .addComponent(jComboBoxCidade, 0, 203, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabelUF)
                                .addGap(11, 11, 11)
                                .addComponent(jComboBoxUf, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldBairro, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCodigo)
                    .addComponent(jTextFieldCodigoAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNome)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCPF)
                    .addComponent(jTextFieldCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelRG, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNascimento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTelefone)
                    .addComponent(jLabelEmail)
                    .addComponent(jTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCelular)
                    .addComponent(jTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEndereco)
                    .addComponent(jTextFieldNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNumero)
                    .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelBairro)
                    .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelUF)
                    .addComponent(jComboBoxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCEP)
                    .addComponent(jTextFieldCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelObservacao)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
        );

        setBounds(10, 10, 558, 544);
    }// </editor-fold>//GEN-END:initComponents

private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
// TODO add your handling code here:
    habilitaCampos(false);

    JButton[] listaBotoes = {btnSalvar, btnCancelar, btnEditar,btnExcluir};
    habilitaBotoes(listaBotoes, false);
   
    modo = Modo.Navegacao;
}//GEN-LAST:event_formInternalFrameOpened

private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
// TODO add your handling code here:
    limpaCampos();   
    jTextFieldNome.requestFocus();

    JButton[] ativaBotoes = {btnSalvar, btnCancelar};
    habilitaBotoes(ativaBotoes, true);

    JButton[] desativaBotoes = {btnFechar, btnEditar, btnExcluir, btnNovo};
    habilitaBotoes(desativaBotoes, false);

    AlunoController alunoCtrl = new AlunoController();
    jTextFieldCodigoAluno.setText(alunoCtrl.getNovoCodigo());
   
    habilitaCampos(true);
    jTable1.setEnabled(false);
   
    modo = Modo.Inclusao;
}//GEN-LAST:event_btnNovoActionPerformed

private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
// TODO add your handling code here:
    boolean podeSalvar = true;
    boolean salvou = false;
   
    if(jTextFieldNome.getText().isEmpty()){
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Nome"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextFieldNome.requestFocus();
    }
   
     if(podeSalvar){
        Pessoa pessoa = new Pessoa();
        pessoa.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoAluno.getText()));
       
        Endereco endereco = new Endereco(
                jTextFieldEndereco.getText(),
                jTextFieldNumero.getText(),
                jTextFieldBairro.getText(),
                jTextFieldCEP.getText(),
                jTextFieldComplemento.getText(),
                jComboBoxCidade.getSelectedItem().toString(),
                jComboBoxUf.getSelectedItem().toString(),
                pessoa);

        Aluno aluno = new Aluno();
        aluno.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoAluno.getText()));
        aluno.setCodigoAluno(Integer.parseInt(jTextFieldCodigoAluno.getText()));
        aluno.setNome(jTextFieldNome.getText());
        aluno.setEmail(jTextFieldEmail.getText());
        aluno.setTelefone(jTextFieldTelefone.getText());
        aluno.setCelular(jTextFieldCelular.getText());
        aluno.setRg(jTextFieldRG.getText());
        aluno.setCpf(jTextFieldCPF.getText());
        aluno.setNascimento(jTextFieldNascimento.getText());
        aluno.setObservacao(jTextAreaObservacao.getText());
        aluno.setEndereco(endereco);
       
        AlunoController alunoController = new AlunoController();
       
        if (modo.equals(Modo.Inclusao)){
            salvou = alunoController.salvar(aluno);
        }else{
            salvou = alunoController.atualizar(aluno);
        }      
       
        if(salvou){
            JButton[] desativaBotoes = {btnSalvar, btnCancelar, btnEditar};
            habilitaBotoes(desativaBotoes, false);

            JButton[] ativaBotoes = {btnNovo, btnFechar, btnExcluir};
            habilitaBotoes(ativaBotoes, true);

            habilitaCampos(false);
            jTable1.setEnabled(true);
           
            JOptionPane.showMessageDialog(this, Strings.operacaoSucesso);
           
            carregaTabela();
           
            modo = Modo.Navegacao;
        }
  }
}//GEN-LAST:event_btnSalvarActionPerformed

private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
// TODO add your handling code here:
    habilitaCampos(true);
    jTextFieldNome.requestFocus();
   
    JButton[] desativaBotoes = {btnNovo, btnEditar, btnFechar, btnExcluir};
    habilitaBotoes(desativaBotoes, false);

    JButton[] ativaBotoes = {btnSalvar, btnCancelar};
    habilitaBotoes(ativaBotoes, true);
   
    jTextFieldCodigoAluno.setEnabled(false);
    jTable1.setEnabled(false);
   
    modo = Modo.Edicao;
}//GEN-LAST:event_btnEditarActionPerformed

private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
// TODO add your handling code here:
    AlunoController alunoCtrl = new AlunoController();
    String codigoSelecionado = jTextFieldCodigoAluno.getText();
    Object[] opcoes = {"Sim", "Não"};
    int confirma = JOptionPane.showOptionDialog(null, Strings.confirmaExcluir, Strings.tituloExcluir, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, opcoes, opcoes[0]);
    if (confirma == 0) {
        if (alunoCtrl.excluir(codigoSelecionado)) {
            JOptionPane.showMessageDialog(this, Strings.operacaoSucesso);
            carregaTabela();
        } else {
            JOptionPane.showMessageDialog(this, Strings.operacaoFracasso, Strings.tituloMessage, JOptionPane.ERROR_MESSAGE);
        }
    }
    modo = Modo.Navegacao;
}//GEN-LAST:event_btnExcluirActionPerformed

private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
// TODO add your handling code here:
    JButton[] desativaBotoes = {btnSalvar, btnCancelar, btnEditar, btnExcluir};
    habilitaBotoes(desativaBotoes, false);

    JButton[] ativaBotoes = {btnNovo, btnFechar};
    habilitaBotoes(ativaBotoes, true);
   
    limpaCampos();
    habilitaCampos(false);
    jTable1.setEnabled(true);
   
    modo = Modo.Navegacao;
}//GEN-LAST:event_btnCancelarActionPerformed

private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
// TODO add your handling code here:
    GerenciadorOperacional.removeFrame();
}//GEN-LAST:event_btnFecharActionPerformed

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
    if(modo.equals(Modo.Navegacao)){
        limpaCampos();
        AlunoController alunoCtrl = new AlunoController();
        int linhaSelecionada = jTable1.getSelectedRow();
        String codigo = String.valueOf(jTable1.getValueAt(linhaSelecionada, 0));
        Aluno aluno = alunoCtrl.getAluno(codigo);
        jTextFieldCodigoAluno.setText(String.valueOf(aluno.getCodigoPessoa()));
        jTextFieldNome.setText(aluno.getNome());
        jTextFieldEmail.setText(aluno.getEmail());
        jTextFieldRG.setText(aluno.getRg());
        jTextFieldCelular.setText(aluno.getCelular());
        jTextFieldBairro.setText(aluno.getEndereco().getBairro());
        jTextFieldCEP.setText(aluno.getEndereco().getCep());
        jTextFieldCPF.setText(aluno.getCpf());
        jTextFieldEndereco.setText(aluno.getEndereco().getLogradouro());
        jTextFieldNascimento.setText(aluno.getNascimento());
        jTextFieldNumero.setText(aluno.getEndereco().getNumero());
        jTextFieldTelefone.setText(aluno.getTelefone());
        jTextFieldComplemento.setText(aluno.getEndereco().getComplemento());
        jComboBoxUf.setSelectedItem(aluno.getEndereco().getUf());
        jComboBoxCidade.setSelectedItem(aluno.getEndereco().getNomeCidade());
        jTextAreaObservacao.setText(aluno.getObservacao());

        JButton[] listaBotoes = {btnEditar, btnExcluir};
        habilitaBotoes(listaBotoes, true);
    }
    evt.consume();
}//GEN-LAST:event_jTable1MouseClicked

private void jTextAreaObservacaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextAreaObservacaoKeyPressed
// TODO add your handling code here:
     if (evt.getKeyCode() == KeyEvent.VK_TAB){
        evt.consume();
        KeyboardFocusManager.
            getCurrentKeyboardFocusManager().focusNextComponent();
    }

    if (evt.getKeyCode() == KeyEvent.VK_TAB &&  evt.isShiftDown()){
        evt.consume();
        KeyboardFocusManager.
            getCurrentKeyboardFocusManager().focusPreviousComponent();
    }
}//GEN-LAST:event_jTextAreaObservacaoKeyPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEditar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox jComboBoxCidade;
    private javax.swing.JComboBox jComboBoxUf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelBairro;
    private javax.swing.JLabel jLabelCEP;
    private javax.swing.JLabel jLabelCPF;
    private javax.swing.JLabel jLabelCelular;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelNascimento;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelObservacao;
    private javax.swing.JLabel jLabelRG;
    private javax.swing.JLabel jLabelTelefone;
    private javax.swing.JLabel jLabelUF;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextAreaObservacao;
    private javax.swing.JFormattedTextField jTextFieldBairro;
    private javax.swing.JFormattedTextField jTextFieldCEP;
    private javax.swing.JFormattedTextField jTextFieldCPF;
    private javax.swing.JFormattedTextField jTextFieldCelular;
    private javax.swing.JTextField jTextFieldCodigoAluno;
    private javax.swing.JTextField jTextFieldComplemento;
    private javax.swing.JFormattedTextField jTextFieldEmail;
    private javax.swing.JFormattedTextField jTextFieldEndereco;
    private javax.swing.JFormattedTextField jTextFieldNascimento;
    private javax.swing.JFormattedTextField jTextFieldNome;
    private javax.swing.JFormattedTextField jTextFieldNumero;
    private javax.swing.JFormattedTextField jTextFieldRG;
    private javax.swing.JFormattedTextField jTextFieldTelefone;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of view.AlunoView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.