Package view

Source Code of view.EmpresaView

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

package view;

import controller.EmpresaController;
import controller.operating.GerenciadorOperacional;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JButton;
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 javax.swing.JComboBox;
import model.Empresa;
import model.Endereco;

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

       
    private enum  Modo {Edicao, Inclusao, Navegacao};
    private Modo modo;
   
    /** Creates new form EmpresaView */
    public EmpresaView() {
        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(){
        EmpresaController empresaCtrl = new EmpresaController();
        Vector<String> vetColunas = new Vector<String>();
        vetColunas.addElement("Código");
        vetColunas.addElement("Razão Social");
        vetColunas.addElement("E-mail");       
        vetColunas.addElement("Telefone");               
        vetColunas.addElement("Fax");                       
        DefaultTableModel modeloTabela = new DefaultTableModel(vetColunas,0);
        modeloTabela = empresaCtrl.getTableEmpresas(modeloTabela, "cadastro");
        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();
        jLabelCodigo = new javax.swing.JLabel();
        jLabelRazao = new javax.swing.JLabel();
        jLabelEmail = new javax.swing.JLabel();
        jLabelTelefone = new javax.swing.JLabel();
        jLabelCNPJ = new javax.swing.JLabel();
        jLabelIE = new javax.swing.JLabel();
        jTextFieldRazao = new javax.swing.JFormattedTextField();
        jTextFieldCNPJ = new javax.swing.JFormattedTextField();
        jTextFieldIE = new javax.swing.JFormattedTextField();
        jTextFieldCodigoEmpresa = new javax.swing.JTextField();
        jTextFieldTelefone = new javax.swing.JFormattedTextField();
        jTextFieldEmail = new javax.swing.JFormattedTextField();
        jLabelFax = new javax.swing.JLabel();
        jTextFieldFax = 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("Empresa");
        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);

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

        jLabelRazao.setText("Razão:");

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

        jLabelTelefone.setText("Telefone:");

        jLabelCNPJ.setText("CNPJ:");

        jLabelIE.setText("IE:");

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

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

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

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

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

        jLabelFax.setText("Fax:");

        try {
            jTextFieldFax.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTextFieldFax.setName("Fax"); // 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(jLabelCNPJ)
                            .addComponent(jLabelTelefone))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldCodigoEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabelRazao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldRazao, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jTextFieldCNPJ, 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(jLabelIE, 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(jTextFieldIE, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabelFax)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldFax, javax.swing.GroupLayout.DEFAULT_SIZE, 131, 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)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxCidade, 0, 203, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .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(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)))))
                .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(jTextFieldCodigoEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelRazao)
                    .addComponent(jTextFieldRazao, 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(jLabelCNPJ)
                    .addComponent(jTextFieldCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelIE, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldIE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelFax)
                    .addComponent(jTextFieldFax, 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(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.UNRELATED)
                .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(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldComplemento, 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.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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 548, 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)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
        );

        setBounds(10, 10, 558, 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();
        EmpresaController empresaCtrl = new EmpresaController();
        int linhaSelecionada = jTable1.getSelectedRow();
        String codigo = String.valueOf(jTable1.getValueAt(linhaSelecionada, 0));
        Empresa empresa = empresaCtrl.getEmpresa(codigo);   
        jTextFieldCodigoEmpresa.setText(String.valueOf(empresa.getCodigoPessoa()));
        jTextFieldRazao.setText(empresa.getRazaosocial());
        jTextFieldEmail.setText(empresa.getEmail());
        jTextFieldIE.setText(empresa.getIe());
        jTextFieldFax.setText(empresa.getFax());
        jTextFieldBairro.setText(empresa.getEndereco().getBairro());
        jTextFieldCEP.setText(empresa.getEndereco().getCep());
        jTextFieldComplemento.setText(empresa.getEndereco().getComplemento());
        jTextFieldCNPJ.setText(empresa.getCnpj());
        jTextFieldEndereco.setText(empresa.getEndereco().getLogradouro());
        jTextFieldNumero.setText(empresa.getEndereco().getNumero());
        jTextFieldTelefone.setText(empresa.getTelefone());
        jComboBoxUf.setSelectedItem(empresa.getEndereco().getUf());
        jComboBoxCidade.setSelectedItem(empresa.getEndereco().getNomeCidade());
        jTextAreaObservacao.setText(empresa.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:   
    jTextFieldRazao.requestFocus();
       
    JButton[] ativaBotoes = {btnSalvar, btnCancelar};
    habilitaBotoes(ativaBotoes, true);

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

    limpaCampos();
   
    EmpresaController empresaCtrl = new EmpresaController();
    jTextFieldCodigoEmpresa.setText(empresaCtrl.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);
    jTextFieldRazao.requestFocus();
   
    JButton[] desativaBotoes = {btnNovo, btnEditar, btnFechar, btnExcluir};
    habilitaBotoes(desativaBotoes, false);

    JButton[] ativaBotoes = {btnSalvar, btnCancelar};
    habilitaBotoes(ativaBotoes, true);
   
    jTextFieldCodigoEmpresa.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:
    EmpresaController empresaCtrl = new EmpresaController();
    String codigoSelecionado = jTextFieldCodigoEmpresa.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 (empresaCtrl.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 (jTextFieldRazao.getText().isEmpty()) {
        podeSalvar = false;
        JOptionPane.showMessageDialog(this, Strings.getMensagemValidacao("Razão Social"), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        jTextFieldRazao.requestFocus();
    }
   
   if(podeSalvar){
        Pessoa pessoa = new Pessoa();
        pessoa.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoEmpresa.getText()));
       
        Endereco endereco = new Endereco(
                jTextFieldEndereco.getText(),
                jTextFieldNumero.getText(),
                jTextFieldBairro.getText(),
                jTextFieldCEP.getText(),
                jTextFieldComplemento.getText(),
                jComboBoxCidade.getSelectedItem().toString(),
                jComboBoxUf.getSelectedItem().toString(),
                pessoa);
       
        Empresa empresa = new Empresa();
        empresa.setCodigoEmpresa(Integer.parseInt(jTextFieldCodigoEmpresa.getText()));
        empresa.setCodigoPessoa(Integer.parseInt(jTextFieldCodigoEmpresa.getText()));
        empresa.setNome(jTextFieldRazao.getText());
        empresa.setEmail(jTextFieldEmail.getText());
        empresa.setTelefone(jTextFieldTelefone.getText());
        empresa.setCelular(" - ");
        empresa.setRazaosocial(jTextFieldRazao.getText());
        empresa.setCnpj(jTextFieldCNPJ.getText());
        empresa.setIe(jTextFieldIE.getText());
        empresa.setFax(jTextFieldFax.getText());
        empresa.setObservacao(jTextAreaObservacao.getText());
        empresa.setEndereco(endereco);
       
        EmpresaController empresaController = new EmpresaController();

        if (modo.equals(Modo.Inclusao)){
            salvou = empresaController.salvar(empresa);
        }else{
            salvou = empresaController.atualizar(empresa);
        }      
       
        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 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 jLabelCNPJ;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelFax;
    private javax.swing.JLabel jLabelIE;
    private javax.swing.JLabel jLabelNumero;
    private javax.swing.JLabel jLabelObservacao;
    private javax.swing.JLabel jLabelRazao;
    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 jTextFieldCNPJ;
    private javax.swing.JTextField jTextFieldCodigoEmpresa;
    private javax.swing.JTextField jTextFieldComplemento;
    private javax.swing.JFormattedTextField jTextFieldEmail;
    private javax.swing.JFormattedTextField jTextFieldEndereco;
    private javax.swing.JFormattedTextField jTextFieldFax;
    private javax.swing.JFormattedTextField jTextFieldIE;
    private javax.swing.JFormattedTextField jTextFieldNumero;
    private javax.swing.JFormattedTextField jTextFieldRazao;
    private javax.swing.JFormattedTextField jTextFieldTelefone;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of view.EmpresaView

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.