KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > OrderTableModel


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 order table model
16  * shown on the Order panel...see the java spec
17  * for details on Swing tables and how models are
18  * used
19  */

20 public class OrderTableModel extends AbstractTableModel {
21     private static java.util.Date JavaDoc tempDt = new java.util.Date JavaDoc();
22     private String JavaDoc[] columnNames = {
23         "OrderNumber", "Status", "Quote Name", "Created On", "Created By" };
24
25     private ArrayList wholeList = null;
26     private Order order = new Order();
27
28     /**
29      * construct the model using a list of ORders
30      * @param wholeList the data to use for this model
31      */

32     public OrderTableModel(ArrayList wholeList) {
33         this.wholeList = wholeList;
34         order.setOrderNumber(new Long JavaDoc(1));
35         Quote temp = new Quote();
36         temp.setName("hi");
37         order.setQuote(temp);
38         order.setModifiedDate(new java.util.Date JavaDoc());
39         order.setModifiedBy("bob");
40         
41         setLang();
42     }
43
44     /**
45      * add an ORder to the table model
46      * @param f order to add
47      */

48     public final void addOrder(Order f) {
49         wholeList.add(f);
50     }
51
52     /**
53      * get an Order from this model's list of Orders
54      * @param index the index of the Order
55      * @return the Order
56      */

57     public final Order getOrder(int index) {
58         return (Order)(wholeList.get(index));
59     }
60
61     /**
62      * delete an Order from the model's list
63      * @param index the index of the Order to delete
64      */

65     public final void deleteOrder(int index) {
66         wholeList.remove(index);
67     }
68
69     /**
70      * get the list of Orders
71      * @return the list of Orders
72      */

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

80     public final Object JavaDoc getValueAt(int row, int col) {
81         Order order=null;
82         order = (Order)wholeList.get(row);
83         switch (col) {
84             case 0: //order number
85
return order.getOrderNumber();
86             case 1: //status
87
return order.getStatus();
88             case 2: //quote name
89
return order.getQuote().getName();
90             case 3: //created date
91
return order.getModifiedDate();
92             case 4: //creator
93
return order.getModifiedBy();
94             default:
95                 System.out.println("oops its dorked");
96             break;
97         }
98         return null;
99     }
100
101     /**
102      * see the java spec
103      */

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

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

118     public final String JavaDoc getColumnName(int col) {
119         return columnNames[col];
120     }
121
122     /**
123      * see the java spec
124      */

125     public final Class JavaDoc getColumnClass(int col) {
126         switch (col) {
127             case 0: //order number
128
return order.getOrderNumber().getClass();
129             case 1: //status
130
return order.getStatus().getClass();
131             case 2: //order name
132
return order.getQuote().getName().getClass();
133             case 3: //created Date
134
return order.getModifiedDate().getClass();
135             case 4: //creator
136
return order.getModifiedBy().getClass();
137             default:
138                 System.out.println("oops its dorked");
139             break;
140         }
141         return null;
142     }
143     
144     /**
145      * see the java spec
146      */

147     public final void setValueAt(Object JavaDoc value, int row, int col) {
148         Order f = null;
149         f = (Order)wholeList.get(row);
150         switch (col) {
151             case 0: //order number
152
order.setOrderNumber((Long JavaDoc)value);
153                 break;
154             case 1: //status
155
System.out.println("setting status to " + value);
156                 order.setStatus((String JavaDoc)value);
157                 break;
158             case 2: //order name
159
order.getQuote().setName((String JavaDoc)value);
160                 break;
161             case 3: //created date
162
order.setModifiedDate((java.util.Date JavaDoc)value);
163                 break;
164             case 4: //creator
165
order.setModifiedBy((String JavaDoc)value);
166                 break;
167             default:
168                 System.out.println("oops its dorked");
169             break;
170         }
171         fireTableCellUpdated(row, col);
172     }
173
174     /**
175      * see the java spec
176      * set NO edit
177      */

178     public final boolean isCellEditable(int row, int col) {
179         Class JavaDoc cls = getColumnClass(col);
180         String JavaDoc name = getColumnName(col);
181
182         if (col == 1) return true;
183         return false;
184     }
185
186     public final void setLang() {
187         Whiteboard wb = MainWindow.getWhiteboard();
188
189         columnNames[0] = wb.getLang().getString("orderNumber");
190         columnNames[1] = wb.getLang().getString("status");
191         columnNames[2] = wb.getLang().getString("quoteName");
192         columnNames[3] = wb.getLang().getString("createdDate");
193         columnNames[4] = wb.getLang().getString("createdBy");
194     }
195 }
196
Popular Tags