Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Vista;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.FocusEvent;
- import java.awt.event.FocusListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.sql.Date;
- import java.util.ArrayList;
- import java.util.Calendar;
- import javax.swing.Box;
- import javax.swing.ButtonGroup;
- import javax.swing.DefaultCellEditor;
- import javax.swing.DefaultListCellRenderer;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JMenu;
- import javax.swing.JMenuItem;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPopupMenu;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.JToggleButton;
- import javax.swing.ListCellRenderer;
- import javax.swing.SwingConstants;
- import javax.swing.border.TitledBorder;
- import javax.swing.event.TableModelEvent;
- import javax.swing.event.TableModelListener;
- import javax.swing.table.DefaultTableCellRenderer;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableCellEditor;
- import javax.swing.table.TableCellRenderer;
- import Vista_ext.Dialogo_reportes;
- import com.toedter.calendar.JDateChooser;
- import DAO.CONSTANTES;
- import DAO.Finca_DAO;
- import DAO.Producto_DAO;
- import Dominio.Producto;
- import Dominio.Parcela;
- import Dominio.Producto;
- import Dominio.Parcela;
- import Dominio.Explotacion;
- import Dominio.Parcela;
- public class panel_explotacion extends JPanel{
- Finca_DAO fincas = new Finca_DAO();
- JButton boton_alta , boton_baja , boton_busqueda , boton_editar ;
- JButton boton_stadisticas , boton_alta_ext , interruptor_relaciones , boton_confirmar , boton_aniadir_relacion01;
- JTable tabla;
- java.sql.Date valor_fecha01;
- java.sql.Date valor_fecha02;
- private Parcela Parcela;
- private Producto Producto;
- private Date Fecha_inicio;
- private Date Fecha_fin;
- String[] columnNames = {"ID", "Fecha inicio" , "Fecha fin" , "Producto"};
- Object[][] datos = {};
- DefaultTableModel modelo;
- JScrollPane scroll ;
- JFrame frame;
- JPanel panel_relaciones , panel_control ;
- JLabel etiqueta01 , etiqueta02;
- JDateChooser fecha01 , fecha02;
- JComboBox combo_relacion_1;
- JComboBox combo_relacion_2;
- Explotacion nueva_entidad = new Explotacion();
- Parcela nueva_relacion_01 = new Parcela ();
- Producto nueva_relacion_02 = new Producto ();
- ArrayList<Explotacion> lista_entidad = CONSTANTES.explotacion_DAO.consultaAll();
- ArrayList<Parcela> lista_relacion_01 = CONSTANTES.parcela_DAO.consultaAll();
- ArrayList<Producto> lista_relacion_02 = CONSTANTES.producto_DAO.consultaAll();
- int memoria = -1 ;
- panel_explotacion(JFrame frame){
- this.frame = frame;
- modelo = new DefaultTableModel (datos , columnNames){
- //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
- @Override
- public Class getColumnClass(int column) {
- switch (column) {
- case 0:
- return Integer.class;
- case 1:
- return String.class;
- case 2:
- return Integer.class;
- default:
- return String.class;
- }
- }
- public boolean isCellEditable(int row, int col) {
- //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
- //no obstante no funciona y no me deja editar apparentemente :)
- if(col == 0){return false;}
- return true;
- }
- };
- tabla = new JTable ( modelo ){
- //en este caso el "defaulttablecellrenderer" Es anonimo por que esta clase tiene un metodo por defecto con un comaprtamiento diferente @override
- //esta propiedad del jtable se encarga de renderizar las celdas bien se podria hacer esto mismo : tabla.setDefaultRenderer(arg0, arg1);
- DefaultTableCellRenderer renderRight = new DefaultTableCellRenderer();
- {
- renderRight.setHorizontalAlignment(SwingConstants.CENTER);
- }
- @Override
- public TableCellRenderer getCellRenderer (int arg0, int arg1) {
- return renderRight;
- }
- };
- ImageIcon icono_alta = new ImageIcon("src/Media/icono_alta.png");
- ImageIcon icono_baja = new ImageIcon("src/Media/icono_baja.png");
- ImageIcon icono_busqueda = new ImageIcon("src/Media/icono_busqueda.png");
- ImageIcon icono_editar = new ImageIcon("src/Media/icono_editar_raw.png");
- ImageIcon icono_datos = new ImageIcon("src/Media/icono_datos.png");
- ImageIcon icono_estadisticas = new ImageIcon("src/Media/icono_estadisticas.png");
- final ImageIcon icono_si = new ImageIcon("src/Media/yes_icon.png");
- scroll = new JScrollPane(tabla);
- boton_alta = new JButton("Nuev@" ,icono_alta );
- boton_alta.setMaximumSize(new Dimension(120,25));
- boton_alta.addActionListener(new oyente_acciones());
- boton_baja = new JButton("Borrar" , icono_baja);
- boton_baja.setMaximumSize(new Dimension(120,25));
- boton_baja.addActionListener(new oyente_acciones());
- boton_editar = new JButton("Modificar" , icono_editar);
- boton_editar.setMaximumSize(new Dimension(120,25));
- boton_editar.addActionListener(new oyente_acciones());
- boton_busqueda = new JButton("Filtro" , icono_busqueda);
- boton_busqueda.setMaximumSize(new Dimension(120,25));
- boton_busqueda.addActionListener(new oyente_acciones());
- ButtonGroup grupo_botones = new ButtonGroup();
- grupo_botones.add(boton_alta);
- grupo_botones.add(boton_baja);
- grupo_botones.add(boton_editar);
- grupo_botones.add(boton_busqueda);
- boton_stadisticas = new JButton("Estadisticas" ,icono_estadisticas);
- boton_stadisticas.setMaximumSize(new Dimension(120,25));
- boton_stadisticas.addActionListener(new oyente_acciones());
- boton_alta_ext = new JButton("Nueva Explotacion" ,icono_alta);
- boton_alta_ext.setMaximumSize(new Dimension(120,25));
- boton_alta_ext.addActionListener(new oyente_acciones());
- boton_confirmar = new JButton("Confirmar");
- boton_confirmar.setMaximumSize(new Dimension(120,25));
- boton_confirmar.addActionListener(new oyente_acciones());
- boton_aniadir_relacion01 = new JButton("Añadir");
- boton_aniadir_relacion01.setMaximumSize(new Dimension(120,25));
- boton_aniadir_relacion01.addActionListener(new oyente_acciones());
- combo_relacion_1 = new JComboBox();
- combo_relacion_1.setPreferredSize(new Dimension(140,25));
- combo_relacion_1.setMaximumSize(new Dimension(140,25));
- combo_relacion_2 = new JComboBox();
- combo_relacion_2.setPreferredSize(new Dimension(140,25));
- combo_relacion_2.setMaximumSize(new Dimension(140,25));
- DefaultListCellRenderer cell_renderer = new DefaultListCellRenderer(){
- int parameter;
- void setParameter(int parameter){this.parameter = parameter;}
- @Override
- public Component getListCellRendererComponent(JList list, Object value, int index,boolean isSelected, boolean cellHasFocus)
- {
- JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
- String texto = label.getText();
- if(texto.contains("free")){texto = texto.replace("null", "Libre") ;label.setText(texto.split("&")[0]);label.setBackground(Color.green);}
- else{label.setBackground(Color.orange);}
- return label;
- }
- };
- combo_relacion_1.setRenderer(cell_renderer);
- combo_relacion_1.addActionListener(new oyente_acciones());
- actualiza_lista_relacion01(1);
- combo_relacion_2.setRenderer(cell_renderer);
- combo_relacion_2.addActionListener(new oyente_acciones());
- actualiza_lista_relacion02(1);
- etiqueta01 = new JLabel (icono_datos , JLabel.LEFT);
- etiqueta01.setMaximumSize(new Dimension(40,25));
- tabla.addMouseListener(new oyente_raton());
- modelo.setRowCount(5);
- modelo.addTableModelListener(new oyente_tabla());
- tabla.getColumnModel().getColumn(0).setMaxWidth(55);
- tabla.setAutoCreateRowSorter(true);
- Calendar c = Calendar.getInstance();
- c.add(Calendar.YEAR, -10);
- fecha01 = new JDateChooser(c.getTime());
- fecha01.addPropertyChangeListener("date" ,new oyente_fecha());
- fecha02 = new JDateChooser(c.getTime());
- fecha02.addPropertyChangeListener("date" , new oyente_fecha());
- //
- //TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tabla.getModel());
- //sorter.setSortable(0, false);
- //tabla.setRowSorter(sorter);
- Box vertical_00 = Box.createVerticalBox();
- vertical_00.add(boton_alta);
- vertical_00.add(Box.createVerticalStrut(8));
- vertical_00.add(boton_baja);
- vertical_00.add(Box.createVerticalStrut(8));
- vertical_00.add(boton_editar);
- vertical_00.add(Box.createVerticalStrut(8));
- vertical_00.add(boton_busqueda);
- vertical_00.add(Box.createVerticalStrut(8));
- vertical_00.add(boton_stadisticas);
- vertical_00.add(Box.createVerticalStrut(80));
- vertical_00.add(Box.createHorizontalStrut(50));
- // panel de control altas
- // lo que hare sera reutilizar este panel_control desde otrras clases
- Box horizontal_00 =Box.createHorizontalBox();
- Box vertical_02 = Box.createVerticalBox();
- horizontal_00.add(Box.createHorizontalStrut(8));
- horizontal_00.add(etiqueta01);
- horizontal_00.add(Box.createHorizontalStrut(8));
- horizontal_00.add(fecha01);
- horizontal_00.add(Box.createHorizontalStrut(8));
- horizontal_00.add(fecha02);
- /*
- horizontal_00.add(Box.createHorizontalStrut(8));
- horizontal_00.add(combo_relacion_1);
- horizontal_00.add(Box.createHorizontalStrut(8));
- horizontal_00.add(combo_relacion_2);
- horizontal_00.add(Box.createHorizontalStrut(8));
- Box horizontal_02 =Box.createHorizontalBox();
- horizontal_02.add(Box.createHorizontalStrut(364));
- horizontal_02.add(Box.createHorizontalStrut(8));
- horizontal_02.add(boton_confirmar);
- interruptor_relaciones = new JButton("Panel de Explotacion");
- horizontal_02.add(Box.createHorizontalStrut(8));
- horizontal_02.add(interruptor_relaciones);
- //
- */
- JPanel panel_relaciones ;
- Box horizontal_03 = Box.createHorizontalBox();
- horizontal_03.add(new JLabel("Selector relaciones"));
- horizontal_03.add(Box.createHorizontalStrut(8));
- horizontal_03.add( combo_relacion_1);
- horizontal_03.add(Box.createHorizontalStrut(8));
- horizontal_03.add(combo_relacion_2);
- horizontal_03.add(Box.createHorizontalStrut(8));
- panel_relaciones = new JPanel();
- panel_relaciones.setBorder(new TitledBorder(null, "Panel Visor", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
- panel_relaciones.add(horizontal_03);
- vertical_02.add(horizontal_00);
- vertical_02.add(Box.createVerticalStrut(10));
- //vertical_02.add(horizontal_02);
- vertical_02.add(panel_relaciones);
- vertical_02.add(Box.createVerticalStrut(10));
- panel_control = new JPanel();
- panel_control.setBorder(new TitledBorder(null, "Panel Control", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
- panel_control.add(vertical_02);
- //
- scroll.setPreferredSize(new Dimension(tabla.getPreferredSize().width,tabla.getRowHeight()*tabla.getRowCount()+100));
- this.setSize(900, 600);
- this.setPreferredSize(new Dimension(900,600));
- actualiza_tabla();
- JPanel panel_tabla = new JPanel();
- Box horizontal_01 =Box.createHorizontalBox();
- Box vertical_01 =Box.createVerticalBox();
- vertical_01.add(scroll);
- vertical_01.add(Box.createVerticalStrut(15));
- vertical_01.add(panel_control);
- horizontal_01.add(vertical_01);
- horizontal_01.add(vertical_00);
- panel_tabla.add(horizontal_01);
- this.setLayout(new BorderLayout());
- this.add(panel_tabla , BorderLayout.CENTER);
- //boton_alta.getModel().setPressed(true);
- //boton_alta.getModel().setSelected(true);
- this.setVisible(true);
- }
- public void actualiza_lista_relacion01(int parameter){
- if(parameter == 1)
- {
- combo_relacion_1.removeAllItems();
- lista_relacion_01 = CONSTANTES.parcela_DAO.consultaAll();
- for(Parcela nueva_relacion_01 : lista_relacion_01)
- {
- String parcela = nueva_relacion_01.getId_parcela() + " : " + "Parcela N: " + nueva_relacion_01.getId_parcela();
- combo_relacion_1.addItem(parcela);
- }
- combo_relacion_1.addItem("TODAS");
- }
- if(parameter == 2)
- {
- combo_relacion_1.removeAllItems();
- //todo
- if(nueva_entidad != null )
- {
- nueva_relacion_01 = new Parcela();
- nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(nueva_entidad.getParcela().getId_parcela());
- if(nueva_relacion_01.getId_parcela() == 0)
- {
- lista_relacion_01.clear();
- combo_relacion_1.addItem("No tiene ");
- }
- else
- {
- String parcela = nueva_relacion_01.getId_parcela() + " : " + "Parcela N: " + nueva_relacion_01.getId_parcela();
- combo_relacion_1.addItem(parcela);
- }
- }
- combo_relacion_1.addItem("TODAS");
- }
- }
- public void actualiza_lista_relacion02(int parameter){
- if(parameter == 1)
- {
- combo_relacion_2.removeAllItems();
- lista_relacion_02 = CONSTANTES.producto_DAO.consultaAll();
- for(Producto nueva_relacion_02 : lista_relacion_02)
- {
- String producto = nueva_relacion_02.getId_producto() + " : " + nueva_relacion_02.getNombre() ;
- combo_relacion_2.addItem(producto);
- }
- combo_relacion_2.addItem("TODAS");
- }
- if(parameter == 2)
- {
- combo_relacion_2.removeAllItems();
- if(nueva_entidad != null )
- {
- nueva_relacion_02 = new Producto();
- nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto());
- String producto = nueva_relacion_02.getId_producto() + " : " + nueva_relacion_02.getNombre() ;
- combo_relacion_2.addItem(producto);
- }
- else{
- nueva_relacion_02 = null;
- }
- if(nueva_relacion_02 == null)
- {
- lista_relacion_02.clear();
- combo_relacion_2.addItem("No tiene ");
- }
- combo_relacion_2.addItem("TODAS");
- }
- }
- public void actualiza_tabla(){
- lista_entidad = CONSTANTES.explotacion_DAO.consultaAll();
- modelo.setRowCount (0);
- for (Explotacion nueva_entidad : lista_entidad)
- {
- Object[] fila = new Object[4];
- fila [0] = nueva_entidad.getId_explotacion();
- fila [1] = nueva_entidad.getFecha_inicio();
- fila [2] = nueva_entidad.getFecha_fin();
- fila [3] = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto()).getNombre();
- modelo.addRow(fila);
- }
- modelo.addRow(new Object[4]);
- }
- public void actualiza_tabla(ArrayList<Explotacion> lista_gasto_obra_ext){
- modelo.setRowCount (0);
- for (Explotacion nueva_entidad : lista_gasto_obra_ext)
- {
- Object[] fila = new Object[4];
- fila [0] = nueva_entidad.getId_explotacion();
- fila [1] = nueva_entidad.getFecha_inicio();
- fila [2] = nueva_entidad.getFecha_fin();
- fila [3] = CONSTANTES.producto_DAO.consulta(nueva_entidad.getProducto().getId_producto()).getNombre();
- modelo.addRow(fila);
- }
- modelo.addRow(new Object[4]);
- }
- public void filtra(){
- modelo.setRowCount (0);
- ArrayList<Explotacion> lista_entidad_filtro = new ArrayList();
- int found = 0 ;
- for (Explotacion nueva_entidad : lista_entidad)
- {
- if(
- nueva_relacion_01 != null && comprueba_relacion(nueva_entidad , nueva_relacion_01) ||
- nueva_relacion_02 != null && comprueba_relacion02(nueva_entidad , nueva_relacion_02)
- )
- {
- lista_entidad_filtro.add(nueva_entidad);
- found++;
- }
- }
- actualiza_tabla (lista_entidad_filtro);
- if(found==0){
- JOptionPane.showMessageDialog(frame, "Comprueve los filtros de busqueda" , "Error en la busqueda" , JOptionPane.INFORMATION_MESSAGE );
- actualiza_tabla();
- reinicia_campos();
- }
- }
- public boolean comprueba_filtro(String filtro){
- if(filtro != null && filtro.equals("") ==false )
- {
- return true;
- }
- return false;
- }
- public Double string_to_double(String target){
- try{return Double.parseDouble(target.toString());}catch(NumberFormatException e){return 00.00;}
- }
- public int string_to_int(String target){
- try{return Integer.parseInt(target.toString());}catch(NumberFormatException e){return 0;}
- }
- public boolean comprueba_relacion(Explotacion nueva_entidad , Parcela nueva_relacion_01){
- if ( nueva_entidad.getParcela().getId_parcela() == nueva_relacion_01.getId_parcela() ) {return true;}
- return false;
- }
- public boolean comprueba_relacion02(Explotacion nueva_entidad ,Producto nueva_relacion_02){
- if ( nueva_entidad.getProducto().getId_producto() == nueva_relacion_02.getId_producto() ) {return true;}
- return false;
- }
- public void reinicia_campos(){
- }
- public boolean comprueba_campos(){
- if(nueva_relacion_01 != null && nueva_relacion_02!= null) {return true;}
- return false;}
- public boolean alta(){
- nueva_entidad = new Explotacion();
- nueva_entidad.setParcela(nueva_relacion_01);
- nueva_entidad.setProducto(nueva_relacion_02);
- nueva_entidad.setFecha_inicio(valor_fecha01);
- nueva_entidad.setFecha_fin(valor_fecha02);
- return CONSTANTES.explotacion_DAO.alta(nueva_entidad);
- }
- public void baja(){
- if(nueva_entidad.getId_explotacion()>0){
- CONSTANTES.explotacion_DAO.baja(nueva_entidad.getId_explotacion());
- }
- }
- public void modificacion(){
- if(nueva_entidad!=null){
- nueva_entidad.setParcela(nueva_relacion_01);
- nueva_entidad.setProducto(nueva_relacion_02);
- nueva_entidad.setFecha_inicio(valor_fecha01);
- nueva_entidad.setFecha_fin(valor_fecha02);
- CONSTANTES.explotacion_DAO.modificacion(nueva_entidad);
- }
- }
- public void limpia_memoria(){
- nueva_relacion_01 = null;
- nueva_relacion_02 = null;
- nueva_entidad = null;
- lista_entidad.clear();
- lista_relacion_01.clear();
- lista_relacion_02.clear();
- }
- class oyente_fecha implements PropertyChangeListener{
- public void propertyChange(PropertyChangeEvent evento) {
- JDateChooser selector_fecha = new JDateChooser();
- if(evento.getSource().getClass().equals(selector_fecha.getClass()))
- {
- selector_fecha = (JDateChooser) evento.getSource();
- if(selector_fecha == fecha01)
- {
- java.util.Date utilDate = new java.util.Date();
- utilDate = (java.util.Date) (evento.getNewValue());
- java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
- valor_fecha01 = sqlDate;
- }
- if(selector_fecha == fecha02)
- {
- java.util.Date utilDate = new java.util.Date();
- utilDate = (java.util.Date) (evento.getNewValue());
- java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
- valor_fecha02 = sqlDate;
- }
- }
- }
- }
- class oyente_acciones implements ActionListener{
- JButton boton = new JButton();
- JToggleButton boton_toogle = new JToggleButton();
- JComboBox combo = new JComboBox();
- public void actionPerformed(ActionEvent evento) {
- if(evento.getSource().getClass().equals(combo.getClass()) )
- {
- combo = (JComboBox) evento.getSource();
- if(combo == combo_relacion_1)
- {
- String texto = (String) combo.getSelectedItem();
- if(texto!= null)
- {
- if(!texto.contains("tiene") && texto.contains("free"))
- {
- int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
- nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(target);
- }
- if(texto.equals("TODAS")){
- actualiza_lista_relacion01(1);
- nueva_relacion_01 =null;
- }
- else if(!texto.contains("tiene") && !texto.equals("TODAS") )
- {
- int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
- nueva_relacion_01 = CONSTANTES.parcela_DAO.consulta(target);
- }
- }
- memoria = combo.getSelectedIndex();
- }
- if(combo == combo_relacion_2)
- {
- String texto = (String) combo.getSelectedItem();
- if(texto!= null)
- {
- if(!texto.contains("tiene") && texto.contains("free"))
- {
- int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
- nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(target);
- }
- if(texto.equals("TODAS")){
- actualiza_lista_relacion02(1);
- nueva_relacion_02 =null;
- }
- else if(!texto.contains("tiene") && !texto.equals("TODAS") )
- {
- int target = Integer.parseInt(texto.substring(0 , texto.indexOf(":")-1));
- nueva_relacion_02 = CONSTANTES.producto_DAO.consulta(target);
- }
- }
- memoria = combo.getSelectedIndex();
- }
- }
- if(evento.getSource().getClass().equals(boton.getClass()))
- {
- boton = (JButton) evento.getSource();
- if(boton==boton_stadisticas && nueva_entidad!= null)
- {
- try {
- Dialogo_reportes nuevo_dialogo = new Dialogo_reportes(nueva_entidad , "" , null);
- nuevo_dialogo.setVisible(true);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if(boton==boton_alta && comprueba_campos())
- {
- alta();
- limpia_memoria();
- actualiza_tabla();
- }
- if(boton==boton_editar)
- {
- modificacion();
- limpia_memoria();
- actualiza_lista_relacion01(2);
- actualiza_lista_relacion02(2);
- actualiza_tabla();
- }
- if(boton==boton_baja)
- {
- baja();
- limpia_memoria();
- actualiza_lista_relacion01(2);
- actualiza_lista_relacion02(2);
- actualiza_tabla();
- }
- if(boton==boton_busqueda)
- {
- filtra( );
- }
- }
- }
- }
- class oyente_enfoque implements FocusListener{
- public void focusGained(FocusEvent evento) {
- JTextField input = (JTextField) evento.getSource();
- }
- public void focusLost(FocusEvent arg0) {
- // TODO Auto-generated method stub
- }
- }
- class oyente_tabla implements TableModelListener{
- public void tableChanged(TableModelEvent evento)
- {
- }
- }
- class oyente_raton extends MouseAdapter{
- public void mouseClicked(MouseEvent evento){
- tabla.convertRowIndexToView(0);
- //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
- int fila =tabla.getRowSorter().convertRowIndexToModel(tabla.rowAtPoint(evento.getPoint()));
- //int fila = tabla.rowAtPoint(evento.getPoint());
- if(fila >-1 )
- {
- try{
- nueva_entidad = CONSTANTES.explotacion_DAO.consulta(Integer.parseInt(modelo.getValueAt(fila,0).toString()));
- if(nueva_entidad == null){System.out.println("nulllll");}
- fecha01.setDate( (Date) (modelo.getValueAt(fila,1)));
- fecha02.setDate( (Date) (modelo.getValueAt(fila,2)));
- actualiza_lista_relacion01(2);
- actualiza_lista_relacion02(2);
- }
- catch (Exception e)
- {
- JOptionPane.showMessageDialog(frame, "Error en cargar el objeto desde la base de datos" , "Error de database" , JOptionPane.INFORMATION_MESSAGE );
- actualiza_tabla();
- reinicia_campos();
- }
- finally{
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement