Package vista

Source Code of vista.EditorServicio

package vista;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

import base.Servicio;
import base.ServicioDTO;



  public class EditorServicio extends AbstractCellEditor implements TableCellEditor, ActionListener {

      Boolean currentValue;
      int fila;
      int columna;
      JButton button;
      JButton button2;
      protected static final String EDIT = "edit";
      private TablaServicio jTable1;
      private AbmServicio a;
    private JButton button3;

      public EditorServicio(TablaServicio jTable1, AbmServicio abm) {
          button2 = new JButton(new ImageIcon(getClass().getResource("/imagenes/eliminar.png")));
          button2.setActionCommand(EDIT);
          button2.addActionListener(this);
          button2.setBorderPainted(false);
        
          button = new JButton(new ImageIcon(getClass().getResource("/imagenes/editar.png")));
          button.setActionCommand(EDIT);
          button.addActionListener(this);
          button.setBorderPainted(false);

          button3 = new JButton(new ImageIcon(getClass().getResource("/imagenes/lupa.png")));
          button3.setActionCommand(EDIT);
          button3.addActionListener(this);
          button3.setBorderPainted(false);
       
          this.a=abm;
          this.jTable1 = jTable1;
      }

      public void actionPerformed(ActionEvent e) {
       
          Servicio s = new Servicio();
          s = ServicioDTO.buscarServicio((Integer.parseInt((String) jTable1.getValueAt(fila, 0))));
          if (columna == 7){
            int option=JOptionPane.showConfirmDialog(null, "�Seguro que desea eliminar el servicio?");
               if (option==JOptionPane.YES_OPTION)
                 ServicioDTO.EliminaServicio(s);
           }
          else
            if(columna == 9){
              MostrarServicio m = new MostrarServicio(this.a, s);
              a.removeAll();
              a.add(m);
              a.repaint();
            }
            else
          ModificarServicio m = new ModificarServicio(this.a, s);
            a.removeAll();
            a.add(m);
            a.repaint();
          }
          fireEditingStopped();
          a.cargarTabla();
         
      }

      //Implement the one CellEditor method that AbstractCellEditor doesn't.
      public Object getCellEditorValue() {
          return currentValue;
      }

      //Implement the one method defined by TableCellEditor.
      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          // Va a mostrar el bot�n solo en la �ltima fila.
          // de otra forma muestra un espacio en blanco.
          //if (row == table.getModel().getRowCount() - 1) {
           
              currentValue = (Boolean) value;
              fila = row;
              columna = column;
              if(column == 5)
                return button;
              else
                if(column == 7)
                  return button2;
                else return button3;
          //}
         // return new JLabel();
      }
  }
TOP

Related Classes of vista.EditorServicio

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.