Ir para conteúdo
Fórum Script Brasil
  • 0

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexO


nicol store

Pergunta

private void initComponents() {  
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();  
  
        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("siscomjavaPU").createEntityManager();  
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT C FROM Cliente C");  
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());  
        jPanel1 = new javax.swing.JPanel();  
        masterScrollPane = new javax.swing.JScrollPane();  
        masterTable = new javax.swing.JTable();  
        masterScrollPane1 = new javax.swing.JScrollPane();  
        masterTable1 = new javax.swing.JTable();  
        newButton = new javax.swing.JButton();  
        deleteButton = new javax.swing.JButton();  
        jButton1 = new javax.swing.JButton();  
        jPanel2 = new javax.swing.JPanel();  
        detailScrollPane = new javax.swing.JScrollPane();  
        detailTable = new javax.swing.JTable();  
        detailScrollPane1 = new javax.swing.JScrollPane();  
        detailTable1 = new javax.swing.JTable();  
        saveButton = new javax.swing.JButton();  
        refreshButton = new javax.swing.JButton();  
        deleteDetailButton = new javax.swing.JButton();  
        newDetailButton = new javax.swing.JButton();  
  
        FormListener formListener = new FormListener();  
  
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 70, 213))); // NOI18N  
  
        masterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);  
  
        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);  
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nomeCliente}"));  
        columnBinding.setColumnName("Nome");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cpfCliente}"));  
        columnBinding.setColumnName("CPF");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rgCliente}"));  
        columnBinding.setColumnName("RG");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${orgaoRgCliente}"));  
        columnBinding.setColumnName("Órgão RG");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dataNascimentoCliente}"));  
        columnBinding.setColumnName("Data Nascimento");  
        columnBinding.setColumnClass(java.util.Date.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneCliente}"));  
        columnBinding.setColumnName("Fone Cliente");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${emailCliente}"));  
        columnBinding.setColumnName("Email");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${profissaoCliente}"));  
        columnBinding.setColumnName("Profissão");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${empresaCliente}"));  
        columnBinding.setColumnName("Empresa");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneEmpresa}"));  
        columnBinding.setColumnName("Fone Empresa");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rendaCliente}"));  
        columnBinding.setColumnName("Renda");  
        columnBinding.setColumnClass(Double.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tipoCliente}"));  
        columnBinding.setColumnName("Tipo Cliente");  
        columnBinding.setColumnClass(Character.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cnpjCliente}"));  
        columnBinding.setColumnName("CNPJ");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${referenciaCliente}"));  
        columnBinding.setColumnName("Referência");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneReferencia}"));  
        columnBinding.setColumnName("Fone Referência");  
        columnBinding.setColumnClass(String.class);  
        bindingGroup.addBinding(jTableBinding);  
        jTableBinding.bind();  
        masterScrollPane.setViewportView(masterTable);  
  
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nomeCliente}"));  
        columnBinding.setColumnName("Nome");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cpfCliente}"));  
        columnBinding.setColumnName("CPF");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rgCliente}"));  
        columnBinding.setColumnName("RG");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${orgaoRgCliente}"));  
        columnBinding.setColumnName("Órgão RG");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dataNascimentoCliente}"));  
        columnBinding.setColumnName("Data Nascimento");  
        columnBinding.setColumnClass(java.util.Date.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneCliente}"));  
        columnBinding.setColumnName("Fone Cliente");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${emailCliente}"));  
        columnBinding.setColumnName("Email");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${profissaoCliente}"));  
        columnBinding.setColumnName("Profissão");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${empresaCliente}"));  
        columnBinding.setColumnName("Empresa");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneEmpresa}"));  
        columnBinding.setColumnName("Fone Empresa");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rendaCliente}"));  
        columnBinding.setColumnName("Renda");  
        columnBinding.setColumnClass(Double.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${tipoCliente}"));  
        columnBinding.setColumnName("Tipo Cliente");  
        columnBinding.setColumnClass(Character.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cnpjCliente}"));  
        columnBinding.setColumnName("CNPJ");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${referenciaCliente}"));  
        columnBinding.setColumnName("Referência");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${foneReferencia}"));  
        columnBinding.setColumnName("Fone Referência");  
        columnBinding.setColumnClass(String.class);  
        bindingGroup.addBinding(jTableBinding);  
        jTableBinding.bind();  
        masterScrollPane1.setViewportView(masterTable1);  
        masterTable1.getColumnModel().getColumn(4).setPreferredWidth(110);  
        masterTable1.getColumnModel().getColumn(9).setPreferredWidth(100);  
        masterTable1.getColumnModel().getColumn(14).setPreferredWidth(110);  
  
        newButton.setText("Inserir Cliente");  
        newButton.addActionListener(formListener);  
  
        deleteButton.setText("Excluir Cliente");  
  
        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));  
        bindingGroup.addBinding(binding);  
  
        deleteButton.addActionListener(formListener);  
  
        jButton1.setText("Editar Cliente");  
  
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jButton1, org.jdesktop.beansbinding.BeanProperty.create("enabled"));  
        bindingGroup.addBinding(binding);  
  
        jButton1.addActionListener(formListener);  
  
        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.TRAILING)  
                    .addGroup(jPanel1Layout.createSequentialGroup()  
                        .addComponent(newButton)  
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                        .addComponent(jButton1)  
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                        .addComponent(deleteButton))  
                    .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 1126, javax.swing.GroupLayout.PREFERRED_SIZE))  
                .addContainerGap(20, Short.MAX_VALUE))  
        );  
  
        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteButton, newButton});  
  
        jPanel1Layout.setVerticalGroup(  
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()  
                .addContainerGap()  
                .addComponent(masterScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
                    .addComponent(deleteButton)  
                    .addComponent(newButton)  
                    .addComponent(jButton1))  
                .addContainerGap())  
        );  
  
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereços do Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 70, 213))); // NOI18N  
  
        detailTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);  
  
        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.clienteEnderecoCollection}");  
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cepEndereco}"));  
        columnBinding.setColumnName("CEP");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${logradouroEndereco}"));  
        columnBinding.setColumnName("Logradouro");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${complementoEndereco}"));  
        columnBinding.setColumnName("Complemento ");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cidadeEndereco}"));  
        columnBinding.setColumnName("Cidade");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${ufEndereco}"));  
        columnBinding.setColumnName("UF");  
        columnBinding.setColumnClass(String.class);  
        jTableBinding.setSourceUnreadableValue(null);  
        bindingGroup.addBinding(jTableBinding);  
        jTableBinding.bind();  
        detailScrollPane.setViewportView(detailTable);  
  
        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.clienteEnderecoCollection}");  
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cepEndereco}"));  
        columnBinding.setColumnName("CEP");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${logradouroEndereco}"));  
        columnBinding.setColumnName("Logradouro");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${complementoEndereco}"));  
        columnBinding.setColumnName("Complemento ");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cidadeEndereco}"));  
        columnBinding.setColumnName("Cidade");  
        columnBinding.setColumnClass(String.class);  
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${ufEndereco}"));  
        columnBinding.setColumnName("UF");  
        columnBinding.setColumnClass(String.class);  
        jTableBinding.setSourceUnreadableValue(null);  
        bindingGroup.addBinding(jTableBinding);  
        jTableBinding.bind();  
        detailScrollPane1.setViewportView(detailTable1);  
  
        saveButton.setText("Salvar");  
        saveButton.addActionListener(formListener);  
  
        refreshButton.setText("Cancelar Alterações");  
        refreshButton.addActionListener(formListener);  
  
        deleteDetailButton.setText("Excluir Endereço");  
  
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteDetailButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));  
        bindingGroup.addBinding(binding);  
  
        deleteDetailButton.addActionListener(formListener);  
  
        newDetailButton.setText("Inserir Endereço");  
  
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), newDetailButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));  
        bindingGroup.addBinding(binding);  
  
        newDetailButton.addActionListener(formListener);  
  
        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);  
        jPanel2.setLayout(jPanel2Layout);  
        jPanel2Layout.setHorizontalGroup(  
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(jPanel2Layout.createSequentialGroup()  
                .addContainerGap()  
                .addComponent(detailScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 1126, javax.swing.GroupLayout.PREFERRED_SIZE)  
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))  
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()  
                .addContainerGap(602, Short.MAX_VALUE)  
                .addComponent(newDetailButton)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addComponent(deleteDetailButton)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addComponent(refreshButton)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addComponent(saveButton)  
                .addContainerGap())  
        );  
  
        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteDetailButton, newDetailButton, refreshButton, saveButton});  
  
        jPanel2Layout.setVerticalGroup(  
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()  
                .addContainerGap()  
                .addComponent(detailScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)  
                    .addComponent(newDetailButton)  
                    .addComponent(saveButton)  
                    .addComponent(refreshButton)  
                    .addComponent(deleteDetailButton))  
                .addContainerGap())  
        );  
  
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);  
        this.setLayout(layout);  
        layout.setHorizontalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(layout.createSequentialGroup()  
                .addContainerGap()  
                .addGroup(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(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)  
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))  
        );  
        layout.setVerticalGroup(  
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
            .addGroup(layout.createSequentialGroup()  
                .addContainerGap()  
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)  
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)  
                .addGap(13, 13, 13))  
        );  
  
        bindingGroup.bind();  
    }  
  
    // Code for dispatching events from components to event handlers.  
  
    private class FormListener implements java.awt.event.ActionListener {  
        FormListener() {}  
        public void actionPerformed(java.awt.event.ActionEvent evt) {  
            if (evt.getSource() == newButton) {  
                ClienteView.this.newButtonActionPerformed(evt);  
            }  
            else if (evt.getSource() == deleteButton) {  
                ClienteView.this.deleteButtonActionPerformed(evt);  
            }  
            else if (evt.getSource() == jButton1) {  
                ClienteView.this.jButton1ActionPerformed(evt);  
            }  
            else if (evt.getSource() == saveButton) {  
                ClienteView.this.saveButtonActionPerformed(evt);  
            }  
            else if (evt.getSource() == refreshButton) {  
                ClienteView.this.refreshButtonActionPerformed(evt);  
            }  
            else if (evt.getSource() == deleteDetailButton) {  
                ClienteView.this.deleteDetailButtonActionPerformed(evt);  
            }  
            else if (evt.getSource() == newDetailButton) {  
                ClienteView.this.newDetailButtonActionPerformed(evt);  
            }  
        }  
    }// </editor-fold>  
  
    private void deleteDetailButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                     
        int index = masterTable.getSelectedRow();  
        br.com.siscom.bean.Cliente C = list.get(masterTable.convertRowIndexToModel(index));  
        Collection<br.com.siscom.bean.ClienteEndereco> cs = C.getClienteEnderecoCollection();  
        int[] selected = detailTable.getSelectedRows();  
        List<br.com.siscom.bean.ClienteEndereco> toRemove = new ArrayList<br.com.siscom.bean.ClienteEndereco>(selected.length);  
        for (int idx =0; idx < selected.length; idx++) {  
            selected[idx] = detailTable.convertRowIndexToModel(selected[idx]);  
            int count = 0;  
            Iterator<br.com.siscom.bean.ClienteEndereco> iter = cs.iterator();  
            while (count++ < selected[idx]) {  
                iter.next();  
            }  
            br.com.siscom.bean.ClienteEndereco c = iter.next();  
            toRemove.add(c);  
            entityManager.remove(c);  
        }  
        cs.removeAll(toRemove);  
        masterTable.clearSelection();  
        masterTable.setRowSelectionInterval(index, index);  
    }                                                    
  
    private void newDetailButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        int index = masterTable.getSelectedRow();  
        br.com.siscom.bean.Cliente C = list.get(masterTable.convertRowIndexToModel(index));  
        Collection<br.com.siscom.bean.ClienteEndereco> cs = C.getClienteEnderecoCollection();  
        if (cs == null) {  
            cs = new LinkedList<br.com.siscom.bean.ClienteEndereco>();  
            C.setClienteEnderecoCollection(cs);  
        }  
        br.com.siscom.bean.ClienteEndereco c = new br.com.siscom.bean.ClienteEndereco();  
        entityManager.persist(c);  
        c.setCodCliente(C);  
        cs.add(c);  
        masterTable.clearSelection();  
        masterTable.setRowSelectionInterval(index, index);  
        int row = cs.size() -1;  
        detailTable.setRowSelectionInterval(row, row);  
        detailTable.scrollRectToVisible(detailTable.getCellRect(row, 0, true));  
    }                                                 
  
    @SuppressWarnings("unchecked")  
    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
        entityManager.getTransaction().rollback();  
        entityManager.getTransaction().begin();  
        java.util.Collection data = query.getResultList();  
        for (Object entity : data) {  
            entityManager.refresh(entity);  
        }  
        list.clear();  
        list.addAll(data);  
    }                                               
  
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
        int[] selected = masterTable.getSelectedRows();  
        List<br.com.siscom.bean.Cliente> toRemove = new ArrayList<br.com.siscom.bean.Cliente>(selected.length);  
        for (int idx = 0; idx < selected.length; idx++) {  
            br.com.siscom.bean.Cliente C = list.get(masterTable.convertRowIndexToModel(selected[idx]));  
            toRemove.add(C);  
            entityManager.remove(C);  
        }  
        list.removeAll(toRemove);  
    }                                              
  
    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        br.com.siscom.bean.Cliente C = new br.com.siscom.bean.Cliente();  
        entityManager.persist(C);  
        list.add(C);  
        int row = list.size() -1;  
        masterTable.setRowSelectionInterval(row, row);  
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));  
  
        //JFrame frame = new JFrame();  
        ClienteEditView ce = new ClienteEditView(null, true);  
        ce.setRegistroAtual(C);  
        ce.setVisible(true);  
  
        if (ce.isConfirmaCliente()) {  
            saveButton.doClick();  
        } else {  
            refreshButton.doClick();  
        }  
    }                                           
  
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        try {  
            entityManager.getTransaction().commit();  
            entityManager.getTransaction().begin();  
        } catch (RollbackException rex) {  
            rex.printStackTrace();  
            entityManager.getTransaction().begin();  
            List<br.com.siscom.bean.Cliente> merged = new ArrayList<br.com.siscom.bean.Cliente>(list.size());  
            for (br.com.siscom.bean.Cliente C : list) {  
                merged.add(entityManager.merge(C));  
            }  
            list.clear();  
            list.addAll(merged);  
        }  
    }                                            
  
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    //JFrame frame = new JFrame();  
    ClienteEditView ce = new ClienteEditView(null, true);  
    ce.setRegistroAtual(list.get(masterTable.getSelectedRow()));  
    ce.setVisible(true);  
  
    if (ce.isConfirmaCliente()) {  
        saveButton.doClick();  
    } else {  
        refreshButton.doClick();  
    }  
}                                          
    // Variables declaration - do not modify  
    private javax.swing.JButton deleteButton;  
    private javax.swing.JButton deleteDetailButton;  
    private javax.swing.JScrollPane detailScrollPane;  
    private javax.swing.JScrollPane detailScrollPane1;  
    private javax.swing.JTable detailTable;  
    private javax.swing.JTable detailTable1;  
    private javax.persistence.EntityManager entityManager;  
    private javax.swing.JButton jButton1;  
    private javax.swing.JPanel jPanel1;  
    private javax.swing.JPanel jPanel2;  
    private java.util.List<br.com.siscom.bean.Cliente> list;  
    private javax.swing.JScrollPane masterScrollPane;  
    private javax.swing.JScrollPane masterScrollPane1;  
    private javax.swing.JTable masterTable;  
    private javax.swing.JTable masterTable1;  
    private javax.swing.JButton newButton;  
    private javax.swing.JButton newDetailButton;  
    private javax.persistence.Query query;  
    private javax.swing.JButton refreshButton;  
    private javax.swing.JButton saveButton;  
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;  
    // End of variables declaration  
  
    public static void main(final String[] args) {  
        EventQueue.invokeLater(new Runnable() {  
  
            public void run() {  
                JFrame frame = new JFrame();  
                frame.setContentPane(new ClienteView());  
                //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                frame.pack();  
                frame.setVisible(true);  
                frame.setTitle(args[0]);  
            }  
        });  
    }  
}

Editado por nicol store
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...