BrightSide Workbench Full Report + Source Code
IssueGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.dossier.zul.issue;
19 
20 import java.util.List;
21 import org.turro.dossier.issue.IssueWrapper;
22 import org.turro.dossier.search.IssueResults;
23 import org.turro.elephant.context.Application;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.grid.GroupExtended;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zul.Column;
28 import org.zkoss.zul.Columns;
29 import org.zkoss.zul.Group;
30 import org.zkoss.zul.Rows;
31 
36 public class IssueGrid extends PagingGrid {
37 
38  private Rows rows;
39  private boolean showDossier = false;
40 
41  public IssueGrid() {
42  addColumns();
43  }
44 
45  public void setIssueList(List<IssueWrapper> issues) {
46  addRows(issues);
47  }
48 
49  public void setIssueResults(IssueResults results) {
50  if(results != null) {
51  setIssueList(results.getIssueList());
52  }
53  }
54 
55  public boolean isShowDossier() {
56  return showDossier;
57  }
58 
59  public void setShowDossier(boolean showDossier) {
60  this.showDossier = showDossier;
61  }
62 
63  private void addColumns() {
64  Columns cols = new Columns();
65  cols.setSizable(true);
66  cols.setMenupopup("auto");
67  appendChild(cols);
68 
69  Column col = new Column("#");
70  col.setWidth("80px");
71  cols.appendChild(col);
72  col = new Column(I_.get("Description"));
73  cols.appendChild(col);
74  col = new Column(I_.get("Creation"));
75  col.setWidth("100px");
76  cols.appendChild(col);
77  col = new Column(I_.get("Start date"));
78  col.setWidth("100px");
79  col.setVisible(false);
80  cols.appendChild(col);
81  col = new Column(I_.get("Delivery"));
82  col.setWidth("100px");
83  cols.appendChild(col);
84  col = new Column(I_.get("Control"));
85  col.setWidth("100px");
86  col.setVisible(false);
87  cols.appendChild(col);
88  col = new Column(I_.get("Status"));
89  col.setWidth("130px");
90  cols.appendChild(col);
91  if(Application.getApplication().isInRole("issue:delete")) {
92  col = new Column();
93  col.setWidth("25px");
94  cols.appendChild(col);
95  }
96  }
97 
98  private void addRows(List<IssueWrapper> issues) {
99 
100  boolean expanded = true;
101  setRowCount(issues.size());
102  if(issues.size() > getMaxResults()) {
103  expanded = false;
104  }
105 
106  if(rows != null) removeChild(rows);
107 
108  rows = new Rows();
109  appendChild(rows);
110 
111  IssueStage stage = null;
112 
113  for(final IssueWrapper wissue : issues) {
114  IssueStage current = getStage(wissue, stage);
115  if(!(current.equals(stage))) {
116  stage = current;
117  createGroup(stage, expanded);
118  }
119 
120  IssueRow row = new IssueRow();
121  row.setValue(wissue);
122  rows.appendChild(row);
123  }
124 
125  invalidate();
126  }
127 
128  private void createGroup(IssueStage stage, boolean expanded) {
129  Group group = new GroupExtended(I_.byKey(stage.toString()));
130  group.setOpen(expanded);
131  rows.appendChild(group);
132  }
133 
134  private IssueStage getStage(IssueWrapper wissue, IssueStage current) {
135 
136  if(wissue.isUnrelated()) {// && current != null && current.getOrder() >= IssueStage.ISSUE_STAGE_UNRELATED.getOrder()) {
137  return IssueStage.ISSUE_STAGE_UNRELATED;
138  }
139 
140  if(wissue.hasPassedNow()) {// && current != null && current.getOrder() >= IssueStage.ISSUE_STAGE_DATE_SURPASSED.getOrder()) {
141  return IssueStage.ISSUE_STAGE_DATE_SURPASSED;
142  }
143 
144  if(!wissue.hasPassedStartDate() || !wissue.canStartBySources()) {
145  return IssueStage.ISSUE_STAGE_TO_COME;
146  }
147 
148  int stage = wissue.getRelevanceOrderByContact();
149 
150  switch(stage) {
151  case 1: return IssueStage.ISSUE_STAGE_TO_DO;
152  case 2: return IssueStage.ISSUE_STAGE_REUNION;
153  case 5: return IssueStage.ISSUE_STAGE_FROZEN;
154  }
155 
156  return IssueStage.ISSUE_STAGE_TO_MONITOR;
157  }
158 
159 }
java.util.List< IssueWrapper > getIssueList()
void setIssueResults(IssueResults results)
Definition: IssueGrid.java:49
void setIssueList(List< IssueWrapper > issues)
Definition: IssueGrid.java:45
void setShowDossier(boolean showDossier)
Definition: IssueGrid.java:59
static String get(String msg)
Definition: I_.java:41