View Javadoc

1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   */
14  /*
15   * This file has been modified by Chris Pheby in accordance with Section 4.2
16   * of the Apache Software License
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  }