KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
22
23 import cowsultants.itracker.ejb.client.models.*;
24 import cowsultants.itracker.ejb.client.resources.*;
25 import cowsultants.itracker.ejb.client.util.*;
26
27 public class IssueTableModel extends ReportTableModel {
28
29     public IssueTableModel(IssueModel[] issues, Locale locale) {
30         super(issues, locale);
31     }
32
33     /**
34       * Returns the current number of rows of data (issues) in the
35       * table model.
36       * @return the number of issues that have been added to the tablemodel
37       */

38     public int getRowCount() {
39         return issues.size();
40     }
41
42     /**
43       * Returns the value at a particular row and column.
44       * @param row the row (zero-based index).
45       * @param column the column (zero-based index).
46       * @return the value.
47       */

48     public Object JavaDoc getValueAt(final int row, final int column) {
49         if(row > getRowCount()) {
50             return null;
51         }
52
53         IssueModel issue = (IssueModel) issues.elementAt(row);
54         if(issue == null) {
55             return null;
56         }
57
58         if (column == COLUMN_ISSUEID) {
59             return issue.getId();
60         } else if (column == COLUMN_PROJECTID) {
61             return issue.getProjectId();
62         } else if (column == COLUMN_PROJECTID) {
63             return issue.getProjectName();
64         } else if (column == COLUMN_DESCRIPTION) {
65             return issue.getDescription();
66         } else if (column == COLUMN_STATUS) {
67             return IssueUtilities.getStatusName(issue.getStatus(), reportLocale);
68         } else if (column == COLUMN_SEVERITY) {
69             return IssueUtilities.getSeverityName(issue.getSeverity(), reportLocale);
70         } else if (column == COLUMN_CREATEDATE) {
71             return (sdf == null ? issue.getCreateDate().toString() : sdf.format(issue.getCreateDate()));
72         } else if (column == COLUMN_LASTMODDATE) {
73             return (sdf == null ? issue.getLastModifiedDate().toString() : sdf.format(issue.getLastModifiedDate()));
74         } else if (column == COLUMN_OWNERNAME) {
75             return (issue.getOwner() == null ? ITrackerResources.getString("itracker.web.generic.unassigned", reportLocale) : issue.getOwner().getFirstName() + " " + issue.getOwner().getLastName());
76         } else if (column == COLUMN_OWNEREMAIL) {
77             return (issue.getOwner() == null ? ITrackerResources.getString("itracker.web.generic.unassigned", reportLocale) : issue.getOwner().getEmail());
78         } else if (column == COLUMN_CREATORNAME) {
79             return (issue.getCreator() == null ? ITrackerResources.getString("itracker.web.generic.unknown", reportLocale) : issue.getCreator().getFirstName() + " " + issue.getCreator().getLastName());
80         } else if (column == COLUMN_CREATOREMAIL) {
81             return (issue.getCreator() == null ? ITrackerResources.getString("itracker.web.generic.unknown", reportLocale) : issue.getCreator().getEmail());
82         } else if (column == COLUMN_TARGETVERSION) {
83             return (issue.getTargetVersion() == null ? "" : issue.getTargetVersion().getNumber());
84         } else if (column == COLUMN_RESOLUTION) {
85             if(issue.getProject() != null && ProjectUtilities.hasOption(ProjectUtilities.OPTION_PREDEFINED_RESOLUTIONS, issue.getProject().getOptions())) {
86                 return IssueUtilities.getResolutionName(issue.getResolution(), reportLocale);
87             } else {
88                 return issue.getResolution();
89             }
90         } else if (column == COLUMN_COMPONENTS) {
91             return issue.getComponents();
92         } else if (column == COLUMN_COMPONENTSSTRING) {
93             return IssueUtilities.componentsToString(issue);
94         } else if (column == COLUMN_VERSIONS) {
95             return issue.getVersions();
96         } else if (column == COLUMN_VERSIONSSTRING) {
97             return IssueUtilities.versionsToString(issue);
98         } else if (column == COLUMN_HISTORY) {
99             return issue.getHistory();
100         } else if (column == COLUMN_HISTORYSTRING) {
101             return IssueUtilities.historyToString(issue, sdf);
102         } else if (column == COLUMN_LASTHISTORY) {
103             if(issue.getHistory().length > 0) {
104                 IssueHistoryModel history = issue.getHistory()[issue.getHistory().length - 1];
105                 return history.getDescription();
106             } else {
107                 return "";
108             }
109         } else if (column == COLUMN_LASTHISTORYDATE) {
110             if(issue.getHistory().length > 0) {
111                 IssueHistoryModel history = issue.getHistory()[issue.getHistory().length - 1];
112                 return sdf.format(history.getLastModifiedDate());
113             } else {
114                 return "";
115             }
116         } else if (column == COLUMN_LASTHISTORYUSER) {
117             if(issue.getHistory().length > 0) {
118                 IssueHistoryModel history = issue.getHistory()[issue.getHistory().length - 1];
119                 return history.getUserFirstName() + " " + history.getUserLastName();
120             } else {
121                 return "";
122             }
123         } else if (column >= TOTAL_STATIC_COLUMNS && column < (TOTAL_STATIC_COLUMNS + customFields.length)) {
124             try {
125                 CustomFieldModel customField = customFields[column - TOTAL_STATIC_COLUMNS];
126                 if(customField != null) {
127                     for(int i = 0; i < issue.getFields().length; i++) {
128                         if(issue.getFields()[i].getCustomFieldId().equals(customField.getId())) {
129                             String JavaDoc value = issue.getFields()[i].getValue(reportLocale);
130                             if(customField.getFieldType() == CustomFieldUtilities.TYPE_LIST) {
131                                 for(int j = 0; j < customField.getOptions().length; j++) {
132                                     if(customField.getOptions()[j].getValue().equals(value)) {
133                                         value = customField.getOptions()[j].getName();
134                                         break;
135                                     }
136                                 }
137                             }
138                             return value;
139                         }
140                     }
141                 }
142             } catch(Exception JavaDoc e) {
143                 Logger.logDebug("Error retrieving custom field data.", e);
144             }
145             return "";
146         } else {
147             return null;
148         }
149     }
150 }
151
Popular Tags