/*
 * VistaPpal.java
 *
 * Created on 19. leden 2006, 13:46
 */

package Vistas;

import Modelo.Cliente;
import Modelo.Controlador;
import Modelo.Sucursal;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;

/**
 *
 * @author  jungi
 */
public class jfrmVistaPpalPersistencia extends javax.swing.JFrame {
    Sucursal sucAux = new Sucursal();
    JFrame auxJf;
    Controlador cBD=new Controlador();
    /**
    * Creates new form VistaPpal
    */
    public jfrmVistaPpalPersistencia(Sucursal suc,JFrame jf) {
	sucAux=suc;
    auxJf=jf;
    initComponents();
	//cBD.setUpDB();
	jList1.setListData(cBD.getData().toArray(new Object[] {}));
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jList1 = new javax.swing.JList();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        addMItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lista de Clientes");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Clientes Actuales:");

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

        jMenu1.setText("Menu");

        addMItem.setText("Añadir Cliente...");
        addMItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMItemActionPerformed(evt);
            }
        });
        jMenu1.add(addMItem);
        jMenu1.add(jSeparator1);

        jMenuItem3.setText("Salir");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jList1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jList1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void addMItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMItemActionPerformed
// TODO add your handling code here:
	jfrmInsCliente dlg = new jfrmInsCliente(this, sucAux,true);
	dlg.setVisible(true);
	Cliente c =dlg.getCliente();
	if (c != null) {
	    cBD.persist(c);
	    jList1.setListData(cBD.getData().toArray(new Object[] {}));
	}
    }//GEN-LAST:event_addMItemActionPerformed
    
    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
// TODO add your handling code here:
	setVisible(false);
	System.exit(0);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        auxJf.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing
    
    /**
     * @param args the command line arguments
     
    public static void main(String args[]) {
	java.awt.EventQueue.invokeLater(new Runnable() {
	    public void run() {
		new jfrmVistaPpalPersistencia().setVisible(true);
	    }
	});
    }*/
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JMenuItem addMItem;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JList jList1;
    public javax.swing.JMenu jMenu1;
    public javax.swing.JMenuBar jMenuBar1;
    public javax.swing.JMenuItem jMenuItem3;
    public javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
