KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > sandbox > TableTest


1 package com.opensymphony.webwork.sandbox;
2
3 import javax.swing.event.TableModelListener JavaDoc;
4 import javax.swing.table.TableModel JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7
8 /**
9  * User: plightbo
10  * Date: Aug 10, 2005
11  * Time: 7:56:08 PM
12  */

13 public class TableTest {
14     PersonTableModel people;
15
16     public String JavaDoc 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 JavaDoc {
28         List JavaDoc people = new ArrayList JavaDoc();
29
30         public int getRowCount() {
31             return people.size();
32         }
33
34         public int getColumnCount() {
35             return 2;
36         }
37
38         public String JavaDoc 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 JavaDoc getColumnClass(int columnIndex) {
50             switch (columnIndex) {
51                 case 0:
52                     return Long JavaDoc.class;
53                 case 1:
54                     return String JavaDoc.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 JavaDoc getValueAt(int rowIndex, int columnIndex) {
65             Person person = (Person) people.get(rowIndex);
66             switch (columnIndex) {
67                 case 0:
68                     return new Long JavaDoc(person.getId());
69                 case 1:
70                     return person.getName();
71                 default:
72                     return null;
73             }
74         }
75
76         public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {
77         }
78
79         public void addTableModelListener(TableModelListener JavaDoc l) {
80         }
81
82         public void removeTableModelListener(TableModelListener JavaDoc l) {
83         }
84
85         public void addPerson(Person person) {
86             people.add(person);
87         }
88     }
89 }
90
Popular Tags