KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > LeadTableModel


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 provides the lead table model
16  * used in the leads dialog
17  */

18 public class LeadTableModel extends AbstractTableModel {
19     private String JavaDoc[] columnNames = {
20         "Contact", "Company", "Phone No.", "Interest Level", "Contacted By",
21         "Notes", "Converted to Opp" };
22
23     private ArrayList wholeList = null;
24     private Lead lead = new Lead();
25
26     /**
27      * construct the lead table model
28      * @param wholeList the list of Leads to store
29      * in the table
30      */

31     public LeadTableModel(ArrayList wholeList) {
32         this.wholeList = wholeList;
33         Address a = new Address();
34         lead.setAddress(a);
35         lead.setCompany("EDS");
36         lead.setInterestLevel("NONE");
37         SalesPerson s = new SalesPerson();
38         lead.setContactedBy(s);
39         lead.setContactDate(new java.util.Date JavaDoc());
40         lead.setConverted(new Boolean JavaDoc(false));
41         setLang();
42     }
43
44     /**
45      * add a lead to the table's model
46      * @param f the Lead to add
47      */

48     public final void addLead(Lead f) {
49         wholeList.add(f);
50     }
51
52     /**
53      * get a Lead from the table
54      * @param index the lead index to use
55      * @return the Lead
56      */

57     public final Lead getLead(int index) {
58         return (Lead)(wholeList.get(index));
59     }
60
61     /**
62      * delete a lead from the model
63      * @param index the lead index to delete with
64      */

65     public final void deleteLead(int index) {
66         wholeList.remove(index);
67     }
68
69     /**
70      * get the leads from this model
71      * @return the list of Leads
72      */

73     public final ArrayList getLeads() {
74         return wholeList;
75     }
76
77     /**
78      * part of the spec for table models
79      */

80     public Object JavaDoc getValueAt(int row, int col) {
81         Lead lead=null;
82         lead = (Lead)wholeList.get(row);
83         switch (col) {
84             case 0: //contact name
85
return lead.getAddress().getFormattedName();
86             case 1: //company
87
return lead.getCompany();
88             case 2: //phone number
89
return lead.getAddress().getPhone();
90             case 3: //interest level
91
return lead.getInterestLevel();
92             case 4: //contacted by
93
return lead.getContactedBy().getAddress().getFormattedName();
94             case 5: //contact date
95
return lead.getContactDate();
96             case 6: //converted flag
97
return lead.getConverted();
98             default:
99                 System.out.println("oops its dorked");
100             break;
101         }
102         return null;
103     }
104
105
106     /**
107      * part of the spec for table models
108      */

109     public Class JavaDoc getColumnClass(int col) {
110         switch (col) {
111             case 0: //contact name
112
return lead.getAddress().getFormattedName().getClass();
113             case 1: //company
114
//return lead.getCompany().getClass();
115
return String JavaDoc.class;
116             case 2: //phone number
117
//return lead.getAddress().getPhone().getClass();
118
return String JavaDoc.class;
119             case 3: //interestLevel
120
//return lead.getInterestLevel().getClass();
121
return String JavaDoc.class;
122             case 4: //contacted by
123
//return lead.getContactedBy().getFormattedName().getClass();
124
return String JavaDoc.class;
125             case 5: //contact date
126
return lead.getContactDate().getClass();
127             case 6: //converted flag
128
return lead.getConverted().getClass();
129             default:
130                 System.out.println("oops its dorked");
131             break;
132         }
133         return null;
134     }
135
136     /**
137      * not implemented cuz this table is read only
138      * part of the spec for table models
139      */

140     public void setValueAt(Object JavaDoc value, int row, int col) {
141         Lead f = null;
142         f = (Lead)wholeList.get(row);
143         switch (col) {
144             case 0: //contact name
145
break;
146             case 1: //company
147
break;
148             case 2: //phone number
149
break;
150             case 3: //interest level
151
break;
152             case 4: //contacted by
153
break;
154             case 5: //contact date
155
break;
156             case 6: //converted flag
157
break;
158             default:
159                 System.out.println("oops its dorked");
160                 break;
161         }
162         fireTableCellUpdated(row, col);
163     }
164
165     /**
166      * part of the table model spec
167      */

168     public boolean isCellEditable(int row, int col) {
169         Class JavaDoc cls = getColumnClass(col);
170         String JavaDoc name = getColumnName(col);
171
172         return false;
173     }
174
175     /**
176      * part of the table model spec
177      */

178     public int getRowCount() {
179         return wholeList.size();
180     }
181
182     /**
183      * part of the table model spec
184      */

185     public int getColumnCount() {
186         return columnNames.length;
187     }
188
189     /**
190      * part of the table model spec
191      */

192     public String JavaDoc getColumnName(int col) {
193         return columnNames[col];
194     }
195
196     public final void setLang() {
197         Whiteboard wb = MainWindow.getWhiteboard();
198         columnNames[0] = wb.getLang().getString("contact");
199         columnNames[1] = wb.getLang().getString("company");
200         columnNames[2] = wb.getLang().getString("phone");
201         columnNames[3] = wb.getLang().getString("interestLevel");
202         columnNames[4] = wb.getLang().getString("contactedBy");
203         columnNames[5] = wb.getLang().getString("notes");
204         columnNames[6] = wb.getLang().getString("convertedToOpp");
205     }
206 }
207
Popular Tags