package com.langtech.plm.form;
import javax.swing.*;
import javax.swing.table.*;

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

public class JButtonEditor extends AbstractCellEditor implements TableCellEditor {
    private JButton button;
    private int row;
    private int column;

    public JButtonEditor(String text, ActionListener actionListener) {
        button = new JButton(text);
        button.addActionListener(actionListener);
    }

    public Component getTableCellEditorComponent(JTable table, Object value,
                                                 boolean isSelected, int row, int column) {
        this.row = row;
        this.column = column;
        button.setText(value.toString());
        return button;
    }

    public Object getCellEditorValue() {
        return new String(button.getText());
    }
}