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 21 public class OrderDetailTableModel extends AbstractTableModel { 22 private String [] columnNames = { 23 "Product Name", "Qty", "Model No.", "Price", 24 "Description" }; 25 26 private ArrayList wholeList = null; 27 private QuoteLine line = new QuoteLine(); 28 29 33 public OrderDetailTableModel(ArrayList wholeList) { 34 this.wholeList = wholeList; 35 line.setProduct(new Product()); 36 line.getProduct().setName("hi"); 37 line.setQuantity(new Integer (10)); 38 line.getProduct().setModelNo("1234"); 39 line.getProduct().setPrice(new Double (10.88)); 40 line.getProduct().setDesc("desc"); 41 42 setLang(); 43 } 44 45 49 public void addQuoteLine(QuoteLine f) { 50 wholeList.add(f); 51 } 52 53 58 public final QuoteLine getQuoteLine(int index) { 59 return (QuoteLine)(wholeList.get(index)); 60 } 61 62 66 public final void deleteQuoteLine(int index) { 67 wholeList.remove(index); 68 } 69 70 74 public final ArrayList getOrderDetails() { 75 return wholeList; 76 } 77 78 81 public final Object getValueAt(int row, int col) { 82 QuoteLine line=null; 83 line = (QuoteLine)wholeList.get(row); 84 switch (col) { 85 case 0: return line.getProduct().getName(); 87 case 1: return line.getQuantity(); 89 case 2: return line.getProduct().getModelNo(); 91 case 3: return line.getProduct().getPrice(); 93 case 4: return line.getProduct().getDesc(); 95 default: 96 System.out.println("oops its dorked"); 97 break; 98 } 99 return null; 100 } 101 102 105 public final int getRowQuantity() { 106 return wholeList.size(); 107 } 108 109 112 public final int getColumnQuantity() { 113 return columnNames.length; 114 } 115 116 117 120 public final Class getColumnClass(int col) { 121 switch (col) { 122 case 0: return line.getProduct().getName().getClass(); 124 case 1: return line.getQuantity().getClass(); 126 case 2: return line.getProduct().getModelNo().getClass(); 128 case 3: return line.getProduct().getPrice().getClass(); 130 case 4: return line.getProduct().getDesc().getClass(); 132 default: 133 System.out.println("oops its dorked"); 134 break; 135 } 136 return null; 137 } 138 139 142 public final void setValueAt(Object value, int row, int col) { 143 QuoteLine line = null; 144 line = (QuoteLine)wholeList.get(row); 145 switch (col) { 146 case 0: line.getProduct().setName((String )value); 148 break; 149 case 1: line.setQuantity((Integer )value); 151 break; 152 case 2: line.getProduct().setModelNo((String )value); 154 break; 155 case 3: line.getProduct().setPrice((Double )value); 157 break; 158 case 4: line.getProduct().setDesc((String )value); 160 break; 161 default: 162 System.out.println("oops its dorked"); 163 break; 164 } 165 fireTableCellUpdated(row, col); 166 } 167 168 171 public final boolean isCellEditable(int row, int col) { 172 Class cls = getColumnClass(col); 173 String name = getColumnName(col); 174 175 return false; 176 } 177 178 181 public final int getColumnCount() { 182 return columnNames.length; 183 } 184 185 188 public final String getColumnName(int col) { 189 return columnNames[col]; 190 } 191 192 195 public final int getRowCount() { 196 return wholeList.size(); 197 } 198 199 public final void setLang() { 200 Whiteboard wb = MainWindow.getWhiteboard(); 201 columnNames[0] = wb.getLang().getString("productName"); 202 columnNames[1] = wb.getLang().getString("qty"); 203 columnNames[2] = wb.getLang().getString("model"); 204 columnNames[3] = wb.getLang().getString("price"); 205 columnNames[4] = wb.getLang().getString("description"); 206 } 207 } 208 | Popular Tags |