BrightSide Workbench Full Report + Source Code
IssueRelationControl.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 org.turro.dossier.entity.Issue;
22 import org.turro.registry.Changes;
23 import org.zkoss.zk.ui.Executions;
24 import org.zkoss.zk.ui.IdSpace;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 import org.zkoss.zk.ui.select.Selectors;
27 import org.zkoss.zk.ui.select.annotation.Listen;
28 import org.zkoss.zk.ui.select.annotation.Wire;
29 import org.zkoss.zul.Checkbox;
30 import org.zkoss.zul.Panel;
31 import org.zkoss.zul.Toolbarbutton;
32 
37 public class IssueRelationControl extends Panel implements IdSpace, AfterCompose {
38 
39  private boolean readOnly, treeCollapsed;
40  private Issue issue;
41  private Changes changes;
42 
43  @Wire("#addRelation")
44  private Toolbarbutton addRelation;
45 
46  @Wire("#editRelation")
47  private Toolbarbutton editRelation;
48 
49  @Wire("#deleteRelation")
50  private Toolbarbutton deleteRelation;
51 
52  @Wire("#mode")
53  private Checkbox mode;
54 
55  @Wire("#relationTree")
56  private IssueRelationTree relationTree;
57 
58  @Listen("onSelect = #relationTree")
59  public void onSelectRelation() {
60  updateButtons(relationTree.getSelectedRelation());
61  }
62 
63  @Listen("onCheck = #mode")
64  public void onMode() throws Exception {
65  relationTree.setMode(mode.isChecked() ? 1 : 0);
66  relationTree.setIssue(issue);
67  }
68 
69  @Listen("onClick = #addRelation")
70  public void onAddRelation() throws Exception {
71  relationTree.addRelation();
72  updateButtons(null);
73  }
74 
75  @Listen("onClick = #editRelation")
76  public void onEditRelation() throws Exception {
77  relationTree.editRelation();
78  updateButtons(null);
79  }
80 
81  @Listen("onClick = #deleteRelation")
82  public void onDeleteRelation() throws Exception {
83  relationTree.deleteRelation();
84  updateButtons(null);
85  }
86 
88  Executions.createComponents("/WEB-INF/_zul/bs/comps/issue/relationControl.zul", this, null);
89  Selectors.wireComponents(this, this, false);
90  Selectors.wireEventListeners(this, this);
91  }
92 
93  public Issue getIssue() {
94  return issue;
95  }
96 
97  public void setIssue(Issue issue) {
98  this.issue = issue;
99  }
100 
101  public Checkbox getMode() {
102  return mode;
103  }
104 
105  public void setMode(Checkbox mode) {
106  this.mode = mode;
107  }
108 
109  public boolean isReadOnly() {
110  return readOnly;
111  }
112 
113  public void setReadOnly(boolean readOnly) {
114  this.readOnly = readOnly;
115  }
116 
117  public boolean isTreeCollapsed() {
118  return treeCollapsed;
119  }
120 
121  public void setTreeCollapsed(boolean treeCollapsed) {
122  this.treeCollapsed = treeCollapsed;
123  }
124 
125  public Changes getChanges() {
126  return changes;
127  }
128 
129  public void setChanges(Changes changes) {
130  this.changes = changes;
131  }
132 
133  @Override
134  public void afterCompose() {
135  initComponents();
136  }
137 
138  private void initComponents() {
139  relationTree.setIssue(issue);
140  updateButtons(relationTree.getSelectedRelation());
141  }
142 
143  private void updateButtons(IssueRelation current) {
144  if(!readOnly && current != null) {
145  addRelation.setDisabled(false);
146  editRelation.setDisabled(!current.canEdit());
147  deleteRelation.setDisabled(!current.canDelete());
148  } else {
149  addRelation.setDisabled(true);
150  editRelation.setDisabled(true);
151  deleteRelation.setDisabled(true);
152  }
153  }
154 
155 }