1 package com.opensymphony.webwork.sandbox; 2 3 import javax.swing.event.TableModelListener ; 4 import javax.swing.table.TableModel ; 5 import java.util.ArrayList ; 6 import java.util.List ; 7 8 13 public class TableTest { 14 PersonTableModel people; 15 16 public String execute() { 17 people = new PersonTableModel(); 18 people.addPerson(new Person()); 19 20 return "success"; 21 } 22 23 public PersonTableModel getPeople() { 24 return people; 25 } 26 27 static class PersonTableModel implements TableModel { 28 List people = new ArrayList (); 29 30 public int getRowCount() { 31 return people.size(); 32 } 33 34 public int getColumnCount() { 35 return 2; 36 } 37 38 public String getColumnName(int columnIndex) { 39 switch (columnIndex) { 40 case 0: 41 return "ID"; 42 case 1: 43 return "Name"; 44 default: 45 return "Unknown"; 46 } 47 } 48 49 public Class getColumnClass(int columnIndex) { 50 switch (columnIndex) { 51 case 0: 52 return Long .class; 53 case 1: 54 return String .class; 55 default: 56 return null; 57 } 58 } 59 60 public boolean isCellEditable(int rowIndex, int columnIndex) { 61 return false; 62 } 63 64 public Object getValueAt(int rowIndex, int columnIndex) { 65 Person person = (Person) people.get(rowIndex); 66 switch (columnIndex) { 67 case 0: 68 return new Long (person.getId()); 69 case 1: 70 return person.getName(); 71 default: 72 return null; 73 } 74 } 75 76 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 77 } 78 79 public void addTableModelListener(TableModelListener l) { 80 } 81 82 public void removeTableModelListener(TableModelListener l) { 83 } 84 85 public void addPerson(Person person) { 86 people.add(person); 87 } 88 } 89 } 90 | Popular Tags |