1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.gui;
19
20 import org.jadira.dependencynavigator.controller.model.DuplicatesListManager;
21 import org.jadira.dependencynavigator.model.Duplicate;
22
23 import javax.swing.event.TableModelListener;
24 import javax.swing.table.TableModel;
25
26 public class DuplicatesTableModel implements TableModel, SelectableTableModel {
27
28 private DuplicatesListManager duplicatesListManager;
29
30 public DuplicatesTableModel(DuplicatesListManager duplicatesListManager) {
31 this.duplicatesListManager = duplicatesListManager;
32 }
33
34 public int getColumnCount() {
35 return 2;
36 }
37
38 public int getRowCount() {
39 return duplicatesListManager.size();
40 }
41
42 public boolean isCellEditable(int rowIndex, int columnIndex) {
43 return false;
44 }
45
46 public Class<String> getColumnClass(int columnIndex) {
47 return String.class;
48 }
49
50 public Object getValueAt(int rowIndex, int columnIndex) {
51 Duplicate duplicate = duplicatesListManager.get(rowIndex);
52 switch (columnIndex) {
53 case 0:
54 return duplicate.getIdentifier();
55 case 1:
56 return duplicate.getVersions();
57 default:
58 throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
59 }
60 }
61
62 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
63 throw new UnsupportedOperationException();
64 }
65
66 public String getColumnName(int columnIndex) {
67 switch (columnIndex) {
68 case 0:
69 return "Artifact";
70 case 1:
71 return "Versions";
72 default:
73 throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
74 }
75 }
76
77 public void addTableModelListener(TableModelListener l) {
78 }
79
80 public void removeTableModelListener(TableModelListener l) {
81 }
82
83 public boolean isSelected(int row) {
84 return duplicatesListManager.get(row).isSelected();
85 }
86 }