1 18 19 package cowsultants.itracker.web.reports; 20 21 import java.text.SimpleDateFormat ; 22 import java.util.*; 23 import javax.swing.table.AbstractTableModel ; 24 25 import cowsultants.itracker.ejb.client.models.*; 26 import cowsultants.itracker.ejb.client.resources.*; 27 import cowsultants.itracker.ejb.client.util.IssueUtilities; 28 import cowsultants.itracker.ejb.client.util.Logger; 29 30 public abstract class ReportTableModel extends AbstractTableModel { 31 public static final int TOTAL_STATIC_COLUMNS = 28; 33 34 public static final int COLUMN_ISSUEID = 0; 35 public static final int COLUMN_PROJECTID = 1; 36 public static final int COLUMN_DESCRIPTION = 2; 37 public static final int COLUMN_SEVERITY = 3; 38 public static final int COLUMN_STATUS = 4; 39 public static final int COLUMN_PROJECTNAME = 5; 40 public static final int COLUMN_TOTALISSUES = 6; 41 public static final int COLUMN_TOTALOPEN = 7; 42 public static final int COLUMN_TOTALRESOLVED = 8; 43 public static final int COLUMN_CREATEDATE = 9; 44 public static final int COLUMN_LASTMODDATE = 10; 45 public static final int COLUMN_OWNERNAME = 11; 46 public static final int COLUMN_OWNEREMAIL = 12; 47 public static final int COLUMN_CREATORNAME = 13; 48 public static final int COLUMN_CREATOREMAIL = 14; 49 public static final int COLUMN_TARGETVERSION = 15; 50 public static final int COLUMN_RESOLUTION = 16; 51 public static final int COLUMN_COMPONENTS = 17; 52 public static final int COLUMN_COMPONENTSSTRING = 18; 53 public static final int COLUMN_VERSIONS = 19; 54 public static final int COLUMN_VERSIONSSTRING = 20; 55 public static final int COLUMN_HISTORY = 21; 56 public static final int COLUMN_HISTORYSTRING = 22; 57 public static final int COLUMN_LASTHISTORY = 23; 58 public static final int COLUMN_LASTHISTORYDATE = 24; 59 public static final int COLUMN_LASTHISTORYUSER = 25; 60 public static final int COLUMN_SEVERITYOPEN = 26; 61 public static final int COLUMN_SEVERITYRESOLVED = 27; 62 63 protected Vector issues; 64 protected CustomFieldModel[] customFields = new CustomFieldModel[0]; 65 protected Locale reportLocale; 66 protected SimpleDateFormat sdf; 67 68 public ReportTableModel() { 69 this.issues = new Vector(); 70 this.reportLocale = ITrackerResources.getLocale(); 71 this.sdf = new SimpleDateFormat (ITrackerResources.getString("itracker.dateformat.full")); 72 this.customFields = IssueUtilities.getCustomFields(ITrackerResources.getLocale()); 73 } 74 75 public ReportTableModel(IssueModel[] issues, Locale locale) { 76 this(); 77 if(issues != null) { 78 for(int i = 0; i < issues.length; i++) { 79 if(issues[i] != null) { 80 addValue(issues[i]); 81 } 82 } 83 } 84 if(locale != null) { 85 this.reportLocale = locale; 86 this.sdf = new SimpleDateFormat (ITrackerResources.getString("itracker.dateformat.full", locale)); 87 this.customFields = IssueUtilities.getCustomFields(locale); 88 } 89 } 90 91 95 public int getColumnCount() { 96 return TOTAL_STATIC_COLUMNS + customFields.length; 97 } 98 99 104 public String getColumnName(final int column) { 105 if(column >= TOTAL_STATIC_COLUMNS && column < (TOTAL_STATIC_COLUMNS + customFields.length)) { 106 if(customFields[column - TOTAL_STATIC_COLUMNS] != null) { 107 return "customfield" + customFields[column - TOTAL_STATIC_COLUMNS].getId(); 108 } 109 } 110 111 switch(column) { 112 case COLUMN_ISSUEID: 113 return "issueid"; 114 case COLUMN_PROJECTID: 115 return "projectid"; 116 case COLUMN_DESCRIPTION: 117 return "description"; 118 case COLUMN_STATUS: 119 return "status"; 120 case COLUMN_SEVERITY: 121 return "severity"; 122 case COLUMN_PROJECTNAME: 123 return "projectname"; 124 case COLUMN_TOTALISSUES: 125 return "totalissues"; 126 case COLUMN_TOTALOPEN: 127 return "totalopen"; 128 case COLUMN_TOTALRESOLVED: 129 return "totalresolved"; 130 case COLUMN_CREATEDATE: 131 return "createdate"; 132 case COLUMN_LASTMODDATE: 133 return "lastmoddate"; 134 case COLUMN_OWNERNAME: 135 return "ownername"; 136 case COLUMN_OWNEREMAIL: 137 return "owneremail"; 138 case COLUMN_CREATORNAME: 139 return "creatorname"; 140 case COLUMN_CREATOREMAIL: 141 return "creatoremail"; 142 case COLUMN_TARGETVERSION: 143 return "targetversion"; 144 case COLUMN_RESOLUTION: 145 return "resolution"; 146 case COLUMN_COMPONENTS: 147 return "components"; 148 case COLUMN_COMPONENTSSTRING: 149 return "componentsstring"; 150 case COLUMN_VERSIONS: 151 return "versions"; 152 case COLUMN_VERSIONSSTRING: 153 return "versionsstring"; 154 case COLUMN_HISTORY: 155 return "history"; 156 case COLUMN_HISTORYSTRING: 157 return "historystring"; 158 case COLUMN_LASTHISTORY: 159 return "lasthistory"; 160 case COLUMN_LASTHISTORYDATE: 161 return "lasthistorydate"; 162 case COLUMN_LASTHISTORYUSER: 163 return "lasthistoryuser"; 164 case COLUMN_SEVERITYOPEN: 165 return "severityopen"; 166 case COLUMN_SEVERITYRESOLVED: 167 return "severityresolved"; 168 default: 169 throw new IllegalArgumentException ("ReportTableModel: Invalid column index."); 170 } 171 } 172 173 178 public int findColumn(String columnName) { 179 if("issueid".equalsIgnoreCase(columnName)) { 180 return COLUMN_ISSUEID; 181 } else if("projectid".equalsIgnoreCase(columnName)) { 182 return COLUMN_PROJECTID; 183 } else if("description".equalsIgnoreCase(columnName)) { 184 return COLUMN_DESCRIPTION; 185 } else if("status".equalsIgnoreCase(columnName)) { 186 return COLUMN_STATUS; 187 } else if("severity".equalsIgnoreCase(columnName)) { 188 return COLUMN_SEVERITY; 189 } else if("projectname".equalsIgnoreCase(columnName)) { 190 return COLUMN_PROJECTNAME; 191 } else if("totalissues".equalsIgnoreCase(columnName)) { 192 return COLUMN_TOTALISSUES; 193 } else if("totalopen".equalsIgnoreCase(columnName)) { 194 return COLUMN_TOTALOPEN; 195 } else if("totalresolved".equalsIgnoreCase(columnName)) { 196 return COLUMN_TOTALRESOLVED; 197 } else if("createdate".equalsIgnoreCase(columnName)) { 198 return COLUMN_CREATEDATE; 199 } else if("lastmoddate".equalsIgnoreCase(columnName)) { 200 return COLUMN_LASTMODDATE; 201 } else if("ownername".equalsIgnoreCase(columnName)) { 202 return COLUMN_OWNERNAME; 203 } else if("owneremail".equalsIgnoreCase(columnName)) { 204 return COLUMN_OWNEREMAIL; 205 } else if("creatorname".equalsIgnoreCase(columnName)) { 206 return COLUMN_CREATORNAME; 207 } else if("creatoremail".equalsIgnoreCase(columnName)) { 208 return COLUMN_CREATOREMAIL; 209 } else if("targetversion".equalsIgnoreCase(columnName)) { 210 return COLUMN_TARGETVERSION; 211 } else if("resolution".equalsIgnoreCase(columnName)) { 212 return COLUMN_RESOLUTION; 213 } else if("components".equalsIgnoreCase(columnName)) { 214 return COLUMN_COMPONENTS; 215 } else if("componentsstring".equalsIgnoreCase(columnName)) { 216 return COLUMN_COMPONENTSSTRING; 217 } else if("versions".equalsIgnoreCase(columnName)) { 218 return COLUMN_VERSIONS; 219 } else if("versionsstring".equalsIgnoreCase(columnName)) { 220 return COLUMN_VERSIONSSTRING; 221 } else if("history".equalsIgnoreCase(columnName)) { 222 return COLUMN_HISTORY; 223 } else if("historystring".equalsIgnoreCase(columnName)) { 224 return COLUMN_HISTORYSTRING; 225 } else if("lasthistory".equalsIgnoreCase(columnName)) { 226 return COLUMN_LASTHISTORY; 227 } else if("lasthistorydate".equalsIgnoreCase(columnName)) { 228 return COLUMN_LASTHISTORYDATE; 229 } else if("lasthistoryuser".equalsIgnoreCase(columnName)) { 230 return COLUMN_LASTHISTORYUSER; 231 } else if("severityopen".equalsIgnoreCase(columnName)) { 232 return COLUMN_SEVERITYOPEN; 233 } else if("severityresolved".equalsIgnoreCase(columnName)) { 234 return COLUMN_SEVERITYRESOLVED; 235 } else if(columnName != null && columnName.startsWith("customfield")) { 236 try { 237 Integer id = new Integer (columnName.substring(11)); 238 for(int i = 0; i < customFields.length; i++) { 239 if(customFields[i] != null && id.equals(customFields[i].getId())) { 240 return TOTAL_STATIC_COLUMNS + i; 241 } 242 } 243 Logger.logDebug("Could not find column: " + columnName + " with id " + id); 244 } catch(Exception e) { 245 Logger.logDebug("Error finding column for report: " + e.getMessage()); 246 } 247 } else { 248 return -1; 249 } 250 251 return -1; 252 } 253 254 public void addValue(IssueModel issue) { 255 addValueAt(issue, -1); 256 } 257 258 public void addValueAt(IssueModel issue, int row) { 259 if(issue != null) { 260 if(row < issues.size() && row >= 0) { 261 this.issues.insertElementAt(issue, row); 262 } else { 263 this.issues.addElement(issue); 264 } 265 } 266 } 267 268 } 269 | Popular Tags |