KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > CampaignTableModel


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 to object
16  * mapping for the campaigns table shown on the
17  * GUI dialog for campaign mgmt.
18  */

19 public class CampaignTableModel extends AbstractTableModel {
20     private String JavaDoc[] columnNames = {
21         "Campaign Name", "Type", "Product Group", "Product Line",
22         "Leads Generated" };
23
24     private ArrayList wholeList = null;
25     private Campaign sample = new Campaign();
26
27     /**
28      * construct a table using a list of Campaign objects
29      * @param wholeList the list of Campaigns to display
30      */

31     public CampaignTableModel(ArrayList wholeList) {
32         this.wholeList = wholeList;
33         sample.setName("camp 1");
34         sample.setType("type 1");
35         sample.setProductGroup("group 1");
36         sample.setProductLine("line 1");
37         sample.setLeadCount(new Integer JavaDoc(3));
38         setLang();
39     }
40
41     /**
42      * add a Campaign to the table
43      * @param f the Campaign to add
44      */

45     public final void addCampaign(Campaign f) {
46         wholeList.add(f);
47     }
48
49     /**
50      * get a Campaign from the table using an index
51      * @param index the Campaign index key
52      * @return the Campaign at that index
53      */

54     public final Campaign getCampaign(int index) {
55         return (Campaign)(wholeList.get(index));
56     }
57
58     /**
59      * delete a Campaign from the table
60      * @param index the Campaign's index
61      */

62     public final void deleteCampaign(int index) {
63         wholeList.remove(index);
64     }
65
66     /**
67      * get the list of Campaigns from this table
68      * @return the ArrayList of Campaigns
69      */

70     public final ArrayList getCampaigns() {
71         return wholeList;
72     }
73
74     /**
75      * get a table cell value
76      * @param row the table cell's row index
77      * @param col the table cell's column index
78      * @return the value at that cell
79      */

80     public final Object JavaDoc getValueAt(int row, int col) {
81         Campaign sample=null;
82         sample = (Campaign)wholeList.get(row);
83         switch (col) {
84             case 0: //campaign name
85
return sample.getName();
86             case 1: //type
87
return sample.getType();
88             case 2: //group
89
return sample.getProductGroup();
90             case 3: //line
91
return sample.getProductLine();
92             case 4: //leads generated count
93
return sample.getLeadCount();
94             default:
95                 System.out.println("oops its dorked");
96             break;
97         }
98         return null;
99     }
100
101     /**
102      * get the row count
103      * @return the row count
104      */

105     public final int getRowCount() {
106         return wholeList.size();
107     }
108
109     /**
110      * get the column count
111      * @return the column count
112      */

113     public final int getColumnCount() {
114         return columnNames.length;
115     }
116
117     /**
118      * get the column name
119      * @param col the column index starting at 0 to get
120      * a name for
121      * @return the column name
122      */

123     public final String JavaDoc getColumnName(int col) {
124         return columnNames[col];
125     }
126
127     /**
128      * get the column's Class
129      * @param col the index of a column
130      * @return the class name of that column
131      */

132     public final Class JavaDoc getColumnClass(int col) {
133         switch (col) {
134             case 0: //campaign name
135
return sample.getName().getClass();
136             case 1: //type
137
return sample.getType().getClass();
138             case 2: //product group
139
return sample.getProductGroup().getClass();
140             case 3: //product line
141
return sample.getProductLine().getClass();
142             case 4: //leads generated count
143
return sample.getLeadCount().getClass();
144             default:
145                 System.out.println("oops its dorked");
146             break;
147         }
148         return null;
149     }
150     
151     /**
152      * set a cell's value
153      * @param value the value we are setting the cell to
154      * @param row the row index of the cell
155      * @param col the column index of the cell
156      */

157     public final void setValueAt(Object JavaDoc value, int row, int col) {
158         Campaign f = null;
159         f = (Campaign)wholeList.get(row);
160         switch (col) {
161             case 0: //campaign name
162
sample.setName((String JavaDoc)value);
163                 break;
164             case 1: //type
165
sample.setType((String JavaDoc)value);
166                 break;
167             case 2: //product group
168
sample.setProductGroup((String JavaDoc)value);
169                 break;
170             case 3: //product line
171
sample.setProductLine((String JavaDoc)value);
172                 break;
173             case 4: //leads generated count
174
sample.setLeadCount((Integer JavaDoc)value);
175                 break;
176             default:
177                 System.out.println("oops its dorked");
178             break;
179         }
180         fireTableCellUpdated(row, col);
181     }
182
183     /**
184      * see if a cell is editable
185      * @param row the row index
186      * @param col the column index
187      * @return true if the cell is editable
188      */

189     public final boolean isCellEditable(int row, int col) {
190         Class JavaDoc cls = getColumnClass(col);
191         String JavaDoc name = getColumnName(col);
192
193         return false;
194     }
195
196     /**
197      * set the table's header text to another language
198      */

199     public final void setLang() {
200         Whiteboard wb = MainWindow.getWhiteboard();
201         
202         columnNames[0] = wb.getLang().getString("campaignName");
203         columnNames[1] = wb.getLang().getString("type");
204         columnNames[2] = wb.getLang().getString("productGroup");
205         columnNames[3] = wb.getLang().getString("productLine");
206         columnNames[4] = wb.getLang().getString("leadsGenerated");
207
208     }
209 }
210
Popular Tags