KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > OrderDetailTableModel


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 is the order detail table model
16  * see the java spec for a full explaination of
17  * this framework
18 //just like QuoteLineTableModel except we don't want to show
19 //the cost on the Order
20  */

21 public class OrderDetailTableModel extends AbstractTableModel {
22     private String JavaDoc[] columnNames = {
23         "Product Name", "Qty", "Model No.", "Price",
24         "Description" };
25
26     private ArrayList wholeList = null;
27     private QuoteLine line = new QuoteLine();
28
29     /**
30      * construct an order detail table model
31      * @param wholeList the list of Orders to load
32      */

33     public OrderDetailTableModel(ArrayList wholeList) {
34         this.wholeList = wholeList;
35         line.setProduct(new Product());
36         line.getProduct().setName("hi");
37         line.setQuantity(new Integer JavaDoc(10));
38         line.getProduct().setModelNo("1234");
39         line.getProduct().setPrice(new Double JavaDoc(10.88));
40         line.getProduct().setDesc("desc");
41     
42         setLang();
43     }
44
45     /**
46      * add a quote line to the model
47      * @param f QuoteLine to add to the list
48      */

49     public void addQuoteLine(QuoteLine f) {
50         wholeList.add(f);
51     }
52
53     /**
54      * get a specific QuoteLine from the list
55      * @param index the index to use
56      * @return the QuoteLine
57      */

58     public final QuoteLine getQuoteLine(int index) {
59         return (QuoteLine)(wholeList.get(index));
60     }
61
62     /**
63      * delete a QuoteLine from the model's list
64      * @param index the QuoteLine to delete
65      */

66     public final void deleteQuoteLine(int index) {
67         wholeList.remove(index);
68     }
69
70     /**
71      * get the whole list of order details
72      * @return the list
73      */

74     public final ArrayList getOrderDetails() {
75         return wholeList;
76     }
77
78     /**
79      * see the java spec
80      */

81     public final Object JavaDoc getValueAt(int row, int col) {
82         QuoteLine line=null;
83         line = (QuoteLine)wholeList.get(row);
84         switch (col) {
85             case 0: //product name
86
return line.getProduct().getName();
87             case 1: //quantity
88
return line.getQuantity();
89             case 2: //model number
90
return line.getProduct().getModelNo();
91             case 3: //price
92
return line.getProduct().getPrice();
93             case 4: //description
94
return line.getProduct().getDesc();
95             default:
96                 System.out.println("oops its dorked");
97             break;
98         }
99         return null;
100     }
101
102     /**
103      * see the java spec
104      */

105     public final int getRowQuantity() {
106         return wholeList.size();
107     }
108
109     /**
110      * see the java spec
111      */

112     public final int getColumnQuantity() {
113         return columnNames.length;
114     }
115
116
117     /**
118      * see the java spec
119      */

120     public final Class JavaDoc getColumnClass(int col) {
121         switch (col) {
122             case 0: //product name
123
return line.getProduct().getName().getClass();
124             case 1: //quantity
125
return line.getQuantity().getClass();
126             case 2: //model number
127
return line.getProduct().getModelNo().getClass();
128             case 3: //price
129
return line.getProduct().getPrice().getClass();
130             case 4: //description
131
return line.getProduct().getDesc().getClass();
132             default:
133                 System.out.println("oops its dorked");
134             break;
135         }
136         return null;
137     }
138     
139     /**
140      * see the java spec
141      */

142     public final void setValueAt(Object JavaDoc value, int row, int col) {
143         QuoteLine line = null;
144         line = (QuoteLine)wholeList.get(row);
145         switch (col) {
146             case 0: //product name
147
line.getProduct().setName((String JavaDoc)value);
148                 break;
149             case 1: //quantity
150
line.setQuantity((Integer JavaDoc)value);
151                 break;
152             case 2: //model number
153
line.getProduct().setModelNo((String JavaDoc)value);
154                 break;
155             case 3: //price
156
line.getProduct().setPrice((Double JavaDoc)value);
157                 break;
158             case 4: //description
159
line.getProduct().setDesc((String JavaDoc)value);
160                 break;
161             default:
162                 System.out.println("oops its dorked");
163             break;
164         }
165         fireTableCellUpdated(row, col);
166     }
167
168     /**
169      * see the java spec
170      */

171     public final boolean isCellEditable(int row, int col) {
172         Class JavaDoc cls = getColumnClass(col);
173         String JavaDoc name = getColumnName(col);
174
175         return false;
176     }
177
178     /**
179      * see the java spec
180      */

181     public final int getColumnCount() {
182         return columnNames.length;
183     }
184
185     /**
186      * see the java spec
187      */

188     public final String JavaDoc getColumnName(int col) {
189         return columnNames[col];
190     }
191
192     /**
193      * see the java spec
194      */

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