KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > QuoteTableModel


1 package sellwin.gui;
2
3 import sellwin.domain.*;
4 import sellwin.utils.*;
5
6 import javax.swing.*;
7 import javax.swing.text.*;
8 import javax.swing.table.*;
9 import java.util.*;
10 import java.text.*;
11
12 // SellWin http://sourceforge.net/projects/sellwincrm
13
//Contact support@open-app.com for commercial help with SellWin
14
//This software is provided "AS IS", without a warranty of any kind.
15

16 /**
17  * This class implements a table model for the quotes table
18  * see the java spec for swing tables for details on thich
19  * mechanism
20  */

21 public class QuoteTableModel extends AbstractTableModel {
22     private String JavaDoc[] columnNames = {
23         "Quote Name", "Created On", "Created By" };
24
25     private ArrayList wholeList = null;
26     private Quote quote = new Quote();
27
28     /**
29      * construct a quote table model
30      * @param wholeList a list of quotes to load this model
31      * with
32      */

33     public QuoteTableModel(ArrayList wholeList) {
34         this.wholeList = wholeList;
35         quote.setName("hi");
36         quote.setModifiedBy("bob");
37
38         setLang();
39     }
40
41     /**
42      * add a Quote to the list this table model uses
43      * @param f Quote to add to this model's list
44      */

45     public final void addQuote(Quote f) {
46         wholeList.add(f);
47     }
48
49     /**
50      * get a Quote from this model's list
51      * @param index use this index to retreive a Quote
52      * from the list used by this model
53      * @return a Quote
54      */

55     public final Quote getQuote(int index) {
56         return (Quote)(wholeList.get(index));
57     }
58
59     /**
60      * delete a Quote from the list
61      * @param index the index to perform the lookup with
62      */

63     public final void deleteQuote(int index) {
64         wholeList.remove(index);
65     }
66
67     /**
68      * get the whole list of Quotes used by this model
69      * @return the list of Quotes
70      */

71     public final ArrayList getQuotes() {
72         return wholeList;
73     }
74
75     /**
76      * see the java spec
77      */

78     public final Object JavaDoc getValueAt(int row, int col) {
79         Quote quote=null;
80         quote = (Quote)wholeList.get(row);
81         switch (col) {
82             case 0: //quote name
83
return quote.getName();
84             case 1: //created date
85
return quote.getModifiedDate();
86             case 2: //creator
87
return quote.getModifiedBy();
88             default:
89                 System.out.println("oops its dorked");
90             break;
91         }
92         return null;
93     }
94
95     /**
96      * see the java spec
97      */

98     public final int getRowCount() {
99         return wholeList.size();
100     }
101
102     /**
103      * see the java spec
104      */

105     public final int getColumnCount() {
106         return columnNames.length;
107     }
108
109     /**
110      * see the java spec
111      */

112     public final String JavaDoc getColumnName(int col) {
113         return columnNames[col];
114     }
115
116     /**
117      * see the java spec
118      */

119     public final Class JavaDoc getColumnClass(int col) {
120         switch (col) {
121             case 0: //quote name
122
return quote.getName().getClass();
123             case 1: //created Date
124
return quote.getModifiedDate().getClass();
125             case 2: //creator
126
return quote.getModifiedBy().getClass();
127             default:
128                 System.out.println("oops its dorked");
129             break;
130         }
131         return null;
132     }
133     
134     /**
135      * see the java spec
136      */

137     public final void setValueAt(Object JavaDoc value, int row, int col) {
138         Quote f = null;
139         f = (Quote)wholeList.get(row);
140         switch (col) {
141             case 0: //quote name
142
quote.setName((String JavaDoc)value);
143                 break;
144             case 1: //created date
145
quote.setModifiedDate((java.util.Date JavaDoc)value);
146                 break;
147             case 2: //creator
148
quote.setModifiedBy((String JavaDoc)value);
149                 break;
150             default:
151                 System.out.println("oops its dorked");
152             break;
153         }
154         fireTableCellUpdated(row, col);
155     }
156
157     /**
158      * see the java spec
159      */

160     public final boolean isCellEditable(int row, int col) {
161         Class JavaDoc cls = getColumnClass(col);
162         String JavaDoc name = getColumnName(col);
163
164         return false;
165     }
166
167     public final void setLang() {
168         Whiteboard wb = MainWindow.getWhiteboard();
169         columnNames[0] = wb.getLang().getString("quoteName");
170         columnNames[1] = wb.getLang().getString("createdDate");
171         columnNames[2] = wb.getLang().getString("createdBy");
172     }
173 }
174
Popular Tags