1 package sellwin.gui; 2 3 import sellwin.domain.*; 4 import javax.swing.*; 5 import javax.swing.text.*; 6 import javax.swing.table.*; 7 import java.util.*; 8 import java.text.*; 9 10 14 19 public class QuoteLineTableModel extends AbstractTableModel { 20 private String [] columnNames = { 21 "Product Name", "Qty", "Model No.", "Cost", "Unit Price", 22 "Total Price", "Description" }; 23 24 private ArrayList wholeList = null; 25 private QuoteLine quote = new QuoteLine(); 26 27 32 public QuoteLineTableModel(ArrayList wholeList) { 33 this.wholeList = wholeList; 34 Product prod = new Product(); 35 prod.setName("hi"); 36 quote.setProduct(prod); 37 quote.setQuantity(new Integer (10)); 38 prod.setModelNo("1234"); 39 prod.setCost(new Double (1.99)); 40 prod.setPrice(new Double (10.88)); 41 prod.setDesc("desc"); 42 43 setLang(); 44 } 45 46 50 public final void addQuoteLine(QuoteLine f) { 51 wholeList.add(f); 52 } 53 54 59 public final QuoteLine getQuoteLine(int index) { 60 return (QuoteLine)(wholeList.get(index)); 61 } 62 63 67 public final void deleteQuoteLine(int index) { 68 wholeList.remove(index); 69 } 70 71 75 public final ArrayList getQuoteLines() { 76 return wholeList; 77 } 78 79 85 public final Object getValueAt(int row, int col) { 86 QuoteLine quote=null; 87 quote = (QuoteLine)wholeList.get(row); 88 switch (col) { 89 case 0: return quote.getProduct().getName(); 91 case 1: return quote.getQuantity(); 93 case 2: return quote.getProduct().getModelNo(); 95 case 3: return quote.getProduct().getCost(); 97 case 4: return quote.getProduct().getPrice(); 99 case 5: return quote.getTotalPrice(); 101 case 6: return quote.getProduct().getDesc(); 103 default: 104 System.out.println("oops its dorked"); 105 break; 106 } 107 return null; 108 } 109 110 114 public final int getRowQuantity() { 115 return wholeList.size(); 116 } 117 118 122 public final int getColumnQuantity() { 123 return columnNames.length; 124 } 125 126 127 132 public final Class getColumnClass(int col) { 133 switch (col) { 134 case 0: return quote.getProduct().getName().getClass(); 136 case 1: return quote.getQuantity().getClass(); 138 case 2: return quote.getProduct().getModelNo().getClass(); 140 case 3: return quote.getProduct().getCost().getClass(); 142 case 4: return quote.getProduct().getPrice().getClass(); 144 case 5: return quote.getTotalPrice().getClass(); 146 case 6: return quote.getProduct().getDesc().getClass(); 148 default: 149 System.out.println("oops its dorked"); 150 break; 151 } 152 return null; 153 } 154 155 161 public final void setValueAt(Object value, int row, int col) { 162 QuoteLine q = (QuoteLine)wholeList.get(row); 163 q.setModified(true); 164 switch (col) { 165 case 0: q.getProduct().setName((String )value); 167 break; 168 case 1: q.setQuantity((Integer )value); 170 break; 171 case 2: q.getProduct().setModelNo((String )value); 173 break; 174 case 3: q.getProduct().setCost((Double )value); 176 break; 177 case 4: q.getProduct().setPrice((Double )value); 179 break; 180 case 5: q.setTotalPrice((Double )value); 182 break; 183 case 6: q.getProduct().setDesc((String )value); 185 break; 186 default: 187 System.out.println("oops its dorked"); 188 break; 189 } 190 fireTableCellUpdated(row, col); 191 } 192 193 199 public final boolean isCellEditable(int row, int col) { 200 Class cls = getColumnClass(col); 201 String name = getColumnName(col); 202 203 if (col != 1) 204 return false; 205 206 return true; 207 } 208 209 213 public final int getColumnCount() { 214 return columnNames.length; 215 } 216 217 222 public final String getColumnName(int col) { 223 return columnNames[col]; 224 } 225 226 230 public final int getRowCount() { 231 return wholeList.size(); 232 } 233 234 public final void setLang() { 235 Whiteboard wb = MainWindow.getWhiteboard(); 236 columnNames[0] = wb.getLang().getString("productName"); 237 columnNames[1] = wb.getLang().getString("qty"); 238 columnNames[2] = wb.getLang().getString("model"); 239 columnNames[3] = wb.getLang().getString("cost"); 240 columnNames[4] = wb.getLang().getString("unitPrice"); 241 columnNames[5] = wb.getLang().getString("total"); 242 columnNames[6] = wb.getLang().getString("description"); 243 } 244 } 245 | Popular Tags |