Advertisement
Guest User

Untitled

a guest
Jun 15th, 2015
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PersonTableModel extends AbstractTableModel {
  2.  
  3.     private static final long serialVersionUID = 1L;
  4.  
  5.     public static final int OBJECT_COL = -1;
  6.     private static final int PERSON_ID = 0;
  7.     private static final int LAST_NAME_COL = 1;
  8.     private static final int FIRST_NAME_COL = 2;
  9.     private static final int FK_COUNTY_ID = 3;
  10.  
  11.     private String[] columnNames = { "Person_ID", "Last_Name", "First_Name",
  12.             "County_ID" };
  13.    
  14.     private List<Person> persons;
  15.  
  16.     public PersonTableModel(List<Person> thePersons) {
  17.         persons = thePersons;
  18.     }
  19.  
  20.     @Override
  21.     public int getColumnCount() {
  22.         return columnNames.length;
  23.     }
  24.  
  25.     @Override
  26.     public int getRowCount() {
  27.         return persons.size();
  28.     }
  29.  
  30.     @Override
  31.     public String getColumnName(int col) {
  32.         return columnNames[col];
  33.     }
  34.  
  35.     @Override
  36.     public Object getValueAt(int row, int col) {
  37.  
  38.         Person tempPerson = persons.get(row);
  39.  
  40.         switch (col) {
  41.         case LAST_NAME_COL:
  42.             return tempPerson.getLastName();
  43.         case FIRST_NAME_COL:
  44.             return tempPerson.getFirstName();
  45.         case PERSON_ID:
  46.             return tempPerson.getId();
  47.         case FK_COUNTY_ID:
  48.             return tempPerson.getCountyId();
  49.         case OBJECT_COL:
  50.             return tempPerson;
  51.         default:
  52.             return tempPerson.getLastName();
  53.         }
  54.     }
  55.  
  56.     @SuppressWarnings({ "unchecked", "rawtypes" })
  57.     public Class getColumnClass(int c) {
  58.         return getValueAt(0, c).getClass();
  59.     }
  60.  
  61. }
Advertisement
RAW Paste Data Copied
Advertisement