/*
 * Copyright 2018 Andres.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.eljavatar.swingutils.core.editorcomponents;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author ElJavatar - Andres Mauricio (http://www.eljavatar.com)
 */
public abstract class ButtonCellEditor extends AbstractCellEditor implements TableCellEditor, ActionListener {

    private final JButton editorButton;
    private JTable jTable;
    private int rowSelected;
    private int colSelected;
    private boolean isPushed;

    public ButtonCellEditor(JButton jButton) {
        this.editorButton = jButton;
//        System.out.println("Entramos al constructor");
        jButton.addActionListener(ButtonCellEditor.this);
        
        //fireEditingStopped();
    }

    private void setjTable(JTable jTable) {
        this.jTable = jTable;
    }

    private void setRowSelected(int rowSelected) {
        this.rowSelected = rowSelected;
    }

    private void setColSelected(int colSelected) {
        this.colSelected = colSelected;
    }
    
    public abstract void action(JTable table, int row, int column);

    @Override
    public final Object getCellEditorValue() {
//        System.out.println("Obtenemos valor");
        if (isPushed)  {
            //action(jTable, rowSelected, colSelected);
        }
        
        isPushed = false;
        return null;
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
//        System.out.println("Iniciamos editor");
        
        if (isSelected) {
            editorButton.setForeground(table.getSelectionForeground());
            editorButton.setBackground(table.getSelectionBackground());
        } else {
            editorButton.setForeground(table.getForeground());
            editorButton.setBackground(table.getBackground());
        }
        
        setjTable(table);
        setRowSelected(row);
        setColSelected(column);
        
        if (isPushed)  {
            //action(jTable, rowSelected, colSelected);
        } else {
            isPushed = true;
        }
        
        return editorButton;
    }

    @Override
    public boolean stopCellEditing() {
//        System.out.println("\nStop edicion\n");
        isPushed = false;
        return super.stopCellEditing();
    }

    @Override
    protected void fireEditingStopped() {
//        System.out.println("\nFired edicion\n");
        super.fireEditingStopped();
        isPushed = false;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
//        System.out.println("\nParamos edicion\n");
        super.fireEditingStopped();
        isPushed = false;
        action(jTable, rowSelected, colSelected);
    }

}

@@ -1095,24 +1095,51 @@
 stener %7B%0D%0A%0D%0A
+    private Object value;%0D%0A
     private 
@@ -1163,24 +1163,30 @@
 torButton;%0D%0A
+    %0D%0A
     private 
@@ -1264,39 +1264,8 @@
 ed;%0D
-%0A    private boolean isPushed;%0D
 %0A%0D%0A 
@@ -1353,66 +1353,8 @@
 n;%0D%0A
-//        System.out.println(%22Entramos al constructor%22);%0D%0A
     
@@ -1412,51 +1412,8 @@
 );%0D%0A
-        %0D%0A        //fireEditingStopped();%0D%0A
     
@@ -1704,22 +1704,18 @@
 %0A    %7D%0D%0A
-    
 %0D%0A
+
     publ
@@ -1836,34 +1836,32 @@
 rValue() %7B%0D%0A
-//
         
 System.out.p
@@ -1852,198 +1852,20 @@
     
-System.out.println(%22Obtenemos valor%22);%0D%0A        if (isPushed)  %7B%0D%0A            //action(jTable, rowSelected, colSelected);%0D%0A        %7D%0D%0A        %0D%0A        isPushed = false;%0D%0A        return null
+return value
 ;%0D%0A 
@@ -2012,69 +2012,8 @@
  %7B%0D%0A
-//        System.out.println(%22Iniciamos editor%22);%0D%0A        %0D%0A
     
@@ -2334,34 +2334,26 @@
 %0A        %7D%0D%0A
-        
 %0D%0A
+
         setj
@@ -2430,24 +2430,16 @@
 lumn);%0D%0A
-        
 %0D%0A      
@@ -2444,150 +2444,48 @@
     
-if (isPushed)  %7B%0D%0A            //action(jTable, rowSelected, colSelected);%0D%0A        %7D else %7B%0D%0A            isPushed = true;%0D%0A        %7D%0D%0A        
+value = table.getValueAt(row, column);%0D%0A
 %0D%0A  
@@ -2580,86 +2580,8 @@
  %7B%0D%0A
-//        System.out.println(%22%5CnStop edicion%5Cn%22);%0D%0A        isPushed = false;%0D%0A
     
@@ -2688,60 +2688,8 @@
  %7B%0D%0A
-//        System.out.println(%22%5CnFired edicion%5Cn%22);%0D%0A
     
@@ -2725,35 +2725,8 @@
 );%0D%0A
-        isPushed = false;%0D%0A
     
@@ -2799,62 +2799,8 @@
  %7B%0D%0A
-//        System.out.println(%22%5CnParamos edicion%5Cn%22);%0D%0A
     
@@ -2836,35 +2836,8 @@
 );%0D%0A
-        isPushed = false;%0D%0A
     

Ajuste en clase ButtonCellEditor