KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > gui > ActivityTableModel


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
16  * object mapping for the Activities listed
17  * on the Activity panel.
18  */

19 public class ActivityTableModel extends AbstractTableModel {
20     public static int START_DT_COLUMN = 1;
21
22     private String JavaDoc[] columnNames = {
23     "Subject", "Start Dt", "Type", "Place", "Message", "Alarm", "Duration", "Updated By" };
24
25     private ArrayList wholeList = null;
26     private Activity activity = new Activity("test");
27
28     /**
29      * construct a table model for the activity table
30      * @param wholelist a list of Activity objects to
31      * build the table with
32      */

33     public ActivityTableModel(ArrayList wholeList) {
34         setLang();
35         this.wholeList = wholeList;
36         activity.setSubject("subject");
37         activity.setType("type");
38         activity.setPlace("place");
39         activity.setMessage("message");
40         activity.setStartDate(new java.util.Date JavaDoc());
41         activity.setDuration(new Integer JavaDoc(15));
42         activity.setModifiedBy("updatedby");
43     }
44
45
46     /**
47      * add an Activity to the table
48      * @param f an Activity to add
49      * @exception class-name description
50      */

51     public void addActivity(Activity f) {
52         wholeList.add(f);
53     }
54
55     /**
56      * get an Activity using an index into
57      * the current list of Activities presented
58      * by this table
59      * @param index the index key
60      * @return the Activity that was at the index
61      */

62     public Activity getActivity(int index) {
63         return (Activity)(wholeList.get(index));
64     }
65
66     /**
67      * delete an Activity from the table's list
68      * @param index the index key
69      */

70     public void deleteActivity(int index) {
71         wholeList.remove(index);
72     }
73
74     /**
75      * get the list of Activity objects used by the list
76      * @return the ArrayList of Activity objects
77      */

78     public ArrayList getActivitys() {
79         return wholeList;
80     }
81
82     /**
83      * get a table cell value
84      * @param row the cell's row index
85      * @param col the cell's column index
86      * @return the value at that cell location
87      */

88     public Object JavaDoc getValueAt(int row, int col) {
89         Activity activity=null;
90         activity = (Activity)wholeList.get(row);
91         switch (col) {
92             case 0: //subject
93
return activity.getSubject();
94             case 1: //start date
95
return activity.getStartDate();
96             case 2: //type
97
return activity.getType();
98             case 3: //Place
99
return activity.getPlace();
100             case 4: //message
101
return activity.getMessage();
102             case 5: //alarm flag
103
return activity.getAlarm();
104             case 6: //duration
105
return activity.getDuration();
106             case 7: //updated by
107
return activity.getModifiedBy();
108             default:
109                 System.out.println("oops its dorked");
110             break;
111         }
112         return null;
113     }
114
115     public int getRowCount() {
116         return wholeList.size();
117     }
118
119     public int getColumnCount() {
120         return columnNames.length;
121     }
122
123     public String JavaDoc getColumnName(int col) {
124         return columnNames[col];
125     }
126
127     public Class JavaDoc getColumnClass(int col) {
128         switch (col) {
129             case 0: //subject
130
return activity.getSubject().getClass();
131             case 1: //start date
132
return activity.getStartDate().getClass();
133             case 2: //type
134
return activity.getType().getClass();
135             case 3: //place
136
return activity.getPlace().getClass();
137             case 4: //message
138
return activity.getMessage().getClass();
139             case 5: //alarm flag
140
return activity.getAlarm().getClass();
141             case 6: //duration
142
return activity.getDuration().getClass();
143             case 7: //updated by
144
return activity.getModifiedBy().getClass();
145             default:
146                 System.out.println("oops its dorked");
147             break;
148         }
149         return null;
150     }
151     
152     public void setValueAt(Object JavaDoc value, int row, int col) {
153         Activity activity = null;
154         activity = (Activity)wholeList.get(row);
155         switch (col) {
156             case 0: //subject
157
activity.setSubject((String JavaDoc)value);
158                 break;
159             case 1: //start date
160
if (value == null) value = new Date();
161                 activity.setStartDate((Date)value);
162                 break;
163             case 2: //type
164
activity.setType((String JavaDoc)value);
165                 break;
166             case 3: //place
167
activity.setPlace((String JavaDoc)value);
168                 break;
169             case 4: //message
170
activity.setMessage((String JavaDoc)value);
171                 break;
172             case 5: //alarm flag
173
activity.setAlarm((Boolean JavaDoc)value);
174                 break;
175             case 6: //duration
176
activity.setDuration((Integer JavaDoc)value);
177                 break;
178             case 7: //updated by
179
activity.setModifiedBy((String JavaDoc)value);
180                 break;
181             default:
182                 System.out.println("oops its dorked");
183             break;
184         }
185         fireTableCellUpdated(row, col);
186     }
187
188     public boolean isCellEditable(int row, int col) {
189         Class JavaDoc cls = getColumnClass(col);
190         String JavaDoc name = getColumnName(col);
191
192         if ((col == 0) || (col == 7)) return false;
193
194         return true;
195     }
196
197     public void setLang() {
198         Whiteboard wb = MainWindow.getWhiteboard();
199     
200         columnNames[0] = wb.getLang().getString("subject");
201         columnNames[1] = wb.getLang().getString("startDate");
202         columnNames[2] = wb.getLang().getString("type");
203         columnNames[3] = wb.getLang().getString("place");
204         columnNames[4] = wb.getLang().getString("message");
205         columnNames[5] = wb.getLang().getString("alarm");
206         columnNames[6] = wb.getLang().getString("duration");
207         columnNames[7] = wb.getLang().getString("updatedBy");
208     }
209 }
210
Popular Tags