BrightSide Workbench Full Report + Source Code
TargetSelectorItem.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.TargetItem;
22 import org.turro.elephant.util.Images;
23 import org.turro.i18n.I_;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.A;
29 import org.zkoss.zul.Hlayout;
30 import org.zkoss.zul.Image;
31 import org.zkoss.zul.Label;
32 
37 public class TargetSelectorItem extends Hlayout implements AfterCompose {
38 
39  private TargetItem targetItem;
40 
41  public TargetSelectorItem(TargetItem targetItem) {
42  this.targetItem = targetItem;
43  setSclass("z-valign-middle");
44  setValign("middle");
45  }
46 
47  private TargetSelector getSelector() {
48  return (TargetSelector) getParent();
49  }
50 
51  @Override
52  public void afterCompose() {
53  Hlayout hbox = new Hlayout();
54  hbox.appendChild(new Image(targetItem.getRelationType().getImage()));
55  hbox.appendChild(new Label(I_.byKey(targetItem.getRelationType().toString())));
56  A del = new A(null, Images.getImage("edit-delete"));
57  hbox.appendChild(del);
58  del.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
59  @Override
60  public void onEvent(Event event) throws Exception {
61  getSelector().getTargetArray().remove(targetItem);
62  Events.postEvent(new Event(Events.ON_CHANGE, getSelector()));
63  TargetSelectorItem.this.detach();
64  }
65  });
66  appendChild(hbox);
67  final NextOperatorListbox nol = new NextOperatorListbox();
68  nol.setMold("select");
69  nol.setObjectValue(targetItem.getNextOperator());
70  nol.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
71  @Override
72  public void onEvent(Event event) throws Exception {
73  targetItem.setNextOperator(nol.getObjectValue());
74  Events.postEvent(new Event(Events.ON_CHANGE, getSelector()));
75  }
76  });
77  appendChild(nol);
78  nol.afterCompose();
79  }
80 
81 }
static String getImage(String image)
Definition: Images.java:36
static String byKey(String key)
Definition: I_.java:83