package util.swing;

import javax.swing.table.*;

import java.util.Comparator;

/**
  * <i>Abstract</i> base implementation of {@link TableEntryDescriptor}.
  *
  * <p>This base implementations is useful when you want to define a TableEntryDescriptor that describes rows
  * that are non-editable and use the default renderer for each cell, based on the cell value's class.
  *
  * @see util.swing.AbstractTableModel
  *
  * @author Steffen Zschaler
  * @version 2.0 27/07/1999
  * @since v2.0
  */
public abstract class AbstractTableEntryDescriptor extends Object implements TableEntryDescriptor {

  /**
    * Dummy constructor, does nothing but call <code>super()</code>.
    */
  public AbstractTableEntryDescriptor() {
    super();
  }

  /**
    * Returns <code>null</code> to indicate that the default cell renderer is to be used based on the cell
    * value's class.
    *
    * @override Sometimes Override this method if you want to define specialized cell renderers for certain
    * columns.
    */
  public TableCellRenderer getCellRenderer (int nIdx) {
    return null;
  }

  /**
    * Returns <code>null</code> to indicate that the default cell editor is to be used based on the cell
    * value's class.
    *
    * @override Sometimes Override this method if you want to define specialized cell editors for certain
    * columns. Note that you will also have to override {@link #isElementEditable} and {@link #setValueAt}
    * for complete editing support.
    */
  public TableCellEditor getCellEditor (int nIdx) {
    return null;
  }

  /**
    * Returns <code>false</code> to indicate that no cell is editable in the entire table.
    *
    * @override Sometimes Override this method if you want to allow editing for certain cells. The actual class
    * of the record passed as <code>oRecord</code> depends on the {@link util.swing.AbstractTableModel TableModel}
    * with which you work. See {@link util.swing.AbstractTableModel#getRecord} in the concrete TableModel for a
    * description.
    * Note that you will also have to override {@link #setValueAt} for complete editing support. It is also
    * recommended that you override {@link #getCellEditor} if you override this method.
    */
  public boolean isElementEditable (Object oRecord, int nIdx) {
    return false;
  }

  /**
    * Does nothing because AbstractTableEntryDescriptor does not allow editing by default.
    *
    * @override Sometimes Override this method if you want to allow editing for certain cells. The actual class
    * of the record passed as <code>oRecord</code> depends on the {@link util.swing.AbstractTableModel TableModel}
    * with which you work. See {@link util.swing.AbstractTableModel#getRecord} in the concrete TableModel for a
    * description.
    * Note that you will also have to override {@link #isElementEditable} for complete editing support. It is
    * also recommended that you override {@link #getCellEditor} if you override this method.
    */
  public void setValueAt (Object oRecord, int nIdx, Object oValue) {}
  
  /** 
    * Returns false because AbstractTableEntryDescriptor does not allow sorting by column by default.
    *
    * @param nIdx the index of the column concerned.
    *
    * @return whether or not records can be sorted by the specified column.
    *
    * @override Sometimes Override this method if you want to support sorting by column
    */
  public boolean canSortByColumn(int nIdx) {
    return false;
  }
  
  /** 
    * Returns <code>null</code> because AbstractTableEntryDescriptor does not allow sorting by column by default.
    *
    * @param nIdx the index of the column concerned.
    *
    * @override Sometimes Override this method if you want to support sorting by column
    */
  public Comparator getColumnOrder(int nIdx) {
    return null;
  }
}