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  
21  import org.jadira.dependencynavigator.controller.model.DuplicatesListManager;
22  import org.jadira.dependencynavigator.model.ArtifactInstanceMap;
23  
24  import javax.swing.event.TableModelListener;
25  import javax.swing.table.TableModel;
26  
27  public class VersionsTableModel implements TableModel, SelectableTableModel {
28  
29      private DuplicatesListManager duplicatesListManager;
30  
31      public VersionsTableModel(DuplicatesListManager duplicatesListManager) {
32          this.duplicatesListManager = duplicatesListManager;
33      }
34  
35      public boolean isSelected(int row) {
36          return duplicatesListManager.getVersionsListManager().get(row).isSelected();
37      }
38  
39      public int getColumnCount() {
40          return 4;
41      }
42  
43      public int getRowCount() {
44          return duplicatesListManager.getVersionsListManager().size();
45      }
46  
47      public boolean isCellEditable(int rowIndex, int columnIndex) {
48          return false;
49      }
50  
51      public Class<String> getColumnClass(int columnIndex) {
52          return String.class;
53      }
54  
55      public Object getValueAt(int rowIndex, int columnIndex) {
56          ArtifactInstanceMap instanceMap = duplicatesListManager.getVersionsListManager().get(rowIndex);
57          switch (columnIndex) {
58          case 0:
59              return instanceMap.getGroupId();
60          case 1:
61              return instanceMap.getArtifactId();
62          case 2:
63              return instanceMap.getVersion();
64          case 3:
65              return String.valueOf(instanceMap.getInstances().size());
66          default:
67              throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
68          }
69      }
70  
71      public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
72          throw new UnsupportedOperationException();
73      }
74  
75      public String getColumnName(int columnIndex) {
76          switch (columnIndex) {
77          case 0:
78              return "Group";
79          case 1:
80              return "Artifact";
81          case 2:
82              return "Version";
83          case 3:
84              return "Instances";
85          default:
86              throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
87          }
88      }
89  
90      public void addTableModelListener(TableModelListener l) {
91      }
92  
93      public void removeTableModelListener(TableModelListener l) {
94      }
95  
96  }