Package org.salamanca.ui

Source Code of org.salamanca.ui.CursoFrame_compomenteABMCListCursos_modificarAdapter

package org.salamanca.ui;

import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JList;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.*;
import java.util.Vector;
import org.salamanca.domain.Curso;
import java.util.*;
import javax.swing.DefaultListModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.salamanca.commands.curso.*;
import javax.swing.text.*;
import java.text.SimpleDateFormat;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import org.salamanca.broker.BrokerServer;
import org.salamanca.domain.User;
import org.salamanca.commands.MessageException;
import componenteTabla.compomenteABMCList;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.text.ParseException;
import java.text.NumberFormat;
import componenteTabla.InsertarEvent;
import componenteTabla.InsertarListener;
import componenteTabla.EliminarEvent;
import componenteTabla.EliminarListener;
import org.jdoinstruments.runtime.discfilemodel.util.DirectOID;
import componenteTabla.ModificarEvent;
import componenteTabla.ModificarListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import componenteTabla.BaseDatosAccess;
import java.util.prefs.Preferences;
import org.salamanca.commands.CommandFactory;
import org.salamanca.commands.ICommand;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CursoFrame extends JInternalFrame {
    int year;
    DefaultListModel model = new DefaultListModel();
    compomenteABMCList compomenteABMCListCursos = new
                                                  compomenteABMCList();

    NumberFormat numberFormat = NumberFormat.getIntegerInstance();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    SimpleDateFormat dateFormatInicio = new SimpleDateFormat("d-M-yyyy");
    SimpleDateFormat dateFormatFin = new SimpleDateFormat("d-M-yyyy");
    JButton jButtonDefinirCuotas = new JButton();
    JLabel jLabel5 = new JLabel();
    JFormattedTextField jFormattedTextFieldYear = new JFormattedTextField();
    JLabel jLabel6 = new JLabel();
    BorderLayout borderLayout1 = new BorderLayout();
    MainFrame mainFrame;

    CuotasFrame cuotasFrame;

    public CursoFrame(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        cuotasFrame = new CuotasFrame(this);

        try {
            jbInit();
            loadTextFieldYear();
            initCuotasFrame();

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

    private void initCuotasFrame() {
        cuotasFrame.setSize(490, 520);
        cuotasFrame.setClosable(true);
        cuotasFrame.setIconifiable(false);
        this.mainFrame.getContentPane().add(cuotasFrame);
    }


    private void loadTextFieldYear() {

        Date actual = new Date();
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(actual);
        String a�oDefault = String.valueOf(cal.get(cal.YEAR));
        //grabo en las preferencias
        Preferences prefs = Preferences.userNodeForPackage(CursoFrame.class);
        String yearStr = prefs.get("A�o", a�oDefault);

        this.jFormattedTextFieldYear.setText(yearStr);

        try {
            year = numberFormat.parse(this.jFormattedTextFieldYear.
                                      getText()).intValue();
            this.loadListCursos(year);
        } catch (ParseException ex) {
            JOptionPane.showMessageDialog(this, "Fecha erronea");
        }

    }

    /**
     * loadList
     */
    private void loadListCursos(int year) {
        try {

            GregorianCalendar calMin = new GregorianCalendar(year, 0, 1);
            GregorianCalendar calMax = new GregorianCalendar(year, 11, 31);

            Date dateMin = calMin.getTime();
            Date dateMax = calMax.getTime();

            compomenteABMCListCursos.clearDatos();

            Vector v = org.salamanca.broker.BrokerServer.instance().
                       queryParameter(
                               Curso.class, "import java.util.Date",
                               "java.util.Date dateMin, java.util.Date dateMax",
                               "fechaInicio>=dateMin && fechaInicio<=dateMax",
                               dateMin, dateMax);
            if ((v != null) && (v.size() > 0)) {
                Object[][] trabajo = new Object[v.size()][7];
                for (int i = 0; i < v.size(); i++) {
                    Curso curso = (Curso) v.elementAt(i);
                    trabajo[i][0] = curso.getNombre();
                    trabajo[i][1] = curso.getObservaciones();
                    SimpleDateFormat dateFormatInicio = new SimpleDateFormat(
                            "d-M-yyyy");
                    trabajo[i][2] = Integer.valueOf(curso.getCantidadPeriodos());
                    trabajo[i][3] = dateFormatInicio.format(curso.
                            getFechaInicio());
                    trabajo[i][4] = dateFormatInicio.format(curso.
                            getFechaFinalizacion());

                    trabajo[i][5] = new Boolean(curso.isPermiteDescuentos());
                    trabajo[i][6] = javax.jdo.JDOHelper.
                                    getObjectId(curso).toString();
                }
                compomenteABMCListCursos.setDatos(trabajo);
            }
        }

        catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jPanel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(6, 49, 500, 326));

        jPanel1.setLayout(borderLayout1);
        jPanel2.setLayout(null);
        jButtonDefinirCuotas.setBounds(new Rectangle(181, 11, 156, 23));
        jButtonDefinirCuotas.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jButtonDefinirCuotas.setText("Definir Cuotas");
        jButtonDefinirCuotas.addActionListener(new
                                               CursoFrame_jButtonDefinirCuotas_actionAdapter(this));
        jLabel5.setFont(new java.awt.Font("Arial", Font.PLAIN, 22));
        jLabel5.setText("Cursos");
        jLabel5.setBounds(new Rectangle(93, 11, 165, 30));
        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        this.setTitle("Cursos");
        this.addComponentListener(new CursoFrame_this_componentAdapter(this));
        jFormattedTextFieldYear.setFont(new java.awt.Font("Arial", Font.PLAIN,
                14));
        jFormattedTextFieldYear.setBounds(new Rectangle(366, 12, 98, 26));
        jFormattedTextFieldYear.addKeyListener(new
                                               CursoFrame_jFormattedTextFieldYear_keyAdapter(this));
        jLabel6.setFont(new java.awt.Font("Arial", Font.PLAIN, 11));
        jLabel6.setText("A�o");
        jLabel6.setBounds(new Rectangle(313, 16, 45, 18));
        compomenteABMCListCursos.addInsertarListener(new
                CursoFrame_compomenteABMCListCursos_insertarAdapter(this));
        compomenteABMCListCursos.addEliminarListener(new
                CursoFrame_compomenteABMCListCursos_eliminarAdapter(this));
        compomenteABMCListCursos.addModificarListener(new
                CursoFrame_compomenteABMCListCursos_modificarAdapter(this));
        this.getContentPane().add(jPanel2);
        jPanel2.add(jButtonDefinirCuotas);
        this.getContentPane().add(jPanel1);
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setBounds(new Rectangle(6, 382, 501, 44));
        this.getContentPane().add(jLabel5);
        this.getContentPane().add(jFormattedTextFieldYear);
        this.getContentPane().add(jLabel6);
        jPanel1.add(compomenteABMCListCursos, java.awt.BorderLayout.CENTER);
        //------------------------ Curso
        compomenteABMCListCursos.setVisibleCantidadRegistros(true);
        compomenteABMCListCursos.setVisibleBuscar(true);
        compomenteABMCListCursos.setInfoColumna(new String[][] { {"nombre",
                                                "tipo", "editable", "editor",
                                                "val.Combo", "Ancho Columna"}
                                                , {"Nombre", "String", "true",
                                                "comun", "", "240"}
                                                , {"Observaciones", "String",
                                                "true", "comun", "", "240"}
                                                , {"Cantidad de Periodos",
                                                "Integer", "true", "comun", "2",
                                                "110"}
                                                , {"Fecha de Inicio", "String",
                                                "true", "comun", "", "100"}
                                                , {"Fecha de Finalizacion",
                                                "String", "true", "comun", "",
                                                "110"}, {"Permite descuentos",
                                                "Boolean", "true", "comun", "",
                                                "110"}, {"oid", "String",
                                                "false", "comun", "", "1"}
        });
        compomenteABMCListCursos.setEditableBoolean(false);
        compomenteABMCListCursos.setVisibleAgregar(true);
        compomenteABMCListCursos.setVisibleOrdenar(false);
        compomenteABMCListCursos.setVisibleModificar(true);
        compomenteABMCListCursos.setVisibleImprimir(true);
        compomenteABMCListCursos.setVisibleGuardarComo(false);
        compomenteABMCListCursos.setVisibleHeaderTabla(true);
        compomenteABMCListCursos.setVisibleFiltrar(false);
        compomenteABMCListCursos.setVisibleEliminar(true);
        compomenteABMCListCursos.setVisibleCopyclipboard(true);
        compomenteABMCListCursos.setVisibleReportes(true);

        compomenteABMCListCursos.setTituloImprimir("Alumnos del Curso ");

    }

    public void jFormattedTextFieldYear_keyPressed(KeyEvent e) {
        if (e.getKeyCode() == e.VK_ENTER) {

            try {
                year = numberFormat.parse(this.jFormattedTextFieldYear.
                                          getText()).
                       intValue();
                this.loadListCursos(year);

                BrokerServer.instance().setYearPreference(year);

            } catch (ParseException ex) {
                JOptionPane.showMessageDialog(this, "Fecha erronea");
            }

        }
    }

    /**
     * compomenteABMCListCursos_Insercion
     *
     * @param e InsertarEvent
     */
    public void compomenteABMCListCursos_Insercion(InsertarEvent e) {
        Curso curso = new Curso();
        String nombre = (String) ((Vector) e.getVector()).elementAt(0);
        String observaciones = (String) ((Vector) e.getVector()).elementAt(1);
        int cantPeriodos = ((Integer) ((Vector) e.getVector()).elementAt(2)).
                           intValue();
        SimpleDateFormat dateFormatInicio = new SimpleDateFormat("d-M-yyyy");
        String fechaInicioStr = (String) ((Vector) e.getVector()).elementAt(
                3);
        Date fechaInicio = null;
        try {
            fechaInicio = dateFormatInicio.parse(fechaInicioStr);
        } catch (ParseException ex1) {
            JOptionPane.showMessageDialog(this, "Fecha Inicio erronea");
            this.loadListCursos(year);
            return;
        }

        String fechaFinStr = (String) ((Vector) e.getVector()).elementAt(
                4);
        Date fechaFin = null;
        try {
            fechaFin = dateFormatInicio.parse(fechaFinStr);
        } catch (ParseException ex1) {
            JOptionPane.showMessageDialog(this, "Fecha Finalizacion erronea");
            this.loadListCursos(year);
            return;
        }

        Boolean permiteDescuento = (Boolean) ((Vector) e.getVector()).elementAt(
                5);

        curso.setNombre(nombre);
        curso.setObservaciones(observaciones);
        curso.setCantidadPeriodos(cantPeriodos);
        curso.setFechaInicio(fechaInicio);
        curso.setFechaFinalizacion(fechaFin);
        curso.setPermiteDescuentos(permiteDescuento.booleanValue());

        ICommand insertarCurso = CommandFactory.createInsertarCurso(curso);
        try {
            insertarCurso.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());

        }

        this.loadListCursos(year);

    }

    /**
     * compomenteABMCListCursos_Eliminacion
     *
     * @param e EliminarEvent
     */
    public void compomenteABMCListCursos_Eliminacion(EliminarEvent e) {
        String oidStr = ((String) ((Vector) e.getVector()).elementAt(6));
        kodo.util.Id oid = new kodo.util.Id(oidStr);

        Curso curso = (Curso) BrokerServer.instance().getPMF().
                      getPersistenceManager().getObjectById(oid, true);

        ICommand eiminarCurso = CommandFactory.createEliminarCurso(curso);
        try {
            eiminarCurso.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        this.loadListCursos(year);
    }

    public void compomenteABMCListCursos_Modificacion(ModificarEvent e) {
        String oidStr = ((String) ((Vector) e.getVector()).elementAt(6));
        kodo.util.Id oid = new kodo.util.Id(oidStr);

        Curso curso = (Curso) BrokerServer.instance().getPMF().
                      getPersistenceManager().getObjectById(oid, true);

        String nombre = (String) ((Vector) e.getVector()).elementAt(0);
        String observaciones = (String) ((Vector) e.getVector()).elementAt(1);
        int cantPeriodos = ((Integer) ((Vector) e.getVector()).elementAt(2)).
                           intValue();
        SimpleDateFormat dateFormatInicio = new SimpleDateFormat("d-M-yyyy");
        String fechaInicioStr = (String) ((Vector) e.getVector()).elementAt(
                3);
        Date fechaInicio = null;
        try {
            fechaInicio = dateFormatInicio.parse(fechaInicioStr);
        } catch (ParseException ex1) {
            JOptionPane.showMessageDialog(this, "Fecha Inicio erronea");
            this.loadListCursos(year);
            return;
        }

        String fechaFinStr = (String) ((Vector) e.getVector()).elementAt(
                4);
        Date fechaFin = null;
        try {
            fechaFin = dateFormatInicio.parse(fechaFinStr);
        } catch (ParseException ex1) {
            JOptionPane.showMessageDialog(this, "Fecha Finalizacion erronea");
            this.loadListCursos(year);
            return;
        }

        Boolean permiteDescuento = (Boolean) ((Vector) e.getVector()).elementAt(
                5);

        ICommand modificarCurso = CommandFactory.createModificarCurso(curso,
                nombre, observaciones, cantPeriodos, fechaInicio, fechaFin,
                permiteDescuento.booleanValue());
        try {
            modificarCurso.execute();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        this.loadListCursos(year);
    }

    public void this_componentShown(ComponentEvent e) {
        loadTextFieldYear();
    }

    public void jButtonDefinirCuotas_actionPerformed(ActionEvent e) {

        if (compomenteABMCListCursos.getSelectedRow() != -1) {
            String oidStr = ((String) compomenteABMCListCursos.
                             getSelectedRowData().
                             getValueAt(6));

            kodo.util.Id oid = new kodo.util.Id(oidStr);
            try {
                Curso curso = (Curso) org.salamanca.broker.BrokerServer.
                              instance().
                              getPMF().getPersistenceManager().getObjectById(
                                      oid, true);
                this.setVisible(false);
                cuotasFrame.setCurso(curso);
                this.setVisible(false);
                cuotasFrame.show();

            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "No se encontr� el curso");
            }

        }
    }


}


class CursoFrame_jButtonDefinirCuotas_actionAdapter implements ActionListener {
    private CursoFrame adaptee;
    CursoFrame_jButtonDefinirCuotas_actionAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class CursoFrame_this_componentAdapter extends ComponentAdapter {
    private CursoFrame adaptee;
    CursoFrame_this_componentAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void componentShown(ComponentEvent e) {
        adaptee.this_componentShown(e);
    }
}


class CursoFrame_compomenteABMCListCursos_modificarAdapter implements
        ModificarListener {
    private CursoFrame adaptee;
    CursoFrame_compomenteABMCListCursos_modificarAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void Modificacion(ModificarEvent e) {
        adaptee.compomenteABMCListCursos_Modificacion(e);
    }
}


class CursoFrame_compomenteABMCListCursos_eliminarAdapter implements
        EliminarListener {
    private CursoFrame adaptee;
    CursoFrame_compomenteABMCListCursos_eliminarAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

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


class CursoFrame_jFormattedTextFieldYear_keyAdapter extends KeyAdapter {
    private CursoFrame adaptee;
    CursoFrame_jFormattedTextFieldYear_keyAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

    public void keyPressed(KeyEvent e) {
        adaptee.jFormattedTextFieldYear_keyPressed(e);
    }
}


class CursoFrame_compomenteABMCListCursos_insertarAdapter implements
        InsertarListener {
    private CursoFrame adaptee;
    CursoFrame_compomenteABMCListCursos_insertarAdapter(CursoFrame adaptee) {
        this.adaptee = adaptee;
    }

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

Related Classes of org.salamanca.ui.CursoFrame_compomenteABMCListCursos_modificarAdapter

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.