Coverage Report - us.daveread.basicquery.util.TableMap
 
Classes in this File Line Coverage Branch Coverage Complexity
TableMap
100%
19/19
100%
2/2
0
 
 1  
 package us.daveread.basicquery.util;
 2  
 
 3  
 import javax.swing.event.TableModelListener;
 4  
 import javax.swing.event.TableModelEvent;
 5  
 import javax.swing.table.AbstractTableModel;
 6  
 import javax.swing.table.TableModel;
 7  
 
 8  
 /**
 9  
  * In a chain of data manipulators some behaviour is common. TableMap
 10  
  * provides most of this behavour and can be subclassed by filters
 11  
  * that only need to override a handful of specific methods. TableMap
 12  
  * implements TableModel by routing all requests to its model, and
 13  
  * TableModelListener by routing all events to its listeners. Inserting
 14  
  * a TableMap which has not been subclassed into a chain of table filters
 15  
  * should have no effect.
 16  
  * 
 17  
  * <p>
 18  
  * Original version 1.4 12/17/97
 19  
  * </p>
 20  
  * 
 21  
  * @author Philip Milne
 22  
  */
 23  
 
 24  
 public class TableMap extends AbstractTableModel implements TableModelListener {
 25  
   /**
 26  
    * Serial UID
 27  
    */
 28  
   private static final long serialVersionUID = -5521533255340043234L;
 29  
   
 30  
   /**
 31  
    * The table model backing this table map
 32  
    */
 33  
   private TableModel model;
 34  
 
 35  
   /**
 36  
    * No operation
 37  
    */
 38  25
   public TableMap() {
 39  25
   }
 40  
 
 41  
   /**
 42  
    * Implements TableModel by forwarding all messages
 43  
    * to the model
 44  
    * 
 45  
    * @return The table model
 46  
    */
 47  
   public TableModel getModel() {
 48  171
     return model;
 49  
   }
 50  
 
 51  
   /**
 52  
    * Sets the table model for this model and adds a listener to the model that's
 53  
    * notified each time a change occurs
 54  
    * 
 55  
    * @param pModel
 56  
    *          The TableModel
 57  
    */
 58  
   public void setModel(TableModel pModel) {
 59  27
     this.model = pModel;
 60  27
     model.addTableModelListener(this);
 61  27
   }
 62  
 
 63  
   /**
 64  
    * Remove the model from this instance, removing this instance as a listener
 65  
    * as well
 66  
    * 
 67  
    * TODO Either don't pass the model or verify that it is the current model
 68  
    * backing this instance
 69  
    * 
 70  
    * @param pModel
 71  
    *          The TableModel
 72  
    */
 73  
   public void removeModel(TableModel pModel) {
 74  2
     pModel.removeTableModelListener(this);
 75  2
     this.model = null;
 76  2
   }
 77  
 
 78  
   /**
 79  
    * Returns the value of the cell at aRow and aColumn
 80  
    * 
 81  
    * @param aRow
 82  
    *          The row whose value is queried
 83  
    * @param aColumn
 84  
    *          The column whose value is queried
 85  
    * 
 86  
    * @return The object at the specified cell
 87  
    */
 88  
   public Object getValueAt(int aRow, int aColumn) {
 89  3
     return model.getValueAt(aRow, aColumn);
 90  
   }
 91  
 
 92  
   /**
 93  
    * Sets the value in the cell at aRow and aColumn to aValue
 94  
    * 
 95  
    * @param aValue
 96  
    *          The new value
 97  
    * @param aRow
 98  
    *          The row whose value is changed
 99  
    * @param aColumn
 100  
    *          The column whose value is changed
 101  
    * 
 102  
    */
 103  
   public void setValueAt(Object aValue, int aRow, int aColumn) {
 104  1
     model.setValueAt(aValue, aRow, aColumn);
 105  1
   }
 106  
 
 107  
   /**
 108  
    * Returns the number of rows in the model
 109  
    * 
 110  
    * @return The number of rows
 111  
    */
 112  
   public int getRowCount() {
 113  1
     return (model == null) ? 0 : model.getRowCount();
 114  
   }
 115  
 
 116  
   /**
 117  
    * Returns the number of columns in the model
 118  
    * 
 119  
    * @return The number of columns
 120  
    */
 121  
   public int getColumnCount() {
 122  5
     return (model == null) ? 0 : model.getColumnCount();
 123  
   }
 124  
 
 125  
   /**
 126  
    * Returns the column name at the column index
 127  
    * 
 128  
    * @param aColumn
 129  
    *          The index of the column
 130  
    * 
 131  
    * @return The object with the name of the column
 132  
    */
 133  
   public String getColumnName(int aColumn) {
 134  6
     return model.getColumnName(aColumn);
 135  
   }
 136  
 
 137  
   /**
 138  
    * Returns the most specific superclass for all the cell values
 139  
    * in the column
 140  
    * 
 141  
    * @param aColumn
 142  
    *          The index of the column
 143  
    * 
 144  
    * @return The common ancestor class of the object values
 145  
    *         in the model
 146  
    */
 147  
   public Class<?> getColumnClass(int aColumn) {
 148  1
     return model.getColumnClass(aColumn);
 149  
   }
 150  
 
 151  
   /**
 152  
    * Returns true if the cell at row and column is editable
 153  
    * If the cell is not editable then the setValueAt will not
 154  
    * change the value
 155  
    * 
 156  
    * @param row
 157  
    *          The row whose value is to be queried
 158  
    * @param column
 159  
    *          The column whose value is to be queried
 160  
    * 
 161  
    * @return The object with the true value if the cell is editable
 162  
    */
 163  
   public boolean isCellEditable(int row, int column) {
 164  1
     return model.isCellEditable(row, column);
 165  
   }
 166  
 
 167  
   /**
 168  
    * To fulfill the TableModelListener interface
 169  
    * By default forward all events to all the listeners
 170  
    * The notification that tells the listeners the exact
 171  
    * range of cells,rows,or columns that changed
 172  
    * 
 173  
    * @param e
 174  
    *          The table model event object that represents the event-fired.
 175  
    */
 176  
   public void tableChanged(TableModelEvent e) {
 177  9
     fireTableChanged(e);
 178  9
   }
 179  
 }