KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > web > reports > ReportTableModel


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.web.reports;
20
21 import java.text.SimpleDateFormat JavaDoc;
22 import java.util.*;
23 import javax.swing.table.AbstractTableModel JavaDoc;
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 JavaDoc {
31     // This number MUST be set to the total number of defined columns.
32
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 JavaDoc sdf;
67
68     public ReportTableModel() {
69         this.issues = new Vector();
70         this.reportLocale = ITrackerResources.getLocale();
71         this.sdf = new SimpleDateFormat JavaDoc(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 JavaDoc(ITrackerResources.getString("itracker.dateformat.full", locale));
87             this.customFields = IssueUtilities.getCustomFields(locale);
88         }
89     }
90
91     /**
92       * Returns the number of columns that have been defined.
93       * @return the number of columns available to reports
94       */

95     public int getColumnCount() {
96         return TOTAL_STATIC_COLUMNS + customFields.length;
97     }
98
99     /**
100       * Returns the name of the column.
101       * @param column the column (zero-based index).
102       * @return the column name.
103       */

104     public String JavaDoc 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 JavaDoc("ReportTableModel: Invalid column index.");
170         }
171     }
172
173     /**
174       * Returns the number of the column.
175       * @param columnName the column name
176       * @return the column number
177       */

178     public int findColumn(String JavaDoc 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 JavaDoc id = new Integer JavaDoc(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 JavaDoc 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