BrightSide Workbench Full Report + Source Code
IssueRelationTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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 
19 package org.turro.dossier.zul.relation;
20 
21 import java.util.List;
22 import java.util.Set;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.dossier.entity.Issue;
26 import org.turro.dossier.entity.IssuePredecessor;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.i18n.I_;
29 import org.turro.registry.ChangeCategory;
30 import org.turro.registry.Changes;
31 import org.turro.registry.UniqueString;
32 import org.zkoss.zul.Tree;
33 import org.zkoss.zul.Treechildren;
34 import org.zkoss.zul.Treecol;
35 import org.zkoss.zul.Treecols;
36 
41 public class IssueRelationTree extends Tree {
42 
43  private Treechildren children;
44  private Issue issue;
45  private Changes changes;
46  private int mode; // 0-direct, 1-all
47 
48  public IssueRelationTree() {
49  super();
50  addColumns();
51  addChildrenSpace();
52  mode = 0;
53  }
54 
55  public Changes getChanges() {
56  return changes;
57  }
58 
59  public void setChanges(Changes changes) {
60  this.changes = changes;
61  }
62 
63  public Issue getIssue() {
64  return issue;
65  }
66 
67  public void setIssue(Issue issue) {
68  if(issue != null) {
69  this.issue = issue;
70  removeChild(children);
71  addChildrenSpace();
72  addRoots(new IssueRelation(null, issue), mode == 0 ? 1 : 999);
73  openChildrenWithIssue(children.getChildren());
74  }
75  }
76 
77  public int getMode() {
78  return mode;
79  }
80 
81  public void setMode(int mode) {
82  this.mode = mode;
83  }
84 
86  if(IssueRelationTree.this.getSelectedItem() instanceof IssueRelation) {
87  return (IssueRelation) IssueRelationTree.this.getSelectedItem();
88  }
89  return null;
90  }
91 
92  private void addColumns() {
93  Treecols cols = new Treecols();
94  cols.setSizable(true);
95  appendChild(cols);
96 
97  Treecol col = new Treecol();
98  col.setLabel("");
99  cols.appendChild(col);
100 
101  col = new Treecol();
102  col.setLabel(I_.get("Status"));
103  col.setWidth("120px");
104  cols.appendChild(col);
105 
106  col = new Treecol();
107  col.setLabel(I_.get("Responsible"));
108  col.setWidth("230px");
109  cols.appendChild(col);
110  }
111 
112  private void addChildrenSpace() {
113  children = new Treechildren();
114  appendChild(children);
115  }
116 
117  private void addRoots(IssueRelation current, int count) {
118  Set<IssuePredecessor> ips = current.getIssue().getSources();
119  if(ips.isEmpty()) {
120  children.appendChild(current);
121  current.setOpen(true);
122  } else {
123  if(count-- > 0) {
124  for(IssuePredecessor ip : ips) {
125  addRoots(new IssueRelation(null, ip.getSource()), count);
126  }
127  }
128  }
129  }
130 
131  public void addRelation() {
132  if(IssueRelationTree.this.getSelectedItem() instanceof IssueRelation) {
133  try {
134  IssueRelation ir = (IssueRelation) IssueRelationTree.this.getSelectedItem();
135  ir.doAddRelation(changes);
136  } catch (InterruptedException ex) {
137  Logger.getLogger(IssueRelationTree.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
138  }
139  }
140  }
141 
142  public void editRelation() {
143  if(IssueRelationTree.this.getSelectedItem() instanceof IssueRelation) {
144  try {
145  IssueRelation ir = (IssueRelation) IssueRelationTree.this.getSelectedItem();
146  ir.doEditRelation(changes);
147  } catch (InterruptedException ex) {
148  Logger.getLogger(IssueRelationTree.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
149  }
150  }
151  }
152 
153  public void deleteRelation() {
154  if(IssueRelationTree.this.getSelectedItem() instanceof IssueRelation) {
155  try {
156  IssueRelation ir = (IssueRelation) IssueRelationTree.this.getSelectedItem();
157  if(changes != null) {
158  ChangeCategory cc = new ChangeCategory(3, I_.get("Relations"));
159  changes.addChange(new UniqueString(cc, "", "-" + ir.getPredecessor().getFullDescription()));
160  }
161  ir.doDeleteRelation();
162  } catch (InterruptedException ex) {
163  Logger.getLogger(IssueRelationTree.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
164  }
165  }
166  }
167 
168  private void openChildrenWithIssue(List children) {
169  for(IssueRelation ir : (List<IssueRelation>) children) {
170  if(ir.getIssue() != null && ir.getIssue().getId() != issue.getId()) {
171  ir.setOpen(true);
172  openChildrenWithIssue(ir.getRelatedChildren());
173  break;
174  }
175  }
176  }
177 
178 }
void doAddRelation(final Changes changes)
void doEditRelation(final Changes changes)
static String get(String msg)
Definition: I_.java:41