Coverage Report - de.glossmaker.gui.bibtex.model.BibTeXItemsTableModel
 
Classes in this File Line Coverage Branch Coverage Complexity
BibTeXItemsTableModel
95%
44/46
76%
10/13
1,8
 
 1  
 package de.glossmaker.gui.bibtex.model;
 2  
 
 3  
 import javax.swing.table.AbstractTableModel;
 4  
 
 5  
 import de.glossmaker.bib.datastructure.ABibItem;
 6  
 import de.glossmaker.bib.datastructure.BibItems;
 7  
 import de.glossmaker.gloss.datastructure.IItem;
 8  
 import de.glossmaker.gloss.language.Translation;
 9  
 
 10  
 /**
 11  
  * 
 12  
  * @author Markus Flingelli
 13  
  *
 14  
  */
 15  
 public class BibTeXItemsTableModel extends AbstractTableModel {
 16  
         private static final long serialVersionUID = 1L;
 17  9
         private String[] mColumnNames = null; 
 18  9
         private Translation mTranslation = null;
 19  9
         private BibItems mBibItems = null;
 20  
         
 21  9
         public BibTeXItemsTableModel(BibItems items) {
 22  9
                 mBibItems = items;
 23  9
                 mTranslation = Translation.getInstance();
 24  9
                 mColumnNames = new String[4];
 25  9
                 mColumnNames[0] = mTranslation.getValue("bibtex.table.bibitem.key.text");
 26  9
                 mColumnNames[1] = mTranslation.getValue("bibtex.table.bibitem.author.text");
 27  9
                 mColumnNames[2] = mTranslation.getValue("bibtex.table.bibitem.title.text");
 28  9
                 mColumnNames[3] = mTranslation.getValue("bibtex.table.bibitem.year.text");
 29  9
         }
 30  
         
 31  
 
 32  
         public String getColumnName(int col) {
 33  4
         return mColumnNames[col];
 34  
     }
 35  
         
 36  
         @Override
 37  
         public int getColumnCount() {
 38  1
                 return mColumnNames.length;
 39  
         }
 40  
 
 41  
         @Override
 42  
         public int getRowCount() {
 43  5
                 return mBibItems.size();
 44  
         }
 45  
 
 46  
         @Override
 47  
         public Object getValueAt(int row, int col) {
 48  5
                 Object result = null;
 49  5
                 ABibItem item = (ABibItem) mBibItems.getItem(row);
 50  5
                 if (item != null) {
 51  5
                 switch(col) {
 52  
                         case 0: // Key
 53  1
                                 result = item.getKey();
 54  1
                                 break;
 55  
                         case 1: // Author
 56  2
                                 result = item.getAuthor();
 57  2
                                 break;
 58  
                         case 2: // Title
 59  1
                                 result = item.getTitle();
 60  1
                                 break;
 61  
                         case 3: // Year
 62  1
                                 result = item.getYear();
 63  
                         }
 64  
                 }
 65  5
                 return result;
 66  
         }
 67  
 
 68  
         public Object getValueAt(int row) {
 69  3
                 return mBibItems.getItem(row);
 70  
         }
 71  
         
 72  
         public int getRow(ABibItem item) {
 73  1
                 int result = 0;
 74  2
                 for(int i = 0; i < getRowCount(); i++) {
 75  1
                         Object modelItem = getValueAt(i, 1);
 76  1
                         if (modelItem instanceof String) {
 77  1
                                 String tmp = (String)modelItem;
 78  1
                                 if (tmp.equals(item.getKey())) {
 79  0
                                         result = i;
 80  0
                                         break;
 81  
                                 }
 82  
                         }
 83  
                 }
 84  1
                 return result;
 85  
         }
 86  
         
 87  
 
 88  
         public boolean isItemValid(int row) {
 89  1
                 ABibItem item = (ABibItem) getValueAt(row);
 90  1
                 return item.isItemValid();
 91  
         }        
 92  
         
 93  
         public IItem removeRow(int row) {
 94  1
                 IItem result = (IItem) getValueAt(row);
 95  1
                 mBibItems.remove(result);
 96  1
             fireTableRowsDeleted(row, row);
 97  1
             return result;
 98  
         }
 99  
         
 100  
         public void removeAll() {
 101  1
                 mBibItems.clear();
 102  1
                 fireTableRowsDeleted(0, 0);
 103  1
         }
 104  
 }