1 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 38 public int getRowCount() { 39 return projects.size(); 40 } 41 42 48 public Object 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 (project.getTotalIssues()); 61 } else if (column == COLUMN_TOTALOPEN) { 62 return new Integer (project.getTotalOpen()); 63 } else if (column == COLUMN_TOTALRESOLVED) { 64 return new Integer (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 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 projectId; 114 private String 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 id, String 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 getProjectId() { 131 return (projectId == null ? new Integer (-1) : projectId); 132 } 133 134 public String 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 [] getOpenSeverityAsInteger() { 155 Integer [] temp = new Integer [openSeverity.length]; 156 for(int i = 0; i < openSeverity.length; i++) { 157 temp[i] = new Integer (openSeverity[i]); 158 } 159 return temp; 160 } 161 162 public int[] getResolvedSeverity() { 163 return resolvedSeverity; 164 } 165 166 public Integer [] getResolvedSeverityAsInteger() { 167 Integer [] temp = new Integer [resolvedSeverity.length]; 168 for(int i = 0; i < resolvedSeverity.length; i++) { 169 temp[i] = new Integer (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 |