KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > QuoteLineTableModel


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 // SellWin http://sourceforge.net/projects/sellwincrm
11
//Contact support@open-app.com for commercial help with SellWin
12
//This software is provided "AS IS", without a warranty of any kind.
13

14 /**
15  * This class implements the table model for the quote line
16  * items table on the quotes panel. This class determines
17  * how table rows are mapped to quote line item objects.
18  */

19 public class QuoteLineTableModel extends AbstractTableModel {
20     private String JavaDoc[] 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     /**
28      * create the quote line table model
29      * @param wholeList the array of objects that we use
30      * to populate the table
31      */

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 JavaDoc(10));
38         prod.setModelNo("1234");
39         prod.setCost(new Double JavaDoc(1.99));
40         prod.setPrice(new Double JavaDoc(10.88));
41         prod.setDesc("desc");
42
43         setLang();
44     }
45
46     /**
47      * add a quote line to the table's list of objects
48      * @param f the QuoteLine object to add
49      */

50     public final void addQuoteLine(QuoteLine f) {
51         wholeList.add(f);
52     }
53
54     /**
55      * get a QuoteLine using an index key value
56      * @param index the index key value
57      * @return the found QuoteLine
58      */

59     public final QuoteLine getQuoteLine(int index) {
60         return (QuoteLine)(wholeList.get(index));
61     }
62
63     /**
64      * delete a QuoteLine from the current array
65      * @param index the index key
66      */

67     public final void deleteQuoteLine(int index) {
68         wholeList.remove(index);
69     }
70
71     /**
72      * get an array of QuoteLines used by the table
73      * @return the ArrayList of QuoteLines
74      */

75     public final ArrayList getQuoteLines() {
76         return wholeList;
77     }
78
79     /**
80      * get a table value at a given row and column
81      * @param row the row index to search
82      * @param col the column index to search
83      * @return the found Object
84      */

85     public final Object JavaDoc getValueAt(int row, int col) {
86         QuoteLine quote=null;
87         quote = (QuoteLine)wholeList.get(row);
88         switch (col) {
89             case 0: //product name
90
return quote.getProduct().getName();
91             case 1: //quantity
92
return quote.getQuantity();
93             case 2: //model number
94
return quote.getProduct().getModelNo();
95             case 3: //cost
96
return quote.getProduct().getCost();
97             case 4: //price
98
return quote.getProduct().getPrice();
99             case 5: //description
100
return quote.getTotalPrice();
101             case 6: //description
102
return quote.getProduct().getDesc();
103             default:
104                 System.out.println("oops its dorked");
105             break;
106         }
107         return null;
108     }
109
110     /**
111      * get the number of objects we are displaying
112      * @return the table size
113      */

114     public final int getRowQuantity() {
115         return wholeList.size();
116     }
117
118     /**
119      * get the column count of the table
120      * @return the column count
121      */

122     public final int getColumnQuantity() {
123         return columnNames.length;
124     }
125
126
127     /**
128      * get the class of a table column
129      * @param col the column index
130      * @return the Class of the column
131      */

132     public final Class JavaDoc getColumnClass(int col) {
133         switch (col) {
134             case 0: //product name
135
return quote.getProduct().getName().getClass();
136             case 1: //quantity
137
return quote.getQuantity().getClass();
138             case 2: //model number
139
return quote.getProduct().getModelNo().getClass();
140             case 3: //cost
141
return quote.getProduct().getCost().getClass();
142             case 4: //price
143
return quote.getProduct().getPrice().getClass();
144             case 5: //total
145
return quote.getTotalPrice().getClass();
146             case 6: //description
147
return quote.getProduct().getDesc().getClass();
148             default:
149                 System.out.println("oops its dorked");
150             break;
151         }
152         return null;
153     }
154     
155     /**
156      * set a table's cell value
157      * @param value the value we are setting
158      * @param row the row index
159      * @param col the column index
160      */

161     public final void setValueAt(Object JavaDoc value, int row, int col) {
162         QuoteLine q = (QuoteLine)wholeList.get(row);
163         q.setModified(true);
164         switch (col) {
165             case 0: //product name
166
q.getProduct().setName((String JavaDoc)value);
167                 break;
168             case 1: //quantity
169
q.setQuantity((Integer JavaDoc)value);
170                 break;
171             case 2: //model number
172
q.getProduct().setModelNo((String JavaDoc)value);
173                 break;
174             case 3: //cost
175
q.getProduct().setCost((Double JavaDoc)value);
176                 break;
177             case 4: //price
178
q.getProduct().setPrice((Double JavaDoc)value);
179                 break;
180             case 5: //total
181
q.setTotalPrice((Double JavaDoc)value);
182                 break;
183             case 6: //description
184
q.getProduct().setDesc((String JavaDoc)value);
185                 break;
186             default:
187                 System.out.println("oops its dorked");
188             break;
189         }
190         fireTableCellUpdated(row, col);
191     }
192
193     /**
194      * check to see if a table's cell is editable
195      * @param row the row index
196      * @param col the col index
197      * @return true if the cell is editable
198      */

199     public final boolean isCellEditable(int row, int col) {
200         Class JavaDoc cls = getColumnClass(col);
201         String JavaDoc name = getColumnName(col);
202
203         if (col != 1)
204             return false;
205
206         return true;
207     }
208
209     /**
210      * get the count of colnms in the table
211      * @return the column count
212      */

213     public final int getColumnCount() {
214         return columnNames.length;
215     }
216
217     /**
218      * get a column's name
219      * @param col the column index
220      * @return the name of the column
221      */

222     public final String JavaDoc getColumnName(int col) {
223         return columnNames[col];
224     }
225
226     /**
227      * get the row count
228      * @return the number of rows in the table
229      */

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