BrightSide Workbench Full Report + Source Code
IssueResolutionCtrl.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 java.util.HashSet;
21 import java.util.Set;
22 import org.turro.dossier.entity.IssueResolution;
23 import org.turro.i18n.I_;
24 import org.zkoss.lang.Strings;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.event.SelectEvent_506;
29 import org.zkoss.zul.Bandbox;
30 import org.zkoss.zul.Bandpopup;
31 import org.zkoss.zul.Listbox;
32 import org.zkoss.zul.Listitem;
33 
38 public class IssueResolutionCtrl extends Bandbox {
39 
40  private Set<IssueResolution> resolutionSet = new HashSet<IssueResolution>();
41  private Listbox resolution;
42 
44  setReadonly(true);
45  addPopup();
46  }
47 
48  public Set<IssueResolution> getResolutionSet() {
49  return resolutionSet;
50  }
51 
52  public void setResolutionSet(Set<IssueResolution> resolutionSet) {
53  this.resolutionSet = resolutionSet;
54  updateCheckMarks();
55  updateText();
56  }
57 
58  private void addPopup() {
59  Bandpopup popup = new Bandpopup();
60  appendChild(popup);
61 
62  resolution = new Listbox();
63  resolution.setWidth("100%");
64  resolution.setMultiple(true);
65  resolution.setCheckmark(true);
66  resolution.addEventListener(Events.ON_SELECT, new EventListener() {
67  @Override
68  public void onEvent(Event event) throws Exception {
69  Listitem li = (Listitem) ((SelectEvent_506) event).getReference();
70  if(li.isSelected()) {
71  resolutionSet.add((IssueResolution) li.getValue());
72  } else {
73  resolutionSet.remove((IssueResolution) li.getValue());
74  }
75  updateText();
76  }
77  });
78  popup.appendChild(resolution);
79 
80  for(IssueResolution is : IssueResolution.values()) {
81  Listitem li = new Listitem(I_.byKey(is.toString()));
82  li.setValue(is);
83  resolution.appendChild(li);
84  }
85  }
86 
87  private void updateCheckMarks() {
88  for(Object obj : resolution.getChildren()) {
89  if(obj instanceof Listitem) {
90  Listitem li = (Listitem) obj;
91  li.setSelected(resolutionSet.contains(li.getValue()));
92  }
93  }
94  }
95 
96 
97  private void updateText() {
98  String newText = "";
99  for(Object obj : resolution.getChildren()) {
100  if(obj instanceof Listitem) {
101  Listitem li = (Listitem) obj;
102  newText += (Strings.isEmpty(newText) ? "" : ",") +
103  (li.isSelected() ? I_.byKey(li.getValue().toString()) : "");
104  }
105  }
106  Events.postEvent(new Event(Events.ON_CHANGE, IssueResolutionCtrl.this));
107  setText(newText);
108  }
109 }
void setResolutionSet(Set< IssueResolution > resolutionSet)