BrightSide Workbench Full Report + Source Code
IssueCtrl.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 org.turro.dossier.db.DossierPU;
21 import org.turro.dossier.entity.Issue;
22 import org.turro.dossier.issue.IssueWrapper;
23 import org.turro.dossier.search.IssueResults;
24 import org.turro.zkoss.label.LabelExtended;
25 import org.zkoss.lang.Strings;
26 import org.zkoss.zk.ui.Component;
27 import org.zkoss.zk.ui.WrongValueException;
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.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.*;
33 
38 public class IssueCtrl extends Bandbox implements AfterCompose {
39 
40  private LabelExtended description;
41  private Issue issue;
42  private int wordWrap = 0, maxChars = 0, parentCount = 1;
43  private boolean showDescription = false;
44 
45  public IssueCtrl() {
46  addPopup();
47  }
48 
49  public boolean isShowDescription() {
50  return showDescription;
51  }
52 
53  public void setShowDescription(boolean showDescription) {
54  this.showDescription = showDescription;
55  if(showDescription) {
56  addEventListener(Events.ON_CHANGE, new EventListener() {
57  @Override
58  public void onEvent(Event event) throws Exception {
59  description.setValue(loadValue());
60  }
61  });
62  }
63  }
64 
65  public Issue getIssue() {
66  return issue;
67  }
68 
69  public void setIssue(Issue issue) {
70  this.issue = issue;
71  if(issue != null) {
72  setValue(issue.getId() + "");
73  }
74  }
75 
76  public int getMaxChars() {
77  return maxChars;
78  }
79 
80  public void setMaxChars(int maxChars) {
81  this.maxChars = maxChars;
82  }
83 
84  public int getParentCount() {
85  return parentCount;
86  }
87 
88  public void setParentCount(int parentCount) {
89  this.parentCount = parentCount;
90  }
91 
92  public int getWordWrap() {
93  return wordWrap;
94  }
95 
96  public void setWordWrap(int wordWrap) {
97  this.wordWrap = wordWrap;
98  }
99 
100  @Override
101  public void afterCompose() {
102  if(!showDescription) return;
103  description = new LabelExtended();
104  description.setValue(loadValue());
105  description.setWordWrap(wordWrap);
106  description.setMaxChars(maxChars);
107  Component comp = getParent();
108  for(int i = 1; i < parentCount; i++) {
109  comp = comp.getParent();
110  }
111  comp.appendChild(description);
112  }
113 
114  @Override
115  public void setValue(String value) throws WrongValueException {
116  if(Strings.isEmpty(value)) value = "0";
117  super.setValue(value);
118  }
119 
120  private void addPopup() {
121  Bandpopup popup = new Bandpopup();
122  appendChild(popup);
123 
124  final Listbox issues = new Listbox();
125  issues.addEventListener(Events.ON_SELECT, new EventListener() {
126  @Override
127  public void onEvent(Event event) throws Exception {
128  IssueCtrl.this.setValue(issues.getSelectedItem().getLabel());
129  IssueCtrl.this.loadValue();
130  Events.postEvent(new Event(Events.ON_CHANGE, IssueCtrl.this));
131  IssueCtrl.this.close();
132  }
133  });
134  popup.appendChild(issues);
135 
136  IssueResults results = new IssueResults();
137 
138  for(IssueWrapper iw : results.getIssueList()) {
139  Listitem item = new Listitem();
140  issues.appendChild(item);
141 
142  Listcell cell = new Listcell(iw.getIssue().getId() + "");
143  item.appendChild(cell);
144 
145  cell = new Listcell(iw.getIssue().getDescription());
146  item.appendChild(cell);
147  }
148 
149  }
150 
151  private String loadValue() {
152  if(!Strings.isEmpty(getValue()) && Long.valueOf(getValue()) > 0) {
153  issue = new DossierPU().find(Issue.class, Long.valueOf(getValue()));
154  if(issue != null) {
155  return issue.getDescription();
156  }
157  }
158  return "";
159  }
160 
161 }
void setShowDescription(boolean showDescription)
Definition: IssueCtrl.java:53
void setParentCount(int parentCount)
Definition: IssueCtrl.java:88
LabelExtended setWordWrap(int wordWrap)
LabelExtended setMaxChars(int maxChars)