package osa.attribute.atgrammar.gui.tables.attributes_table;

import javax.swing.*;
import javax.swing.table.*;

import osa.attribute.atgrammar.grammar.*;
import osa.attribute.atgrammar.grammar.symbols.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: </p>
 * <p>Company: </p>
 * @author not attributable
 * @version
 */

public class AttributesTM
  extends AbstractTableModel
  {

  Symbol symbol=null;

  protected static int counter=0;

  public AttributesTM(Symbol symbol)
    {
    this.symbol=symbol;
    }

  public int getRowCount()
    {
    if(symbol!=null)
      {
      return symbol.getAttrubutesCount();
      }
    return 0;
    }

  public int getColumnCount()
    {
    return 4;
    }

  public String getColumnName(int columnIndex)
    {
    String return_value;

    switch(columnIndex)
          {
          case 0:
            return_value="¹";
            break;
          case 1:
            return_value="Èìÿ";
            break;
          case 2:
            return_value="Òèï";
            break;
          case 3:
            return_value="Êëàññ";
            break;
          default:
            return_value="???";
          }
    return return_value;
    }

  public boolean isCellEditable(int rowIndex, int columnIndex)
    {
    if(columnIndex==0||columnIndex==3)
      {
      return false;
      }
    return true;
    }

  public Object getValueAt(int rowIndex, int columnIndex)
    {
    Attribute attribute;
    attribute=symbol.getAttributeAt(rowIndex);
    return attribute;
    }

  public void addRow()
    {
    System.err.println("begin");
    int rows=this.getRowCount();
    rows++;
    counter++;
    Attribute new_attribute=new Attribute("Àòðèáóò "+new Integer(counter).toString());
    symbol.addAttribute(new_attribute);
    fireTableRowsInserted(rows,rows);


    System.err.println("end");
    }

  public void removeRow(int row)
    {
    Attribute attribute=symbol.getAttributeAt(row);
    symbol.removeAttributeAt(row);
    this.fireTableRowsDeleted(row,row);
    }

  }