1 package net.sourceforge.argval.packageinfo.swing;
2
3
4 import java.util.ArrayList;
5
6 import javax.swing.event.TableModelListener;
7 import javax.swing.table.TableModel;
8
9 import net.sourceforge.argval.packageinfo.PackageInfo;
10 import net.sourceforge.argval.packageinfo.PackageInfoManager;
11 import net.sourceforge.argval.packageinfo.impl.PackageInfoManagerImpl;
12
13
14
15
16
17
18
19
20 final public class PackageInfoTableModel implements TableModel {
21
22 public final String columnNames[] =
23 new String[] {
24 "Specification Title", "Specification Version", "Specification Vendor",
25 "Implementation Title", "Implementation Version", "Implementation Vendor"
26 };
27
28 private final ArrayList<TableModelListener> tableModelListenerList = new ArrayList<TableModelListener>();
29
30 private final PackageInfoManager manager;
31
32
33 public PackageInfoTableModel(PackageInfoManager manager) {
34 super();
35 this.manager = manager;
36 }
37
38
39 public Class<?> getColumnClass(int columnIndex) {
40 return null;
41 }
42
43
44 public int getColumnCount() {
45 return columnNames.length;
46 }
47
48 public String getColumnName(int columnIndex) {
49 return (columnIndex < columnNames.length) ? columnNames[columnIndex] : null;
50 }
51
52 public int getRowCount() {
53 return manager.getTitleSet().size();
54 }
55
56
57 public Object getValueAt(int rowIndex, int columnIndex) {
58 String title = (String)manager.getTitleSet().toArray()[rowIndex];
59 PackageInfo packageInfo = manager.getPackage(title);
60 final Object result;
61 switch (columnIndex) {
62 case 0:
63 result = packageInfo.getSpecificationTitle();
64 break;
65 case 1:
66 result = packageInfo.getSpecificationVersion();
67 break;
68 case 2:
69 result = packageInfo.getSpecificationVendor();
70 break;
71 case 3:
72 result = packageInfo.getImplementationTitle();
73 break;
74 case 4:
75 result = packageInfo.getImplementationVersion();
76 break;
77 case 5:
78 result = packageInfo.getImplementationVendor();
79 break;
80 default:
81 result = null;
82 }
83 return result;
84 }
85
86
87 public boolean isCellEditable(int rowIndex, int columnIndex) {
88 return false;
89 }
90
91 public void setValueAt(Object value, int rowIndex, int columnIndex) {
92
93 }
94
95
96 public void addTableModelListener(TableModelListener tml) {
97 if (! tableModelListenerList.contains(tml)) {
98 tableModelListenerList.add(tml);
99 }
100 }
101
102 public void removeTableModelListener(TableModelListener tml) {
103 tableModelListenerList.remove(tml);
104 }
105
106 }