KickJava   Java API By Example, From Geeks To Geeks.

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


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 ProjectTableModel extends ReportTableModel {
28     private Vector projects;
29
30     public ProjectTableModel(IssueModel[] issues, Locale locale) {
31         super(issues, locale);
32     }
33
34     /**
35       * Returns the current number of unique projects in the issue data.
36       * @return the number of projects that have been added to the tablemodel
37       */

38     public int getRowCount() {
39         return projects.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         ProjectData project = getProjectData(row);
54
55         if (column == COLUMN_PROJECTID) {
56             return project.getProjectId();
57         } else if (column == COLUMN_PROJECTNAME) {
58             return project.getProjectName();
59         } else if (column == COLUMN_TOTALISSUES) {
60             return new Integer JavaDoc(project.getTotalIssues());
61         } else if (column == COLUMN_TOTALOPEN) {
62             return new Integer JavaDoc(project.getTotalOpen());
63         } else if (column == COLUMN_TOTALRESOLVED) {
64             return new Integer JavaDoc(project.getTotalResolved());
65         } else if (column == COLUMN_SEVERITYOPEN) {
66             return project.getOpenSeverityAsInteger();
67         } else if (column == COLUMN_SEVERITYRESOLVED) {
68             return project.getResolvedSeverityAsInteger();
69         } else {
70             return null;
71         }
72     }
73
74     public ProjectData getProjectData(final int row) {
75         if(row > getRowCount()) {
76             return null;
77         }
78
79         ProjectData project = (ProjectData) projects.elementAt(row);
80         return project;
81     }
82
83     public void addValueAt(IssueModel issue, int row) {
84         if(issue != null) {
85             if(row < issues.size() && row >= 0) {
86                 this.issues.insertElementAt(issue, row);
87             } else {
88                 this.issues.addElement(issue);
89             }
90
91             if(projects == null) {
92                 projects = new Vector();
93             }
94
95             for(int i = 0; i < projects.size(); i++) {
96                 ProjectData project = (ProjectData) projects.elementAt(i);
97                 if(project.getProjectId().intValue() == issue.getProjectId().intValue()) {
98                     project.addIssue(issue);
99                     return;
100                 }
101             }
102
103             // No existing project was found
104
ProjectData project = new ProjectData(issue.getProjectId(), issue.getProjectName());
105             project.addIssue(issue);
106             projects.addElement(project);
107         }
108     }
109
110 }
111
112 class ProjectData {
113     private Integer JavaDoc projectId;
114     private String JavaDoc projectName;
115     private int totalIssues;
116     private int totalResolved;
117     private int totalOpen;
118
119     private int[] openSeverity;
120     private int[] resolvedSeverity;
121
122     public ProjectData(Integer JavaDoc id, String JavaDoc name) {
123         this.projectId = id;
124         this.projectName = name;
125
126         openSeverity = new int[IssueUtilities.getNumberSeverities()];
127         resolvedSeverity = new int[IssueUtilities.getNumberSeverities()];
128     }
129
130     public Integer JavaDoc getProjectId() {
131         return (projectId == null ? new Integer JavaDoc(-1) : projectId);
132     }
133
134     public String JavaDoc getProjectName() {
135         return (projectName == null ? "" : projectName);
136     }
137
138     public int getTotalIssues() {
139         return totalIssues;
140     }
141
142     public int getTotalOpen() {
143         return totalOpen;
144     }
145
146     public int getTotalResolved() {
147         return totalResolved;
148     }
149
150     public int[] getOpenSeverity() {
151         return openSeverity;
152     }
153
154     public Integer JavaDoc[] getOpenSeverityAsInteger() {
155         Integer JavaDoc[] temp = new Integer JavaDoc[openSeverity.length];
156         for(int i = 0; i < openSeverity.length; i++) {
157             temp[i] = new Integer JavaDoc(openSeverity[i]);
158         }
159         return temp;
160     }
161
162     public int[] getResolvedSeverity() {
163         return resolvedSeverity;
164     }
165
166     public Integer JavaDoc[] getResolvedSeverityAsInteger() {
167         Integer JavaDoc[] temp = new Integer JavaDoc[resolvedSeverity.length];
168         for(int i = 0; i < resolvedSeverity.length; i++) {
169             temp[i] = new Integer JavaDoc(resolvedSeverity[i]);
170         }
171         return temp;
172     }
173
174     public void addIssue(IssueModel issue) {
175         if(issue != null) {
176             totalIssues++;
177             if(issue.getStatus() < IssueUtilities.STATUS_RESOLVED) {
178                 totalOpen++;
179                 if(issue.getSeverity() > 0 && issue.getSeverity() < openSeverity.length) {
180                     openSeverity[issue.getSeverity() - 1]++;
181                 }
182             } else {
183                 totalResolved++;
184                 if(issue.getSeverity() > 0 && issue.getSeverity() < resolvedSeverity.length) {
185                     resolvedSeverity[issue.getSeverity() - 1]++;
186                 }
187             }
188         }
189     }
190 }
191
Popular Tags