BrightSide Workbench Full Report + Source Code
TargetSelector.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.contacts.zul.organigram;
20 
21 import org.turro.contacts.organigram.TargetArray;
22 import org.turro.contacts.organigram.TargetItem;
23 import org.zkoss.zk.ui.event.Event;
24 import org.zkoss.zk.ui.event.EventListener;
25 import org.zkoss.zk.ui.event.Events;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Hlayout;
28 import org.zkoss.zul.Space;
29 
34 public class TargetSelector extends Hlayout implements AfterCompose {
35 
36  private TargetArray targetArray;
37 
38  public TargetSelector() {
39  setSclass("z-valign-middle");
40  setValign("middle");
41  }
42 
44  return targetArray;
45  }
46 
47  public void setTargetArray(TargetArray targetArray) {
48  this.targetArray = targetArray;
49  }
50 
51  @Override
52  public void afterCompose() {
53  addItems();
54  }
55 
56  public void refresh() {
57  addItems();
58  }
59 
60  private void addItems() {
61  getChildren().clear();
62  if(targetArray == null) {
63  targetArray = new TargetArray();
64  }
65  for(TargetItem ti : targetArray) {
66  TargetSelectorItem tsi = new TargetSelectorItem(ti);
67  appendChild(tsi);
68  tsi.afterCompose();
69  }
70  final LastItemListbox lil = new LastItemListbox();
71  lil.setMold("select");
72  lil.setObjectValue(targetArray.getLastItem());
73  lil.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
74  @Override
75  public void onEvent(Event event) throws Exception {
76  targetArray.setLastItem(lil.getObjectValue());
77  Events.postEvent(new Event(Events.ON_CHANGE, TargetSelector.this));
78  }
79  });
80  appendChild(lil);
81  lil.afterCompose();
82  Space sep = new Space();
83  sep.setBar(true);
84  appendChild(sep);
85  TargetSelectorNewItem tsni = new TargetSelectorNewItem();
86  appendChild(tsni);
87  tsni.afterCompose();
88  }
89 
90 }