BrightSide Workbench Full Report + Source Code
ContractDefinitionBandbox.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.financials.contract;
19 
20 import org.turro.financials.entity.ContractDefinition;
21 import org.turro.zkoss.input.GenericBandbox;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zk.ui.event.InputEvent;
26 
31 public class ContractDefinitionBandbox extends GenericBandbox<ContractDefinition> {
32 
34  private boolean typing = false;
35 
36  @Override
37  protected void fillPopup() {
38  if(!isFilled()) {
39  getBandPopup().setHeight("300px");
40  setAutodrop(true);
41  tree.setVflex(true);
42  addEventListener(Events.ON_CHANGING, new EventListener() {
43  @Override
44  public void onEvent(Event event) throws Exception {
45  try {
46  typing = true;
47  tree.selectItemByText(((InputEvent) event).getValue());
48  } finally {
49  typing = false;
50  }
51  }
52  });
53  tree.afterCompose();
54  tree.addEventListener(Events.ON_SELECT, new EventListener() {
55  @Override
56  public void onEvent(Event event) {
57  if(!typing && getObjectValue() != null) {
58  Events.postEvent(new Event(Events.ON_CHANGE, ContractDefinitionBandbox.this));
59  ContractDefinitionBandbox.this.close();
60  }
61  }
62  });
63  setPopupComponent(tree);
64  }
65  }
66 
67  @Override
70  if(v != null) {
71  setBandText(v.getName());
72  } else {
73  setBandText("");
74  }
75  return v;
76  }
77 
78  @Override
80  tree.setObjectValue(v);
81  if(v != null) {
82  setBandText(v.getName());
83  } else {
84  setBandText("");
85  }
86  }
87 
88 }
void setPopupComponent(Component component)
void selectItemByText(String text)