Package view

Source Code of view.CandidatoView

/*
* CandidatoView.java
*
* Created on 13 de Setembro de 2008, 11:48
*/
package view;

import controller.CandidatoController;
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.Candidato;
import model.Endereco;
import model.Pessoa;
import controller.operating.Strings;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import util.DocumentoDeTamanhoFixo;

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

    private enum Modo {Edicao, Inclusao, Navegacao};
    private Modo modo;

    /** Creates new form CandidatoView */
    public CandidatoView() {
        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("Celular");
        elementosDaTabela.addElement("Lattes");
        CandidatoController candidatoCtrl = new CandidatoController();
        DefaultTableModel modeloTabela = new DefaultTableModel(elementosDaTabela, 0);
        modeloTabela = candidatoCtrl.getTableCandidatos(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() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        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();
        jPanel1 = new javax.swing.JPanel();
        jLabelObservacao = new javax.swing.JLabel();
        jLabelCodigo = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        jLabelCidade = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelCelular = new javax.swing.JLabel();
        jLabelBairro = new javax.swing.JLabel();
        jLabelEndereco = new javax.swing.JLabel();
        jLabelTelefone = new javax.swing.JLabel();
        jLabelCPF = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacao = new javax.swing.JTextArea();
        jLabelUF = new javax.swing.JLabel();
        jLabelRG = new javax.swing.JLabel();
        jLabelNumero = new javax.swing.JLabel();
        jLabelCEP = new javax.swing.JLabel();
        jLabelLattes = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JFormattedTextField();
        jComboBoxUf = new javax.swing.JComboBox();
        jComboBoxCidade = new javax.swing.JComboBox();
        jTextFieldCPF = new javax.swing.JFormattedTextField();
        jTextFieldRG = new javax.swing.JFormattedTextField();
        jTextFieldCodigoCandidato = new javax.swing.JTextField();
        jTextFieldTelefone = new javax.swing.JFormattedTextField();
        jTextFieldCelular = new javax.swing.JFormattedTextField();
        jTextFieldEmail = new javax.swing.JFormattedTextField();
        jTextFieldLattes = new javax.swing.JFormattedTextField();
        jTextFieldEndereco = new javax.swing.JFormattedTextField();
        jTextFieldNumero = new javax.swing.JFormattedTextField();
        jLabelNascimento = new javax.swing.JLabel();
        jTextFieldNascimento = new javax.swing.JFormattedTextField();
        jTextFieldBairro = new javax.swing.JFormattedTextField();
        jTextFieldCEP = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldComplemento = new javax.swing.JTextField();
        jTextFieldTitulacao = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Candidato");
        setAutoscrolls(true);
        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);
            }
        });

        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);

        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);

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

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

        jLabelNome.setText("Nome:");

        jLabelCidade.setText("Cidade:");

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

        jLabelCelular.setText("Celular:");

        jLabelBairro.setText("Bairro:");

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

        jLabelTelefone.setText("Telefone:");

        jLabelCPF.setText("CPF:");

        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);

        jLabelUF.setText("UF:");

        jLabelRG.setText("RG:");

        jLabelNumero.setText("N°:");

        jLabelCEP.setText("CEP:");

        jLabelLattes.setText("Lattes:");

        jTextFieldNome.setDocument(new DocumentoDeTamanhoFixo(20));
        jTextFieldNome.setName("Nome"); // NOI18N

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

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

        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

        jTextFieldCodigoCandidato.setEditable(false);
        jTextFieldCodigoCandidato.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);

        jTextFieldLattes.setName("Currículo Lattes"); // NOI18N

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

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

        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

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

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

        jLabel1.setText("Complemento:");

        jLabel2.setText("Titulação:");

        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()
                        .addComponent(jLabelObservacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelCodigo)
                            .addComponent(jLabelCPF)
                            .addComponent(jLabelTelefone)
                            .addComponent(jLabelEndereco)
                            .addComponent(jLabelBairro)
                            .addComponent(jLabelCEP)
                            .addComponent(jLabel2))
                        .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)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelCidade)
                                .addGap(18, 18, 18)
                                .addComponent(jComboBoxCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelUF)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxUf, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldCodigoCandidato, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelNome)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jTextFieldTelefone, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldCPF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelRG, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelCelular))
                                .addGap(7, 7, 7)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldRG, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabelNascimento)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabelEmail)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldBairro, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                                .addGap(10, 10, 10)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .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, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldTitulacao, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabelLattes)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldLattes, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jComboBoxUf, jTextFieldNumero});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabelNumero, jLabelUF});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCodigo)
                    .addComponent(jTextFieldCodigoCandidato, 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(jTextFieldNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .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(jLabelNascimento)
                    .addComponent(jTextFieldRG, 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(jLabelTelefone)
                    .addComponent(jTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCelular)
                    .addComponent(jLabelEmail)
                    .addComponent(jTextFieldEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCelular, 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(jLabel2)
                    .addComponent(jTextFieldLattes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelLattes)
                    .addComponent(jTextFieldTitulacao, 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(jLabelEndereco)
                    .addComponent(jLabelNumero)
                    .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNumero, 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(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .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)
                    .addComponent(jComboBoxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelUF))
                .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.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        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, 541, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 541, 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, 551, 544);
    }// </editor-fold>//GEN-END:initComponents

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

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

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 btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
    // TODO add your handling code here:
    CandidatoController candidatoCtrl = new CandidatoController();
    jTextFieldNome.requestFocus();

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

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

    limpaCampos();
    jTextFieldCodigoCandidato.setText(candidatoCtrl.getNovoCodigo());
    habilitaCampos(true);
    jTable1.setEnabled(false);
   
    modo = Modo.Inclusao;
}//GEN-LAST:event_btnNovoActionPerformed

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 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 btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
// TODO add your handling code here:
    habilitaCampos(true);

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

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

    jTextFieldCodigoCandidato.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:
    CandidatoController candidatoCtrl = new CandidatoController();
    String codigoSelecionado = jTextFieldCodigoCandidato.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 (candidatoCtrl.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 btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
    // TODO add your handling code here:
    boolean podeSalvar = true;
    boolean salvou = false;
    /**
     * Esse trecho aqui valida os campos que se precisa
     */
    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(jTextFieldCodigoCandidato.getText()));
       
        Endereco endereco = new Endereco(
                jTextFieldEndereco.getText(),
                jTextFieldNumero.getText(),
                jTextFieldBairro.getText(),
                jTextFieldCEP.getText(),
                jTextFieldComplemento.getText(),
                jComboBoxCidade.getSelectedItem().toString(),
                jComboBoxUf.getSelectedItem().toString(),
                pessoa);

        Candidato candidato = new Candidato();       
        candidato.setCodigoCandidato(Integer.parseInt(jTextFieldCodigoCandidato.getText()));
        candidato.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoCandidato.getText()));
        candidato.setNome(jTextFieldNome.getText());
        candidato.setEmail(jTextFieldEmail.getText());
        candidato.setTelefone(jTextFieldTelefone.getText());
        candidato.setCelular(jTextFieldCelular.getText());       
        candidato.setRg(jTextFieldRG.getText());
        candidato.setCpf(jTextFieldCPF.getText());
        candidato.setNascimento(jTextFieldNascimento.getText());
        candidato.setLattes(jTextFieldLattes.getText());
        candidato.setObservacao(jTextAreaObservacao.getText());
        candidato.setEndereco(endereco);

        CandidatoController candidatoController = new CandidatoController();

        if (modo == Modo.Inclusao) {
            salvou = candidatoController.salvar(candidato);
        } else {
            salvou = candidatoController.atualizar(candidato);
        }
        if (salvou) {
            JButton[] desativaBotoes = {btnSalvar, btnCancelar, btnExcluir,btnEditar};
            habilitaBotoes(desativaBotoes, false);

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

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

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 jLabel2;
    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 jLabelLattes;
    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 jTextFieldCodigoCandidato;
    private javax.swing.JTextField jTextFieldComplemento;
    private javax.swing.JFormattedTextField jTextFieldEmail;
    private javax.swing.JFormattedTextField jTextFieldEndereco;
    private javax.swing.JFormattedTextField jTextFieldLattes;
    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.JFormattedTextField jTextFieldTitulacao;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of view.CandidatoView

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.