001    package nl.cwi.sen1.gui.plugin.data;
002    
003    import java.util.Iterator;
004    import java.util.LinkedList;
005    
006    import javax.swing.table.AbstractTableModel;
007    
008    public class ModuledetailsTableModel extends AbstractTableModel {
009        private String[] columnNames;
010        private LinkedList<String[]> data;
011        
012        public ModuledetailsTableModel(String[] columnNames) {
013            this.columnNames = columnNames;
014            data = new LinkedList<String[]>();
015        }
016        
017        public int getRowCount() {
018            return data.size();
019        }
020    
021        public int getColumnCount() {
022            return columnNames.length;
023        }
024    
025        public String getColumnName(int col) {
026            return columnNames[col];
027        }
028        
029        public Object getValueAt(int rowIndex, int columnIndex) {
030            String[] row = data.get(rowIndex);
031            return row[columnIndex];
032        }
033        
034        public void setDetails(String namespace, String key, String value) {
035            String[] found = null;
036            
037            for (Iterator iter = data.iterator(); iter.hasNext();) {
038                String[] row = (String[]) iter.next();
039                if (row[0].equals(namespace) && row[1].equals(key)) {
040                    found = row;
041                }
042            }
043            
044            if (found != null) {
045                found[2] = value;
046            } else {
047                found = new String[3];
048                found[0] = namespace;
049                found[1] = key;
050                found[2] = value;
051                data.add(found);
052            }
053            fireTableDataChanged();
054        }
055    }