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 14 19 public class ActivityTableModel extends AbstractTableModel { 20 public static int START_DT_COLUMN = 1; 21 22 private String [] 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 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 ()); 41 activity.setDuration(new Integer (15)); 42 activity.setModifiedBy("updatedby"); 43 } 44 45 46 51 public void addActivity(Activity f) { 52 wholeList.add(f); 53 } 54 55 62 public Activity getActivity(int index) { 63 return (Activity)(wholeList.get(index)); 64 } 65 66 70 public void deleteActivity(int index) { 71 wholeList.remove(index); 72 } 73 74 78 public ArrayList getActivitys() { 79 return wholeList; 80 } 81 82 88 public Object getValueAt(int row, int col) { 89 Activity activity=null; 90 activity = (Activity)wholeList.get(row); 91 switch (col) { 92 case 0: return activity.getSubject(); 94 case 1: return activity.getStartDate(); 96 case 2: return activity.getType(); 98 case 3: return activity.getPlace(); 100 case 4: return activity.getMessage(); 102 case 5: return activity.getAlarm(); 104 case 6: return activity.getDuration(); 106 case 7: 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 getColumnName(int col) { 124 return columnNames[col]; 125 } 126 127 public Class getColumnClass(int col) { 128 switch (col) { 129 case 0: return activity.getSubject().getClass(); 131 case 1: return activity.getStartDate().getClass(); 133 case 2: return activity.getType().getClass(); 135 case 3: return activity.getPlace().getClass(); 137 case 4: return activity.getMessage().getClass(); 139 case 5: return activity.getAlarm().getClass(); 141 case 6: return activity.getDuration().getClass(); 143 case 7: 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 value, int row, int col) { 153 Activity activity = null; 154 activity = (Activity)wholeList.get(row); 155 switch (col) { 156 case 0: activity.setSubject((String )value); 158 break; 159 case 1: if (value == null) value = new Date(); 161 activity.setStartDate((Date)value); 162 break; 163 case 2: activity.setType((String )value); 165 break; 166 case 3: activity.setPlace((String )value); 168 break; 169 case 4: activity.setMessage((String )value); 171 break; 172 case 5: activity.setAlarm((Boolean )value); 174 break; 175 case 6: activity.setDuration((Integer )value); 177 break; 178 case 7: activity.setModifiedBy((String )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 cls = getColumnClass(col); 190 String 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 |