Advertisement
madocter

vista_dao

Nov 29th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.06 KB | None | 0 0
  1. package Vista;
  2.  
  3.  
  4. import java.awt.BorderLayout;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.awt.FlowLayout;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.GridBagLayout;
  11. import java.awt.GridLayout;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.FocusEvent;
  15. import java.awt.event.FocusListener;
  16. import java.awt.event.MouseAdapter;
  17. import java.awt.event.MouseEvent;
  18. import java.beans.PropertyChangeEvent;
  19. import java.beans.PropertyChangeListener;
  20. import java.sql.Date;
  21. import java.util.ArrayList;
  22. import java.util.Calendar;
  23.  
  24. import javax.swing.Box;
  25. import javax.swing.ButtonGroup;
  26. import javax.swing.DefaultCellEditor;
  27. import javax.swing.DefaultListCellRenderer;
  28. import javax.swing.ImageIcon;
  29. import javax.swing.JButton;
  30. import javax.swing.JComboBox;
  31. import javax.swing.JFrame;
  32. import javax.swing.JLabel;
  33. import javax.swing.JList;
  34. import javax.swing.JMenu;
  35. import javax.swing.JMenuItem;
  36. import javax.swing.JOptionPane;
  37. import javax.swing.JPanel;
  38. import javax.swing.JPopupMenu;
  39. import javax.swing.JScrollPane;
  40. import javax.swing.JTable;
  41. import javax.swing.JTextField;
  42. import javax.swing.JToggleButton;
  43. import javax.swing.ListCellRenderer;
  44. import javax.swing.SwingConstants;
  45. import javax.swing.border.TitledBorder;
  46. import javax.swing.event.TableModelEvent;
  47. import javax.swing.event.TableModelListener;
  48. import javax.swing.table.DefaultTableCellRenderer;
  49. import javax.swing.table.DefaultTableModel;
  50. import javax.swing.table.TableCellEditor;
  51. import javax.swing.table.TableCellRenderer;
  52.  
  53. import Vista_ext.Dialogo_reportes;
  54.  
  55. import com.toedter.calendar.JDateChooser;
  56.  
  57. import DAO.CONSTANTES;
  58. import DAO.Finca_DAO;
  59. import DAO.Producto_DAO;
  60. import Dominio.Producto;
  61. import Dominio.Parcela;
  62. import Dominio.Producto;
  63. import Dominio.Parcela;
  64. import Dominio.Explotacion;
  65. import Dominio.Parcela;
  66.  
  67. public class panel_explotacion extends JPanel{
  68.     Finca_DAO fincas = new Finca_DAO();
  69.     JButton boton_alta , boton_baja , boton_busqueda , boton_editar ;
  70.     JButton  boton_stadisticas , boton_alta_ext  , interruptor_relaciones , boton_confirmar , boton_aniadir_relacion01;
  71.     JTable tabla;
  72.    
  73.     java.sql.Date valor_fecha01;
  74.     java.sql.Date valor_fecha02;
  75.    
  76.     private Parcela Parcela;
  77.     private Producto Producto;
  78.     private Date Fecha_inicio;
  79.     private Date Fecha_fin;
  80.    
  81.     String[] columnNames = {"ID", "Fecha inicio" , "Fecha fin" , "Producto"};
  82.     Object[][] datos = {};
  83.     DefaultTableModel modelo;
  84.     JScrollPane scroll ;
  85.    
  86.     JFrame frame;
  87.     JPanel panel_relaciones , panel_control ;
  88.    
  89.     JLabel etiqueta01 , etiqueta02;
  90.    
  91.     JDateChooser fecha01 , fecha02;
  92.    
  93.     JComboBox combo_relacion_1;
  94.     JComboBox combo_relacion_2;
  95.    
  96.     Explotacion nueva_entidad = new Explotacion();
  97.     Parcela nueva_relacion_01 = new     Parcela ();
  98.     Producto nueva_relacion_02 = new    Producto ();   
  99.  
  100.     ArrayList<Explotacion> lista_entidad = CONSTANTES.explotacion_DAO.consultaAll();
  101.     ArrayList<Parcela> lista_relacion_01 = CONSTANTES.parcela_DAO.consultaAll();
  102.     ArrayList<Producto> lista_relacion_02 = CONSTANTES.producto_DAO.consultaAll();
  103.    
  104.  
  105.     int memoria = -1 ;
  106.    
  107.     panel_explotacion(JFrame frame){
  108.     this.frame  = frame;
  109.     modelo = new    DefaultTableModel   (datos , columnNames){
  110.         //redefinimos el metodo getcolumclass para que actue de manera diferente segun el tipo de datos de la columna : sauce: http://www.codejava.net/java-se/swing/6-techniques-for-sorting-jtable-you-should-know
  111.         @Override
  112.         public Class getColumnClass(int column) {
  113.             switch (column) {
  114.                 case 0:
  115.                     return Integer.class;
  116.                 case 1:
  117.                     return String.class;
  118.                 case 2:
  119.                     return Integer.class;
  120.                 default:
  121.                     return String.class;
  122.             }
  123.         }
  124.        
  125.         public boolean isCellEditable(int row, int col) {
  126.             //este metodo es el que determina si una celda es editable o no , devuelve true siempre salvo que la columna sea 0 donde se almacena el id , valor que no debe ser cambiado
  127.             //no obstante no funciona y no me deja editar apparentemente :)
  128.             if(col == 0){return false;}
  129.             return true;
  130.         }
  131.     }; 
  132.    
  133.     tabla = new JTable  (   modelo  ){
  134.         //en este caso el "defaulttablecellrenderer" Es anonimo por que esta clase tiene un metodo por defecto con un comaprtamiento diferente @override
  135.         //esta propiedad del jtable se encarga de renderizar las celdas bien se podria hacer esto mismo : tabla.setDefaultRenderer(arg0, arg1);    
  136.         DefaultTableCellRenderer renderRight = new DefaultTableCellRenderer();
  137.  
  138.         {
  139.             renderRight.setHorizontalAlignment(SwingConstants.CENTER);
  140.         }
  141.  
  142.         @Override
  143.         public TableCellRenderer getCellRenderer (int arg0, int arg1) {
  144.             return renderRight;
  145.         }
  146.     }; 
  147.  
  148.     ImageIcon icono_alta = new ImageIcon("src/Media/icono_alta.png");
  149.     ImageIcon icono_baja = new ImageIcon("src/Media/icono_baja.png");
  150.     ImageIcon icono_busqueda = new ImageIcon("src/Media/icono_busqueda.png");
  151.     ImageIcon icono_editar = new ImageIcon("src/Media/icono_editar_raw.png");
  152.     ImageIcon icono_datos = new ImageIcon("src/Media/icono_datos.png");
  153.     ImageIcon icono_estadisticas = new ImageIcon("src/Media/icono_estadisticas.png");
  154.     final ImageIcon icono_si = new ImageIcon("src/Media/yes_icon.png");
  155.  
  156.  
  157.    
  158.     scroll = new JScrollPane(tabla);
  159.    
  160.     boton_alta = new JButton("Nuev@" ,icono_alta );
  161.     boton_alta.setMaximumSize(new Dimension(120,25));
  162.     boton_alta.addActionListener(new oyente_acciones());   
  163.     boton_baja = new JButton("Borrar" , icono_baja);
  164.     boton_baja.setMaximumSize(new Dimension(120,25));
  165.     boton_baja.addActionListener(new oyente_acciones());
  166.     boton_editar = new JButton("Modificar" , icono_editar);
  167.     boton_editar.setMaximumSize(new Dimension(120,25));
  168.     boton_editar.addActionListener(new oyente_acciones());
  169.     boton_busqueda = new JButton("Filtro" , icono_busqueda);
  170.     boton_busqueda.setMaximumSize(new Dimension(120,25));
  171.     boton_busqueda.addActionListener(new oyente_acciones());
  172.    
  173.     ButtonGroup grupo_botones = new ButtonGroup();
  174.     grupo_botones.add(boton_alta);
  175.     grupo_botones.add(boton_baja);
  176.     grupo_botones.add(boton_editar);
  177.     grupo_botones.add(boton_busqueda);
  178.    
  179.     boton_stadisticas = new JButton("Estadisticas" ,icono_estadisticas);
  180.     boton_stadisticas.setMaximumSize(new Dimension(120,25));
  181.     boton_stadisticas.addActionListener(new oyente_acciones());
  182.    
  183.     boton_alta_ext = new JButton("Nueva Explotacion" ,icono_alta);
  184.     boton_alta_ext.setMaximumSize(new Dimension(120,25));
  185.     boton_alta_ext.addActionListener(new oyente_acciones());
  186.  
  187.     boton_confirmar = new JButton("Confirmar");
  188.     boton_confirmar.setMaximumSize(new Dimension(120,25));
  189.     boton_confirmar.addActionListener(new oyente_acciones());
  190.    
  191.     boton_aniadir_relacion01 = new JButton("Añadir");
  192.     boton_aniadir_relacion01.setMaximumSize(new Dimension(120,25));
  193.     boton_aniadir_relacion01.addActionListener(new oyente_acciones());
  194.    
  195.    
  196.     combo_relacion_1 = new JComboBox();
  197.     combo_relacion_1.setPreferredSize(new Dimension(140,25));
  198.     combo_relacion_1.setMaximumSize(new Dimension(140,25));
  199.  
  200.     combo_relacion_2 = new JComboBox();
  201.     combo_relacion_2.setPreferredSize(new Dimension(140,25));
  202.     combo_relacion_2.setMaximumSize(new Dimension(140,25));
  203.    
  204. DefaultListCellRenderer cell_renderer = new DefaultListCellRenderer(){
  205.         int parameter;
  206.  
  207.         void setParameter(int parameter){this.parameter = parameter;}
  208.    
  209.         @Override
  210.         public Component getListCellRendererComponent(JList list, Object value, int index,boolean isSelected, boolean cellHasFocus)
  211.         {
  212.            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
  213.            String texto  = label.getText();
  214.            if(texto.contains("free")){texto = texto.replace("null", "Libre") ;label.setText(texto.split("&")[0]);label.setBackground(Color.green);}
  215.            else{label.setBackground(Color.orange);}
  216.            return label;
  217.  
  218.         }
  219.        
  220.        
  221.     };
  222.    
  223.     combo_relacion_1.setRenderer(cell_renderer);
  224.     combo_relacion_1.addActionListener(new oyente_acciones());
  225.     actualiza_lista_relacion01(1);
  226.  
  227.    
  228.     combo_relacion_2.setRenderer(cell_renderer);
  229.     combo_relacion_2.addActionListener(new oyente_acciones());
  230.     actualiza_lista_relacion02(1);
  231.    
  232.     etiqueta01 = new JLabel (icono_datos , JLabel.LEFT);
  233.     etiqueta01.setMaximumSize(new Dimension(40,25));
  234.  
  235.    
  236.     tabla.addMouseListener(new oyente_raton());
  237.     modelo.setRowCount(5);  
  238.     modelo.addTableModelListener(new oyente_tabla());
  239.     tabla.getColumnModel().getColumn(0).setMaxWidth(55);
  240.     tabla.setAutoCreateRowSorter(true);
  241.    
  242.     Calendar c = Calendar.getInstance();
  243.     c.add(Calendar.YEAR, -10);
  244.    
  245.     fecha01 = new JDateChooser(c.getTime());
  246.     fecha01.addPropertyChangeListener("date" ,new oyente_fecha());
  247.     fecha02 = new JDateChooser(c.getTime());
  248.     fecha02.addPropertyChangeListener("date" , new oyente_fecha());
  249.    
  250.     //
  251.     //TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabla.getModel());
  252.     //sorter.setSortable(0, false);
  253.     //tabla.setRowSorter(sorter);
  254.    
  255.    
  256.     Box vertical_00 = Box.createVerticalBox(); 
  257.    
  258.  
  259.     vertical_00.add(boton_alta);
  260.     vertical_00.add(Box.createVerticalStrut(8));
  261.     vertical_00.add(boton_baja);
  262.     vertical_00.add(Box.createVerticalStrut(8));
  263.     vertical_00.add(boton_editar);
  264.     vertical_00.add(Box.createVerticalStrut(8));
  265.     vertical_00.add(boton_busqueda);
  266.     vertical_00.add(Box.createVerticalStrut(8));
  267.     vertical_00.add(boton_stadisticas);
  268.     vertical_00.add(Box.createVerticalStrut(80));
  269.     vertical_00.add(Box.createHorizontalStrut(50));
  270.  
  271.    
  272.     // panel de control altas
  273.     // lo que hare sera reutilizar este panel_control desde otrras clases
  274.     Box horizontal_00 =Box.createHorizontalBox();
  275.     Box vertical_02 = Box.createVerticalBox(); 
  276.    
  277.     horizontal_00.add(Box.createHorizontalStrut(8));
  278.     horizontal_00.add(etiqueta01);
  279.    
  280.     horizontal_00.add(Box.createHorizontalStrut(8));
  281.     horizontal_00.add(fecha01);
  282.     horizontal_00.add(Box.createHorizontalStrut(8));
  283.     horizontal_00.add(fecha02);
  284. /* 
  285.     horizontal_00.add(Box.createHorizontalStrut(8));
  286.     horizontal_00.add(combo_relacion_1);   
  287.     horizontal_00.add(Box.createHorizontalStrut(8));
  288.     horizontal_00.add(combo_relacion_2);   
  289.     horizontal_00.add(Box.createHorizontalStrut(8));
  290.    
  291.  
  292.     Box horizontal_02 =Box.createHorizontalBox();
  293.     horizontal_02.add(Box.createHorizontalStrut(364));
  294.     horizontal_02.add(Box.createHorizontalStrut(8));
  295.     horizontal_02.add(boton_confirmar);
  296.     interruptor_relaciones = new JButton("Panel de Explotacion");
  297.     horizontal_02.add(Box.createHorizontalStrut(8));
  298.     horizontal_02.add(interruptor_relaciones);
  299.     //
  300. */
  301.    
  302.     JPanel panel_relaciones ;
  303.     Box horizontal_03 = Box.createHorizontalBox();
  304.     horizontal_03.add(new JLabel("Selector relaciones"));
  305.     horizontal_03.add(Box.createHorizontalStrut(8));
  306.     horizontal_03.add( combo_relacion_1);
  307.     horizontal_03.add(Box.createHorizontalStrut(8));
  308.     horizontal_03.add(combo_relacion_2);
  309.     horizontal_03.add(Box.createHorizontalStrut(8));
  310.  
  311.     panel_relaciones = new JPanel();
  312.     panel_relaciones.setBorder(new TitledBorder(null, "Panel Visor", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
  313.     panel_relaciones.add(horizontal_03);
  314.    
  315.     vertical_02.add(horizontal_00);
  316.     vertical_02.add(Box.createVerticalStrut(10));
  317.     //vertical_02.add(horizontal_02);
  318.     vertical_02.add(panel_relaciones);
  319.     vertical_02.add(Box.createVerticalStrut(10));
  320.  
  321.  
  322.    
  323.    
  324.     panel_control = new JPanel();
  325.     panel_control.setBorder(new TitledBorder(null, "Panel Control", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
  326.     panel_control.add(vertical_02);
  327.  
  328.  
  329.     //
  330.  
  331.    
  332.     scroll.setPreferredSize(new Dimension(tabla.getPreferredSize().width,tabla.getRowHeight()*tabla.getRowCount()+100));
  333.    
  334.     this.setSize(900, 600);
  335.     this.setPreferredSize(new Dimension(900,600)); 
  336.            
  337.     actualiza_tabla();
  338.    
  339.     JPanel panel_tabla = new JPanel();
  340.     Box horizontal_01 =Box.createHorizontalBox();
  341.     Box vertical_01 =Box.createVerticalBox();
  342.     vertical_01.add(scroll);
  343.     vertical_01.add(Box.createVerticalStrut(15));
  344.     vertical_01.add(panel_control);
  345.     horizontal_01.add(vertical_01);
  346.     horizontal_01.add(vertical_00);
  347.     panel_tabla.add(horizontal_01);
  348.    
  349.    
  350.     this.setLayout(new BorderLayout());
  351.    
  352.     this.add(panel_tabla , BorderLayout.CENTER);
  353.        
  354.     //boton_alta.getModel().setPressed(true);
  355.     //boton_alta.getModel().setSelected(true);
  356.    
  357.     this.setVisible(true);
  358.     }  
  359.    
  360.  
  361.    
  362. public void actualiza_lista_relacion01(int parameter){
  363.  
  364.  
  365. if(parameter == 1)
  366. {
  367. combo_relacion_1.removeAllItems();
  368. lista_relacion_01 = CONSTANTES.parcela_DAO.consultaAll();
  369.  
  370.  
  371. for(Parcela nueva_relacion_01 : lista_relacion_01)
  372.     {
  373.     String parcela = nueva_relacion_01.getId_parcela() + " : " + "Parcela N: " + nueva_relacion_01.getId_parcela();
  374.     combo_relacion_1.addItem(parcela);                 
  375.     }
  376.  
  377. combo_relacion_1.addItem("TODAS");
  378. }
  379.  
  380.  
  381. if(parameter == 2)
  382. {  
  383.     combo_relacion_1.removeAllItems();
  384. //todo
  385.     if(nueva_entidad != null )
  386.     {
  387.         nueva_relacion_01 = new Parcela();
  388.         nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(nueva_entidad.getParcela().getId_parcela());
  389.        
  390.         if(nueva_relacion_01.getId_parcela() == 0)
  391.         {
  392.         lista_relacion_01.clear();
  393.         combo_relacion_1.addItem("No tiene ");
  394.         }
  395.        
  396.         else
  397.         {
  398.         String parcela = nueva_relacion_01.getId_parcela() + " : " + "Parcela N: " + nueva_relacion_01.getId_parcela();
  399.         combo_relacion_1.addItem(parcela);
  400.         }
  401.     }
  402.    
  403.    
  404.     combo_relacion_1.addItem("TODAS");
  405. }
  406.  
  407. }  
  408.  
  409.  
  410. public void actualiza_lista_relacion02(int parameter){
  411.  
  412.  
  413. if(parameter == 1)
  414. {
  415. combo_relacion_2.removeAllItems();
  416. lista_relacion_02 = CONSTANTES.producto_DAO.consultaAll();
  417.  
  418.  
  419. for(Producto nueva_relacion_02 : lista_relacion_02)
  420.     {
  421.     String producto = nueva_relacion_02.getId_producto() + " : " +  nueva_relacion_02.getNombre() ;
  422.     combo_relacion_2.addItem(producto);                
  423.     }
  424.  
  425. combo_relacion_2.addItem("TODAS");
  426. }
  427.  
  428.  
  429. if(parameter == 2)
  430. {  
  431.     combo_relacion_2.removeAllItems();
  432.  
  433.     if(nueva_entidad != null )
  434.     {
  435.         nueva_relacion_02 = new Producto();
  436.         nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto());
  437.         String producto = nueva_relacion_02.getId_producto() + " : " +  nueva_relacion_02.getNombre() ;
  438.         combo_relacion_2.addItem(producto);    
  439.     }
  440.     else{
  441.     nueva_relacion_02 = null;  
  442.     }
  443.    
  444.    
  445.    
  446.    
  447.     if(nueva_relacion_02 == null)
  448.     {
  449.     lista_relacion_02.clear();
  450.     combo_relacion_2.addItem("No tiene ");
  451.     }
  452.    
  453.     combo_relacion_2.addItem("TODAS");
  454. }
  455.  
  456. }  
  457.  
  458.  
  459.  
  460. public void actualiza_tabla(){
  461.     lista_entidad = CONSTANTES.explotacion_DAO.consultaAll();
  462.     modelo.setRowCount (0);  
  463.  
  464.     for (Explotacion nueva_entidad : lista_entidad)
  465.     {      
  466.         Object[] fila = new Object[4];        
  467.         fila [0] = nueva_entidad.getId_explotacion();
  468.         fila [1] = nueva_entidad.getFecha_inicio();
  469.         fila [2] = nueva_entidad.getFecha_fin();
  470.         fila [3] = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto()).getNombre();
  471.         modelo.addRow(fila);  
  472.     }      
  473.    
  474.     modelo.addRow(new Object[4]);
  475.                    
  476. }
  477.  
  478. public void actualiza_tabla(ArrayList<Explotacion> lista_gasto_obra_ext){
  479.     modelo.setRowCount (0);  
  480.  
  481.     for (Explotacion nueva_entidad : lista_gasto_obra_ext)
  482.     {
  483.         Object[] fila = new Object[4];        
  484.         fila [0] = nueva_entidad.getId_explotacion();
  485.         fila [1] = nueva_entidad.getFecha_inicio();
  486.         fila [2] = nueva_entidad.getFecha_fin();
  487.         fila [3] = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto()).getNombre();
  488.         modelo.addRow(fila);  
  489.     }      
  490.    
  491.     modelo.addRow(new Object[4]);
  492.                    
  493. }
  494.    
  495.    
  496. public void filtra(){
  497.     modelo.setRowCount (0);
  498.     ArrayList<Explotacion> lista_entidad_filtro = new ArrayList();
  499.     int found = 0 ;
  500.    
  501.  
  502.    
  503.     for (Explotacion nueva_entidad : lista_entidad)
  504.     {
  505.         if(  
  506.            nueva_relacion_01 != null && comprueba_relacion(nueva_entidad , nueva_relacion_01) ||
  507.            nueva_relacion_02 != null && comprueba_relacion02(nueva_entidad , nueva_relacion_02)
  508.         )
  509.            
  510.         {
  511.  
  512.             lista_entidad_filtro.add(nueva_entidad);
  513.             found++;
  514.         }
  515.     }
  516.    
  517.     actualiza_tabla (lista_entidad_filtro);
  518.  
  519.    
  520.     if(found==0){
  521.     JOptionPane.showMessageDialog(frame, "Comprueve los filtros de busqueda" , "Error en la busqueda" , JOptionPane.INFORMATION_MESSAGE );
  522.     actualiza_tabla();
  523.     reinicia_campos();
  524.     }
  525. }
  526.  
  527. public boolean comprueba_filtro(String filtro){
  528. if(filtro != null &&  filtro.equals("") ==false  )
  529. {
  530.     return true;
  531. }  
  532.    
  533.     return false;
  534. }
  535.  
  536. public Double string_to_double(String target){
  537.  
  538.     try{return Double.parseDouble(target.toString());}catch(NumberFormatException e){return 00.00;}
  539.  
  540. }
  541.  
  542. public int string_to_int(String target){
  543.  
  544.     try{return Integer.parseInt(target.toString());}catch(NumberFormatException e){return 0;}
  545.  
  546. }
  547.  
  548.  
  549. public boolean comprueba_relacion(Explotacion nueva_entidad , Parcela nueva_relacion_01){
  550.     if ( nueva_entidad.getParcela().getId_parcela() == nueva_relacion_01.getId_parcela() ) {return true;}  
  551. return false;          
  552. }
  553.  
  554. public boolean comprueba_relacion02(Explotacion nueva_entidad ,Producto nueva_relacion_02){
  555.     if ( nueva_entidad.getProducto().getId_producto() == nueva_relacion_02.getId_producto() ) {return true;}   
  556. return false;          
  557. }
  558.  
  559.  
  560. public void reinicia_campos(){
  561.    
  562. }
  563.  
  564. public boolean comprueba_campos(){
  565.     if(nueva_relacion_01 != null && nueva_relacion_02!= null) {return true;}
  566.     return false;}
  567.  
  568.  
  569. public boolean alta(){
  570.     nueva_entidad = new Explotacion();
  571.     nueva_entidad.setParcela(nueva_relacion_01);
  572.     nueva_entidad.setProducto(nueva_relacion_02);
  573.     nueva_entidad.setFecha_inicio(valor_fecha01);
  574.     nueva_entidad.setFecha_fin(valor_fecha02);
  575.  
  576.    
  577.     return CONSTANTES.explotacion_DAO.alta(nueva_entidad);
  578. }
  579.  
  580. public void baja(){
  581.     if(nueva_entidad.getId_explotacion()>0){
  582.     CONSTANTES.explotacion_DAO.baja(nueva_entidad.getId_explotacion());
  583.     }
  584. }
  585.  
  586. public void modificacion(){
  587.     if(nueva_entidad!=null){
  588.         nueva_entidad.setParcela(nueva_relacion_01);
  589.         nueva_entidad.setProducto(nueva_relacion_02);
  590.         nueva_entidad.setFecha_inicio(valor_fecha01);
  591.         nueva_entidad.setFecha_fin(valor_fecha02);
  592.     CONSTANTES.explotacion_DAO.modificacion(nueva_entidad);
  593.     }
  594. }
  595.  
  596. public void limpia_memoria(){
  597.     nueva_relacion_01 = null;
  598.     nueva_relacion_02 = null;
  599.     nueva_entidad = null;
  600.    
  601.     lista_entidad.clear();
  602.     lista_relacion_01.clear();
  603.     lista_relacion_02.clear();
  604. }
  605.  
  606.  
  607. class oyente_fecha implements PropertyChangeListener{
  608.  
  609.     public void propertyChange(PropertyChangeEvent evento) {
  610.     JDateChooser selector_fecha = new JDateChooser();
  611.    
  612.     if(evento.getSource().getClass().equals(selector_fecha.getClass()))
  613.     {
  614.         selector_fecha = (JDateChooser) evento.getSource();
  615.         if(selector_fecha == fecha01)
  616.         {  
  617.         java.util.Date utilDate = new java.util.Date();
  618.         utilDate = (java.util.Date) (evento.getNewValue());    
  619.         java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
  620.         valor_fecha01 = sqlDate;       
  621.         }
  622.        
  623.         if(selector_fecha == fecha02)
  624.         {
  625.         java.util.Date utilDate = new java.util.Date();
  626.         utilDate = (java.util.Date) (evento.getNewValue());    
  627.         java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
  628.         valor_fecha02 = sqlDate;   
  629.         }
  630.        
  631.     }
  632.    
  633.  
  634.     }
  635.    
  636.    
  637. }
  638.  
  639.  
  640. class oyente_acciones implements ActionListener{
  641.     JButton boton = new JButton();
  642.     JToggleButton boton_toogle = new JToggleButton();
  643.     JComboBox combo = new JComboBox();
  644.  
  645.     public void actionPerformed(ActionEvent evento) {
  646.    
  647.         if(evento.getSource().getClass().equals(combo.getClass()) )
  648.         {
  649.         combo = (JComboBox) evento.getSource();
  650.        
  651.             if(combo == combo_relacion_1)
  652.             {
  653.                 String texto = (String) combo.getSelectedItem();  
  654.                 if(texto!= null)
  655.                 {
  656.                     if(!texto.contains("tiene") && texto.contains("free"))
  657.                     {
  658.                     int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
  659.                     nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(target);
  660.                     }
  661.                    
  662.                     if(texto.equals("TODAS")){
  663.                     actualiza_lista_relacion01(1);
  664.                     nueva_relacion_01 =null;
  665.                     }
  666.                    
  667.                     else if(!texto.contains("tiene") && !texto.equals("TODAS") )    
  668.                     {                                                              
  669.                     int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
  670.                     nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(target);
  671.                     }
  672.                    
  673.                 }
  674.                 memoria = combo.getSelectedIndex();
  675.             }
  676.            
  677.            
  678.             if(combo == combo_relacion_2)
  679.             {
  680.                 String texto = (String) combo.getSelectedItem();  
  681.                 if(texto!= null)
  682.                 {
  683.                     if(!texto.contains("tiene") && texto.contains("free"))
  684.                     {
  685.                     int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
  686.                     nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(target);
  687.                     }
  688.                    
  689.                     if(texto.equals("TODAS")){
  690.                     actualiza_lista_relacion02(1);
  691.                     nueva_relacion_02 =null;
  692.                     }
  693.                    
  694.                     else if(!texto.contains("tiene") && !texto.equals("TODAS") )    
  695.                     {                                                              
  696.                     int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
  697.                     nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(target);
  698.                     }
  699.                    
  700.                 }
  701.                 memoria = combo.getSelectedIndex();
  702.             }
  703.            
  704.        
  705.            
  706.            
  707.         }      
  708.  
  709.         if(evento.getSource().getClass().equals(boton.getClass()))
  710.         {
  711.         boton = (JButton) evento.getSource();      
  712.        
  713.        
  714.         if(boton==boton_stadisticas && nueva_entidad!= null)
  715.         {          
  716.             try {
  717.                 Dialogo_reportes nuevo_dialogo = new Dialogo_reportes(nueva_entidad , "" , null);
  718.                 nuevo_dialogo.setVisible(true);
  719.             } catch (Exception e) {
  720.                 // TODO Auto-generated catch block
  721.                 e.printStackTrace();
  722.             }
  723.          }
  724.  
  725.         if(boton==boton_alta && comprueba_campos())
  726.         {          
  727.             alta();
  728.             limpia_memoria();
  729.             actualiza_tabla();
  730.  
  731.          }
  732.    
  733.        
  734.         if(boton==boton_editar)
  735.         {
  736.             modificacion();
  737.             limpia_memoria();
  738.             actualiza_lista_relacion01(2);
  739.             actualiza_lista_relacion02(2);
  740.             actualiza_tabla();
  741.         }
  742.        
  743.         if(boton==boton_baja)
  744.         {
  745.             baja();
  746.             limpia_memoria();
  747.             actualiza_lista_relacion01(2);
  748.             actualiza_lista_relacion02(2);
  749.             actualiza_tabla();
  750.              
  751.         }
  752.        
  753.         if(boton==boton_busqueda)
  754.         {              
  755.             filtra( );
  756.        
  757.         }
  758.                
  759.                      
  760.        
  761.         }
  762.        
  763.        
  764.     }
  765.    
  766. }
  767.  
  768.  
  769. class oyente_enfoque implements FocusListener{
  770.  
  771.     public void focusGained(FocusEvent evento) {
  772.         JTextField input = (JTextField) evento.getSource();
  773.    
  774.      
  775.        
  776.     }
  777.  
  778.     public void focusLost(FocusEvent arg0) {
  779.         // TODO Auto-generated method stub
  780.        
  781.     }
  782. }
  783.  
  784.  
  785.  
  786. class oyente_tabla implements TableModelListener{
  787.  
  788.     public void tableChanged(TableModelEvent evento)
  789.     {
  790.  
  791.        
  792.     }
  793. }
  794.  
  795.  
  796.  
  797. class oyente_raton extends MouseAdapter{
  798.    
  799.     public void mouseClicked(MouseEvent evento){
  800.        
  801.         tabla.convertRowIndexToView(0);
  802.  
  803.         //Uso este metodo sobre la el sorteador de filas de la tabla para que me de el indice en base a la vista actual , en cas ode que el usuario haya reordenado la tabla , sauce : http://stackoverflow.com/questions/4151850/how-to-keep-track-of-row-index-when-jtable-has-been-sorted-by-the-user
  804.         int fila =tabla.getRowSorter().convertRowIndexToModel(tabla.rowAtPoint(evento.getPoint()));
  805.         //int fila = tabla.rowAtPoint(evento.getPoint());
  806.                    
  807.         if(fila >-1 )
  808.         {
  809.         try{
  810.         nueva_entidad = CONSTANTES.explotacion_DAO.consulta(Integer.parseInt(modelo.getValueAt(fila,0).toString()));    
  811.         if(nueva_entidad == null){System.out.println("nulllll");}
  812.        
  813.  
  814.         fecha01.setDate( (Date) (modelo.getValueAt(fila,1)));  
  815.         fecha02.setDate( (Date) (modelo.getValueAt(fila,2)));  
  816.        
  817.        
  818.         actualiza_lista_relacion01(2);
  819.         actualiza_lista_relacion02(2);
  820.        
  821.         }  
  822.         catch (Exception e)
  823.         {  
  824.         JOptionPane.showMessageDialog(frame, "Error en cargar el objeto desde la base de datos" , "Error de database" , JOptionPane.INFORMATION_MESSAGE );
  825.         actualiza_tabla();    
  826.         reinicia_campos();
  827.         }
  828.         finally{
  829.            
  830.         }
  831.        
  832.         }
  833.  
  834.     }
  835.    
  836.  
  837.    
  838.    
  839.    
  840.    
  841.     }  
  842. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement