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    import org.jadira.dependencynavigator.controller.model.DuplicatesListManager;
021    import org.jadira.dependencynavigator.model.Duplicate;
022    
023    import javax.swing.event.TableModelListener;
024    import javax.swing.table.TableModel;
025    
026    public class DuplicatesTableModel implements TableModel, SelectableTableModel {
027    
028        private DuplicatesListManager duplicatesListManager;
029    
030        public DuplicatesTableModel(DuplicatesListManager duplicatesListManager) {
031            this.duplicatesListManager = duplicatesListManager;
032        }
033    
034        public int getColumnCount() {
035            return 2;
036        }
037    
038        public int getRowCount() {
039            return duplicatesListManager.size();
040        }
041    
042        public boolean isCellEditable(int rowIndex, int columnIndex) {
043            return false;
044        }
045    
046        public Class<String> getColumnClass(int columnIndex) {
047            return String.class;
048        }
049    
050        public Object getValueAt(int rowIndex, int columnIndex) {
051            Duplicate duplicate = duplicatesListManager.get(rowIndex);
052            switch (columnIndex) {
053            case 0:
054                return duplicate.getIdentifier();
055            case 1:
056                return duplicate.getVersions();
057            default:
058                throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
059            }
060        }
061    
062        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
063            throw new UnsupportedOperationException();
064        }
065    
066        public String getColumnName(int columnIndex) {
067            switch (columnIndex) {
068            case 0:
069                return "Artifact";
070            case 1:
071                return "Versions";
072            default:
073                throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
074            }
075        }
076    
077        public void addTableModelListener(TableModelListener l) {
078        }
079    
080        public void removeTableModelListener(TableModelListener l) {
081        }
082    
083        public boolean isSelected(int row) {
084            return duplicatesListManager.get(row).isSelected();
085        }
086    }