18 package org.turro.dossier.zul.relation;
20 import java.util.List;
22 import org.turro.dossier.entity.Issue;
23 import org.turro.dossier.entity.IssuePredecessor;
24 import org.turro.i18n.I_;
25 import org.turro.registry.ChangeCategory;
26 import org.turro.registry.Changes;
27 import org.turro.registry.UniqueString;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.*;
39 private Treechildren children;
40 private Toolbar toolbar;
41 private Toolbarbutton addRelation, editRelation, deleteRelation;
43 private Changes changes;
56 this.changes = changes;
65 removeChild(children);
68 openChildrenWithIssue(children.getChildren());
72 if(addToolbar && toolbar ==
null) {
73 toolbar =
new Toolbar();
74 toolbar.setStyle(
"width:100%");
75 getParent().appendChild(toolbar);
77 addEventListener(Events.ON_SELECT,
new EventListener() {
79 public void onEvent(Event event)
throws Exception {
87 private void addColumns() {
88 Treecols cols =
new Treecols();
89 cols.setSizable(
true);
92 Treecol col =
new Treecol();
94 cols.appendChild(col);
97 col.setLabel(
I_.
get(
"Status"));
98 col.setWidth(
"120px");
99 cols.appendChild(col);
102 col.setLabel(
I_.
get(
"Responsible"));
103 col.setWidth(
"230px");
104 cols.appendChild(col);
107 private void addChildrenSpace() {
108 children =
new Treechildren();
109 appendChild(children);
112 private void addRoots(IssueRelation current) {
113 Set<IssuePredecessor> ips = current.getIssue().getSources();
115 children.appendChild(current);
116 current.setOpen(
true);
118 for(IssuePredecessor ip : ips) {
119 addRoots(
new IssueRelation(
null, ip.getSource()));
124 private void addToolbarButtons() {
125 addRelation =
new Toolbarbutton(
126 I_.get(
"Add relation"),
127 "/_zul/images/new.png"
129 addRelation.addEventListener(Events.ON_CLICK,
new EventListener() {
131 public void onEvent(Event event)
throws Exception {
134 ir.doAddRelation(changes);
138 toolbar.appendChild(addRelation);
139 editRelation =
new Toolbarbutton(
141 "/_zul/images/edit.png"
143 editRelation.addEventListener(Events.ON_CLICK,
new EventListener() {
145 public void onEvent(Event event)
throws Exception {
148 ir.doEditRelation(changes);
152 toolbar.appendChild(editRelation);
153 deleteRelation =
new Toolbarbutton(
154 I_.get(
"Delete relation"),
155 "/_zul/images/edit-delete.png"
157 deleteRelation.addEventListener(Events.ON_CLICK,
new EventListener() {
159 public void onEvent(Event event)
throws Exception {
162 if(changes !=
null) {
163 ChangeCategory cc =
new ChangeCategory(3, I_.get(
"Relations"));
164 changes.addChange(
new UniqueString(cc,
"",
"-" + ir.getPredecessor().getFullDescription()));
166 ir.doDeleteRelation();
170 toolbar.appendChild(deleteRelation);
173 private void openChildrenWithIssue(List children) {
174 for(IssueRelation ir : (List<IssueRelation>) children) {
175 if(ir.getIssue() !=
null && ir.getIssue().getId() != issue.
getId()) {
177 openChildrenWithIssue(ir.getRelatedChildren());
183 private void updateButtons() {
184 if(toolbar !=
null) {
185 boolean isSelected = getSelectedItem() instanceof IssueRelation;
186 addRelation.setVisible(isSelected);
187 editRelation.setVisible(isSelected && ((IssueRelation) getSelectedItem()).canEdit());
188 deleteRelation.setVisible(isSelected && ((IssueRelation) getSelectedItem()).canDelete());
static String get(String msg)