1 package sellwin.gui; 2 3 import sellwin.domain.*; 4 import java.util.*; 5 import javax.swing.table.*; 6 7 11 16 public class ProductTableModel extends DefaultTableModel { 17 private ArrayList rows; 18 private ArrayList columnNames; 19 20 26 public ProductTableModel(ArrayList r) { 27 setLang(); 28 rows = r; 29 } 30 31 35 public final ArrayList getRows() { 36 return rows; 37 } 38 39 43 public final void removeRowByIndex(int rowIndex) { 44 rows.remove(rowIndex); 45 fireTableRowsDeleted(rowIndex, rowIndex); 46 } 47 48 51 public final void removeRowObject(Object rowObject) { 52 removeRowByIndex(rows.indexOf(rowObject)); 53 } 54 55 59 public final void setRows(ArrayList r) { 60 rows = r; 61 } 62 63 66 public final int getColumnCount() { 67 if (columnNames == null) 68 return 0; 69 else 70 return columnNames.size(); 71 } 72 73 76 public final int getRowCount() { 77 if (rows == null) 78 return 0; 79 else 80 return rows.size(); 81 } 82 83 86 public final String getColumnName(int col) { 87 if (columnNames != null && col < columnNames.size()) 88 return (String ) columnNames.get(col); 89 else 90 return super.getColumnName(col); 91 } 92 93 96 public final Object getValueAt(int row, int col) { 97 ArrayList rows = getRows(); 98 99 if (rows != null && row < rows.size()) { 100 CustomerInventory line = (CustomerInventory)rows.get(row); 101 102 if (line != null) { 103 if (col == 0) { 104 return line.getProduct().getName(); 105 } 106 if (col == 1) { 107 return line.getCount(); 108 } 109 } 110 } 111 112 return null; 113 } 114 115 118 public final void setLang() { 119 Whiteboard wb = MainWindow.getWhiteboard(); 120 columnNames = new ArrayList(); 121 columnNames.add(wb.getLang().getString("product")); 122 columnNames.add(wb.getLang().getString("count")); 123 } 124 } 125 | Popular Tags |