Package org.salamanca.ui

Source Code of org.salamanca.ui.ValeFrame_this_internalFrameAdapter

package org.salamanca.ui;

import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.FlowLayout;
import componenteTabla.compomenteABMCList;
import org.salamanca.domain.*;
import java.util.Vector;
import java.text.SimpleDateFormat;
import componenteTabla.InsertarEvent;
import componenteTabla.InsertarListener;
import java.util.Date;
import org.salamanca.commands.CommandFactory;
import org.salamanca.commands.ICommand;
import java.text.ParseException;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameAdapter;
import org.salamanca.broker.BrokerServer;
import componenteTabla.EliminarEvent;
import componenteTabla.EliminarListener;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ValeFrame extends JInternalFrame {


    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    BorderLayout borderLayout2 = new BorderLayout();
    JLabel jLabel1 = new JLabel();
    FlowLayout flowLayout1 = new FlowLayout();

    compomenteABMCList compomenteABMCListVales = new
                                                 compomenteABMCList();
    MainFrame mainFrame;
    Persona persona;
    JPanel jPanel3 = new JPanel();
    JButton jButtonUtilizarVale = new JButton();
    JButton jButtonDeshacerUtilizacion = new JButton();

    public ValeFrame() {

        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public void loadPersona(MainFrame mainFrame, Persona persona) {
        this.mainFrame = mainFrame;
        this.persona = persona;
        loadList();
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(borderLayout1);
        compomenteABMCListVales.addInsertarListener(new
                ValeFrame_compomenteABMCListVales_insertarAdapter(this));
        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        this.addInternalFrameListener(new ValeFrame_this_internalFrameAdapter(this));
        compomenteABMCListVales.addEliminarListener(new
                ValeFrame_compomenteABMCListVales_eliminarAdapter(this));
        jButtonUtilizarVale.setText("Utilizar");
        jButtonUtilizarVale.addActionListener(new
                ValeFrame_jButtonUtilizarVale_actionAdapter(this));
        jButtonDeshacerUtilizacion.setText("Deshacer Utilizaci�n");
        jButtonDeshacerUtilizacion.addActionListener(new
                ValeFrame_jButtonDeshacerUtilizacion_actionAdapter(this));
        this.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
        jLabel1.setFont(new java.awt.Font("Arial", Font.BOLD, 14));
        jLabel1.setText("Vales");
        jPanel1.setLayout(flowLayout1);
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setLayout(borderLayout2);
        jPanel1.add(jLabel1, null);
        jPanel2.add(compomenteABMCListVales, java.awt.BorderLayout.CENTER);
        this.getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
        jPanel3.add(jButtonUtilizarVale);
        jPanel3.add(jButtonDeshacerUtilizacion);

        this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
        jPanel3.add(jButtonDeshacerUtilizacion);
        compomenteABMCListVales.setVisibleCantidadRegistros(true);
        compomenteABMCListVales.setVisibleBuscar(true);
        compomenteABMCListVales.setInfoColumna(new String[][] { {"nombre",
                                               "tipo", "editable", "editor",
                                               "val.Combo", "Ancho Columna"}
                                               , {"Importe", "Double",
                                               "true", "comun", "", "80"}

                                               , {"Fecha de emisi�n",
                                               "String", "false", "comun", "",
                                               "140"}

                                               , {"Fecha de utilizaci�n",
                                               "String", "false", "comun", "",
                                               "140"}

                                               , {"oid", "String",
                                               "false", "comun", "", "1"}
        });
        compomenteABMCListVales.setPrimaryKeyColumn(3); //es el DNI
        compomenteABMCListVales.setVisibleAgregar(true);
        compomenteABMCListVales.setVisibleOrdenar(false);
        compomenteABMCListVales.setVisibleModificar(false);
        compomenteABMCListVales.setVisibleImprimir(true);
        compomenteABMCListVales.setVisibleGuardarComo(false);
        compomenteABMCListVales.setVisibleHeaderTabla(true);
        compomenteABMCListVales.setVisibleFiltrar(false);
        compomenteABMCListVales.setVisibleEliminar(true);
        compomenteABMCListVales.setVisibleCopyclipboard(true);
        compomenteABMCListVales.setVisibleReportes(true);
        compomenteABMCListVales.setEditableBoolean(false);

        compomenteABMCListVales.setTituloImprimir("Vales");

    }

    /**
     * loadList
     */
    private void loadList() {
      //actualizo la persona
        persona = (Persona)BrokerServer.instance().getPMF().getPersistenceManager().
                  getObjectById(javax.jdo.JDOHelper.getObjectId(persona) , true);

                try {
            compomenteABMCListVales.clearDatos();
            if (this.persona.getSetVale() != null) { //puede ser nulo porque en el schema evolution
                //en principio no existia este campo
                Vector v = new Vector(this.persona.getSetVale());

                if ((v != null) && (v.size() > 0)) {
                    Object[][] trabajo = new Object[v.size()][4];
                    for (int i = 0; i < v.size(); i++) {
                        Vale vale = (Vale) v.elementAt(i);
                        trabajo[i][0] = new Double(vale.getImporte());
                        SimpleDateFormat dateFormatInicio = new
                                SimpleDateFormat(
                                        "d-M-yyyy");
                        trabajo[i][1] = dateFormatInicio.format(vale.
                                getFechaEmision());
                        if (vale.getFechaUtilizacion() != null) {
                            trabajo[i][2] = dateFormatInicio.format(vale.
                                    getFechaUtilizacion());
                        }
                        trabajo[i][3] = javax.jdo.JDOHelper.
                                        getObjectId(vale).toString();
                    }
                    compomenteABMCListVales.setDatos(trabajo);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    /**
     * compomenteABMCListVales_Insercion
     *
     * @param e InsertarEvent
     */
    public void compomenteABMCListVales_Insercion(InsertarEvent e) {
        Vale vale = new Vale();
        double importe = ((Double) ((Vector) e.getVector()).elementAt(0)).
                         doubleValue();

        Date fechaEmision = new Date();
        vale.setImporte(importe);
        vale.setFechaEmision(fechaEmision);

        ICommand insertarVale = CommandFactory.createInsertarVale(vale, persona);
        try {
            insertarVale.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }

        loadList();
    }

    /**
     * this_internalFrameClosing
     *
     * @param e InternalFrameEvent
     */
    public void this_internalFrameClosing(InternalFrameEvent e) {
        this.mainFrame.personaFrame.setVisible(true);
    }

    public void compomenteABMCListVales_Eliminacion(EliminarEvent e) {
        String oidStr = ((String) ((Vector) e.getVector()).elementAt(3));
        kodo.util.Id oid = new kodo.util.Id(oidStr);

        Vale vale = (Vale) BrokerServer.instance().getPMF().
                          getPersistenceManager().getObjectById(oid,true);

        ICommand eiminarVale = CommandFactory.createEliminarVale(vale);
        try {
            eiminarVale.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
            loadList();

        }
        loadList();
    }

    /**
     * jButtonUtilizarVale_actionPerformed
     *
     * @param e ActionEvent
     */
    public void jButtonUtilizarVale_actionPerformed(ActionEvent e) {

        if (compomenteABMCListVales.getSelectedRow() != -1) {
            String oidStr = ((String) compomenteABMCListVales.
                             getSelectedRowData().
                             getValueAt(3));
            kodo.util.Id oid = new kodo.util.Id(oidStr);
            Vale vale = (Vale) BrokerServer.instance().getPMF().
                        getPersistenceManager().getObjectById(oid, true);

            ICommand utilizarVale = CommandFactory.createUtilizarVale(vale);
            try {
                utilizarVale.execute();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
                loadList();

            }
            loadList();
        }
    }

    public void jButtonDeshacerUtilizacion_actionPerformed(ActionEvent e) {
        if (compomenteABMCListVales.getSelectedRow() != -1) {
            String oidStr = ((String) compomenteABMCListVales.
                             getSelectedRowData().
                             getValueAt(3));
            kodo.util.Id oid = new kodo.util.Id(oidStr);
            Vale vale = (Vale) BrokerServer.instance().getPMF().
                        getPersistenceManager().getObjectById(oid, true);

            ICommand deshacerUtilizarVale = CommandFactory.createDeshacerUtilizacionVale(vale);
            try {
                deshacerUtilizarVale.execute();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, ex.getMessage());
                loadList();

            }
            loadList();
        }
    }
}


class ValeFrame_jButtonDeshacerUtilizacion_actionAdapter implements
        ActionListener {
    private ValeFrame adaptee;
    ValeFrame_jButtonDeshacerUtilizacion_actionAdapter(ValeFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButtonDeshacerUtilizacion_actionPerformed(e);
    }
}


class ValeFrame_jButtonUtilizarVale_actionAdapter implements ActionListener {
    private ValeFrame adaptee;
    ValeFrame_jButtonUtilizarVale_actionAdapter(ValeFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButtonUtilizarVale_actionPerformed(e);
    }
}


class ValeFrame_this_internalFrameAdapter extends InternalFrameAdapter {
    private ValeFrame adaptee;
    ValeFrame_this_internalFrameAdapter(ValeFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void internalFrameClosing(InternalFrameEvent e) {
        adaptee.this_internalFrameClosing(e);
    }
}


class ValeFrame_compomenteABMCListVales_eliminarAdapter implements
        EliminarListener {
    private ValeFrame adaptee;
    ValeFrame_compomenteABMCListVales_eliminarAdapter(ValeFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void Eliminacion(EliminarEvent e) {
        adaptee.compomenteABMCListVales_Eliminacion(e);
    }
}


class ValeFrame_compomenteABMCListVales_insertarAdapter implements
        InsertarListener {
    private ValeFrame adaptee;
    ValeFrame_compomenteABMCListVales_insertarAdapter(ValeFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void Insercion(InsertarEvent e) {
        adaptee.compomenteABMCListVales_Insercion(e);
    }
}
TOP

Related Classes of org.salamanca.ui.ValeFrame_this_internalFrameAdapter

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.