BrightSide Workbench Full Report + Source Code
TargetSelectorNewItem.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 java.util.EnumSet;
22 import org.turro.contacts.organigram.RelationType;
23 import org.turro.contacts.organigram.TargetItem;
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.Hlayout;
29 
34 public class TargetSelectorNewItem extends Hlayout implements AfterCompose {
35 
37  setSclass("z-valign-middle");
38  setValign("middle");
39  }
40 
41  private TargetSelector getSelector() {
42  return (TargetSelector) getParent();
43  }
44 
45  @Override
46  public void afterCompose() {
47  EnumSet<RelationType> rts = EnumSet.complementOf(getSelector().getTargetArray().getRelationTypes());
48  final OrganigramListbox ol = new OrganigramListbox();
49  ol.setMold("select");
50  ol.setAllowNull(true);
51  ol.setNullLabel("Add to selection");
52  ol.setCollection(rts);
53  ol.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
54  @Override
55  public void onEvent(Event event) throws Exception {
56  if(ol.getObjectValue() != null) {
57  TargetItem ti = new TargetItem();
58  ti.setRelationType(ol.getObjectValue());
59  getSelector().getTargetArray().add(ti);
60  Events.postEvent(new Event(Events.ON_CHANGE, getSelector()));
61  getSelector().refresh();
62  }
63  }
64  });
65  appendChild(ol);
66  ol.afterCompose();
67  }
68 
69 }
void setCollection(Collection< V > collection)