001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 /* 015 * This file has been modified by Chris Pheby in accordance with Section 4.2 016 * of the Apache Software License 017 */ 018 package org.jadira.dependencynavigator.gui; 019 020 021 import org.jadira.dependencynavigator.controller.model.DuplicatesListManager; 022 import org.jadira.dependencynavigator.model.ArtifactInstanceMap; 023 024 import javax.swing.event.TableModelListener; 025 import javax.swing.table.TableModel; 026 027 public class VersionsTableModel implements TableModel, SelectableTableModel { 028 029 private DuplicatesListManager duplicatesListManager; 030 031 public VersionsTableModel(DuplicatesListManager duplicatesListManager) { 032 this.duplicatesListManager = duplicatesListManager; 033 } 034 035 public boolean isSelected(int row) { 036 return duplicatesListManager.getVersionsListManager().get(row).isSelected(); 037 } 038 039 public int getColumnCount() { 040 return 4; 041 } 042 043 public int getRowCount() { 044 return duplicatesListManager.getVersionsListManager().size(); 045 } 046 047 public boolean isCellEditable(int rowIndex, int columnIndex) { 048 return false; 049 } 050 051 public Class<String> getColumnClass(int columnIndex) { 052 return String.class; 053 } 054 055 public Object getValueAt(int rowIndex, int columnIndex) { 056 ArtifactInstanceMap instanceMap = duplicatesListManager.getVersionsListManager().get(rowIndex); 057 switch (columnIndex) { 058 case 0: 059 return instanceMap.getGroupId(); 060 case 1: 061 return instanceMap.getArtifactId(); 062 case 2: 063 return instanceMap.getVersion(); 064 case 3: 065 return String.valueOf(instanceMap.getInstances().size()); 066 default: 067 throw new IllegalArgumentException("Column index out of bounds " + columnIndex); 068 } 069 } 070 071 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 072 throw new UnsupportedOperationException(); 073 } 074 075 public String getColumnName(int columnIndex) { 076 switch (columnIndex) { 077 case 0: 078 return "Group"; 079 case 1: 080 return "Artifact"; 081 case 2: 082 return "Version"; 083 case 3: 084 return "Instances"; 085 default: 086 throw new IllegalArgumentException("Column index out of bounds " + columnIndex); 087 } 088 } 089 090 public void addTableModelListener(TableModelListener l) { 091 } 092 093 public void removeTableModelListener(TableModelListener l) { 094 } 095 096 }