Package view

Source Code of view.ContatoView

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

package view;

import controller.ContatoController;
import controller.operating.GerenciadorDeConfiguracoesDoSistema;
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 controller.operating.Strings;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import model.Contato;
import model.Pessoa;

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

    private enum  Modo {Edicao, Inclusao, Navegacao};   
    private Modo modo;
    public FormPesquisa pesquisa;
   
    /** Creates new form CandidatoView */
    public ContatoView() {
        initComponents();
        carregaTabela();
        modo = Modo.Navegacao;
    }
   
    public static void retornaBusca(){
        jTextFieldCodigoPessoa.setText(GerenciadorOperacional.getCodigo());
        jTextFieldNome.setText(GerenciadorOperacional.getDescricao());
        JButton[] listaBotoes = {jButtonConsultar, btnSalvar, btnCancelar};
        habilitaBotoes(listaBotoes, true);       
    }
   
    public static void cancelaBusca(){
        JButton[] listaBotoes = {jButtonConsultar, btnSalvar, btnCancelar};
        habilitaBotoes(listaBotoes, true);
    }
   
    private void habilitaCampos(Boolean pValor) {
        // TODO add your handling code here:
        Component[] c = jPanel1.getComponents();
        jTextAreaObjetivo.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("Selecione");
            }
        }
       jTextAreaObjetivo.setText("");
    }
     
    private static 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("Assunto");
        elementosDaTabela.addElement("Data");       
        elementosDaTabela.addElement("Objetivo");               
        elementosDaTabela.addElement("Canal");                                     
        ContatoController contatoCtrl= new ContatoController();                      
        DefaultTableModel modeloTabela = new DefaultTableModel(elementosDaTabela,0);
        modeloTabela = contatoCtrl.getTableContatos(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() {

        jPanel1 = new javax.swing.JPanel();
        jLabelObjetivo = new javax.swing.JLabel();
        jLabelNome = new javax.swing.JLabel();
        jLabelCanal = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelInicio = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JTextField();
        jComboBoxCanal = new javax.swing.JComboBox();
        jButtonConsultar = new javax.swing.JButton();
        jLabelTarefa = new javax.swing.JLabel();
        jComboBoxCategoria = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldAssunto = new javax.swing.JFormattedTextField();
        jTextFieldHorario = new javax.swing.JFormattedTextField();
        jTextFieldTermino = new javax.swing.JFormattedTextField();
        jTextFieldData = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObjetivo = new javax.swing.JTextArea();
        jTextFieldCodigoContato = new javax.swing.JTextField();
        jTextFieldCodigoPessoa = new javax.swing.JTextField();
        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();

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

        jLabelObjetivo.setText("Objetivo:");

        jLabelNome.setText("Nome:");

        jLabelCanal.setText("Canal:");
        jLabelCanal.setPreferredSize(new java.awt.Dimension(20, 14));

        jLabelEmail.setText("Término:");

        jLabelInicio.setText("Horário:");

        jTextFieldNome.setFocusable(false);
        jTextFieldNome.setName("Nome do Contato"); // NOI18N
        jTextFieldNome.setPreferredSize(new java.awt.Dimension(290, 20));

        jComboBoxCanal.setModel(new javax.swing.DefaultComboBoxModel(Strings.comboCanais));
        jComboBoxCanal.setName("Canal"); // NOI18N
        jComboBoxCanal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxCanalActionPerformed(evt);
            }
        });

        jButtonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/Pesquisar.png"))); // NOI18N
        jButtonConsultar.setText("Contactado");
        jButtonConsultar.setActionCommand("Pesquisar");
        jButtonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarActionPerformed(evt);
            }
        });

        jLabelTarefa.setText("Categoria:");

        jComboBoxCategoria.setModel(new javax.swing.DefaultComboBoxModel(Strings.comboCategorias));
        jComboBoxCategoria.setName("Tarefa"); // NOI18N

        jLabel1.setText("Assunto:");

        jTextFieldAssunto.setName("Assunto"); // NOI18N

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

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

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

        jLabel2.setText("Data:");

        jTextAreaObjetivo.setColumns(20);
        jTextAreaObjetivo.setLineWrap(true);
        jTextAreaObjetivo.setRows(5);
        jTextAreaObjetivo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextAreaObjetivoKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTextAreaObjetivo);

        jTextFieldCodigoContato.setEditable(false);
        jTextFieldCodigoContato.setText("jTextFieldCodigoContato");

        jTextFieldCodigoPessoa.setEditable(false);
        jTextFieldCodigoPessoa.setText("jTextFieldCodigoPessoa");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabelInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelCanal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabelNome)
                                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabelObjetivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldNome, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonConsultar))
                            .addComponent(jTextFieldAssunto, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jComboBoxCanal, 0, 194, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelTarefa, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldHorario, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(28, 28, 28)
                                        .addComponent(jLabelEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(2, 2, 2)
                                        .addComponent(jTextFieldTermino, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldData, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jComboBoxCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(115, 115, 115)
                        .addComponent(jTextFieldCodigoContato, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCodigoPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, 101, 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(jLabelNome)
                    .addComponent(jButtonConsultar)
                    .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(jLabel1)
                    .addComponent(jTextFieldAssunto, 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(jLabelCanal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTarefa)
                    .addComponent(jComboBoxCanal, 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(jLabelInicio)
                    .addComponent(jTextFieldHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabelEmail)
                    .addComponent(jTextFieldTermino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldCodigoContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldCodigoPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabelObjetivo))))
        );

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

            },
            new String [] {

            }
        ));
        jTable1.setDragEnabled(true);
        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);

        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)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        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)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .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, 224, Short.MAX_VALUE))
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </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();
        ContatoController contatoCtrl = new ContatoController();
        int linhaSelecionada = jTable1.getSelectedRow();
        String codigo = String.valueOf(jTable1.getValueAt(linhaSelecionada, 0));
        Contato contato = contatoCtrl.getContato(codigo);
        jTextFieldCodigoContato.setText(String.valueOf(contato.getCodigoContato()));
        jTextFieldCodigoPessoa.setText(String.valueOf(contato.getPessoa().getCodigoPessoa()));
        jTextFieldData.setText(contato.getData());
        jTextFieldAssunto.setText(contato.getAssunto());
        jTextFieldNome.setText(contato.getPessoa().getNome());
        jTextFieldTermino.setText(contato.getTermino());
        jTextFieldHorario.setText(contato.getHorario());
        jComboBoxCanal.setSelectedItem(contato.getCanalContato());
        jComboBoxCategoria.setSelectedItem(contato.getCategoria());
        jTextAreaObjetivo.setText(contato.getObjetivo());
   
        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:
    ContatoController contatoCtrl = new ContatoController();
    jButtonConsultar.requestFocus();
   
    modo = Modo.Inclusao;
    JButton[] ativaBotoes = {btnSalvar, btnCancelar, jButtonConsultar};
    habilitaBotoes(ativaBotoes, true);

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

    limpaCampos();
    jTextFieldCodigoContato.setText(contatoCtrl.getNovoCodigo());
    habilitaCampos(true);
    jTable1.setEnabled(false);
}//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, jButtonConsultar};
    habilitaBotoes(desativaBotoes, false);

    JButton[] ativaBotoes = {btnNovo, btnFechar, btnExcluir};
    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);
    if(GerenciadorDeConfiguracoesDoSistema.getUsarConexao()){
        jTextFieldCodigoContato.setVisible(false);
        jTextFieldCodigoPessoa.setVisible(false);
    }

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

private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed
// TODO add your handling code here:
    habilitaCampos(true);

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

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

private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
// TODO add your handling code here:
    ContatoController contatoCtrl = new ContatoController();
    String codigoSelecionado = jTextFieldCodigoContato.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 (contatoCtrl.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;

    if (jTextFieldNome.getText().isEmpty()){
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Nome"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextFieldNome.requestFocus();
    }else if (jTextFieldAssunto.getText().isEmpty()){
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Assunto"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextFieldAssunto.requestFocus();
    }else if (jTextFieldData.getText().equals("  /  /    ")){
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Data"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextFieldData.requestFocus();
    }else if (jTextAreaObjetivo.getText().isEmpty()){
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Objetivo"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextAreaObjetivo.requestFocus();
    }

    if(podeSalvar){
        Pessoa pessoa = new Pessoa();
        pessoa.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoPessoa.getText()));
       
        Contato contato = new Contato();
        contato.setCodigoContato(Integer.parseInt(jTextFieldCodigoContato.getText()));
        contato.setHorario(jTextFieldHorario.getText());
        contato.setTermino(jTextFieldTermino.getText());
        contato.setData(jTextFieldData.getText());
        contato.setAssunto(jTextFieldAssunto.getText());
        contato.setObjetivo(jTextAreaObjetivo.getText());
        contato.setCanalContato(jComboBoxCanal.getSelectedItem().toString());
        contato.setCategoria(jComboBoxCategoria.getSelectedItem().toString());
        contato.setPessoa(pessoa);
    
        ContatoController contatoController = new ContatoController();
        if (modo == Modo.Inclusao)
            salvou = contatoController.salvar(contato);
        else
            salvou = contatoController.atualizar(contato);      
       
        if(salvou){
            JButton[] desativaBotoes = {btnSalvar, btnCancelar, btnEditar, jButtonConsultar};
            habilitaBotoes(desativaBotoes, false);

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

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

private void jButtonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarActionPerformed
// TODO add your handling code here:
    if(modo != Modo.Navegacao){
        JButton[] listaBotoes = {jButtonConsultar, btnSalvar, btnCancelar};
        habilitaBotoes(listaBotoes, false);
        GerenciadorOperacional.getPesquisa("contato");       
    }else{
        JOptionPane.showMessageDialog(null, Strings.mensagemErroAcesso, Strings.tituloMessage, JOptionPane.INFORMATION_MESSAGE);
    }       
}//GEN-LAST:event_jButtonConsultarActionPerformed

private void jTextAreaObjetivoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextAreaObjetivoKeyPressed
// 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_jTextAreaObjetivoKeyPressed

private void jComboBoxCanalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxCanalActionPerformed
// TODO add your handling code here:
    if(jComboBoxCanal.getSelectedItem().equals("E-mail")){
        //jTextFieldHorario.setEnabled(false);
        jTextFieldTermino.setEnabled(false);
    }else{
        //jTextFieldHorario.setEnabled(true);
        jTextFieldTermino.setEnabled(true);
    }
}//GEN-LAST:event_jComboBoxCanalActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private static javax.swing.JButton btnCancelar;
    private static javax.swing.JButton btnEditar;
    private static javax.swing.JButton btnExcluir;
    private static javax.swing.JButton btnFechar;
    private static javax.swing.JButton btnNovo;
    private static javax.swing.JButton btnSalvar;
    private static javax.swing.JButton jButtonConsultar;
    private javax.swing.JComboBox jComboBoxCanal;
    private javax.swing.JComboBox jComboBoxCategoria;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelCanal;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelInicio;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelObjetivo;
    private javax.swing.JLabel jLabelTarefa;
    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 jTextAreaObjetivo;
    private static javax.swing.JFormattedTextField jTextFieldAssunto;
    private static javax.swing.JTextField jTextFieldCodigoContato;
    private static javax.swing.JTextField jTextFieldCodigoPessoa;
    private javax.swing.JFormattedTextField jTextFieldData;
    private javax.swing.JFormattedTextField jTextFieldHorario;
    private static javax.swing.JTextField jTextFieldNome;
    private javax.swing.JFormattedTextField jTextFieldTermino;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of view.ContatoView

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.