18 package org.turro.dossier.zul.relation;
20 import java.util.List;
22 import org.turro.collections.CollectionUtil;
23 import org.turro.command.Command;
24 import org.turro.command.Context;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.dossier.entity.IssuePredecessor;
28 import org.turro.dossier.entity.IssuePredecessorType;
29 import org.turro.dossier.issue.IssueWrapper;
30 import org.turro.elephant.util.Messages;
31 import org.turro.elephant.zkoss.Modal;
32 import org.turro.i18n.I_;
33 import org.turro.registry.ChangeCategory;
34 import org.turro.registry.Changes;
35 import org.turro.registry.UniqueString;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.EventListener;
39 import org.zkoss.zk.ui.event.Events;
40 import org.zkoss.zul.Treecell;
41 import org.zkoss.zul.Treechildren;
42 import org.zkoss.zul.Treeitem;
43 import org.zkoss.zul.Treerow;
51 private Treechildren children;
52 private final Issue issue;
56 this.predecessor = predecessor;
73 return CollectionUtil.from(children.getChildren()).<List<IssueRelation>>cast();
77 Component comp = getParent().getParent();
82 removeChild(children);
99 public void doAddRelation(
final Changes changes)
throws InterruptedException {
103 getDesktop().setAttribute(
"predecessor", ip);
105 Modal.
doModal(
"/WEB-INF/_zul/issue/relation.zul",
new Command() {
107 public Object execute(Context context) {
108 if(checkRelation(ip)) {
109 predecessor =
new DossierPU().saveObject(ip);
111 if(changes !=
null) {
112 ChangeCategory cc =
new ChangeCategory(3,
I_.
get(
"Relations"));
113 changes.addChange(
new UniqueString(cc,
"",
"+" +
getPredecessor().getFullDescription()));
122 getDesktop().setAttribute(
"predecessor", predecessor);
123 Modal.
doModal(
"/WEB-INF/_zul/issue/relation.zul",
new Command() {
125 public Object execute(Context context) {
126 if(checkRelation(predecessor)) {
127 predecessor =
new DossierPU().saveObject(predecessor);
129 if(changes !=
null) {
130 ChangeCategory cc =
new ChangeCategory(3,
I_.
get(
"Relations"));
131 changes.addChange(
new UniqueString(cc,
"",
getPredecessor().getFullDescription()));
147 return predecessor !=
null;
151 return predecessor !=
null;
154 private void addChildrenSpace() {
155 children =
new Treechildren();
156 appendChild(children);
159 private void addCells() {
160 Treerow row =
new Treerow();
164 if(predecessor !=
null) {
165 if(predecessor.
getType().equals(IssuePredecessorType.START_WHEN_STARTS)) {
166 src =
"/_zul/images/start_starts.png";
168 src =
"/_zul/images/start_ends.png";
172 row.appendChild(
new Treecell(I_.byKey(issue.
getStatus().toString())));
173 row.appendChild(
new Treecell(
new IssueWrapper(issue).getResponsibleString()));
176 private void initLoadOnDemand() {
178 addEventListener(Events.ON_OPEN,
new EventListener() {
180 public void onEvent(Event event)
throws Exception {
188 private void addTargets() {
189 if(children.getChildren().isEmpty()) {
190 Set<IssuePredecessor> ips = issue.
getTargets();
191 for(IssuePredecessor ip : ips) {
197 private boolean checkRelation(IssuePredecessor ip) {
198 if(ip.getSource() !=
null && ip.getTarget() !=
null) {
199 if(ip.getSource().getId().equals(ip.getTarget().getId())) {
202 if(!ip.getSource().getId().equals(issue.
getId()) && followUp(ip.getSource())) {
205 if(!ip.getTarget().getId().equals(issue.
getId()) && followDown(ip.getTarget())) {
213 private boolean followUp(Issue source) {
214 for(IssuePredecessor ip : source.getSources()) {
215 if(ip.getSource().getId().equals(issue.
getId())) {
218 followUp(ip.getSource());
224 private boolean followDown(Issue target) {
225 for(IssuePredecessor ip : target.getTargets()) {
226 if(ip.getTarget().getId().equals(issue.
getId())) {
229 followUp(ip.getTarget());
IssuePredecessorType getType()
void setTarget(Issue target)
void setType(IssuePredecessorType type)
Set< IssuePredecessor > getTargets()
IssueRelation(IssuePredecessor predecessor, Issue issue)
void doAddRelation(final Changes changes)
void doEditRelation(final Changes changes)
IssueRelation getRelatedParent()
List< IssueRelation > getRelatedChildren()
IssuePredecessor getPredecessor()
static Messages confirmDeletion()
static int doModal(String file)
static String get(String msg)
void deleteObject(Object obj)