BrightSide Workbench Full Report + Source Code
GenericOverloadCombobox.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.zkoss.input;
19 
20 import java.util.LinkedList;
21 import org.zkoss.zul.Combobox;
22 import org.zkoss.zul.Constraint;
23 
28 @Deprecated
29 public abstract class GenericOverloadCombobox<V> extends Combobox {
30 
31  private boolean allowNotInModelValues = false;
32  private V currentValue;
33 
34  public GenericOverloadCombobox(String value) {
35  super(value);
36  createModel(value);
37  }
38 
40  createModel("");
41  }
42 
43  public V getObjectValue() {
44  V value = getObjectFromText(getText());
45  getSelectedItem();
46  if(value == null && allowNotInModelValues && currentValue != null) {
47  if(getText().equals(getTextFromObject(currentValue))) {
48  value = currentValue;
49  }
50  }
51  return value;
52  }
53 
54  public void setObjectValue(V value) {
55  Constraint c = getConstraint();
56  setConstraint((Constraint) null);
57  currentValue = value;
58  setText(value != null ? getTextFromObject(value) : null);
59  setConstraint(c);
60  }
61 
62  public boolean isAllowNotInModelValues() {
63  return allowNotInModelValues;
64  }
65 
66  public void setAllowNotInModelValues(boolean allowNotInModelValues) {
67  this.allowNotInModelValues = allowNotInModelValues;
68  }
69 
70  public void refreshModel() {
71  Constraint c = getConstraint();
72  setConstraint((Constraint) null);
73  createModel(getText());
74  setConstraint(c);
75  }
76 
77  private void createModel(String value) {
78  GenericComboModel ccm = new GenericComboModel(new Object[0]) {
79  @Override
80  public void populateList(String value, LinkedList list, int nRows) {
81  GenericOverloadCombobox.this.populateList(value, list, nRows);
82  }
83  };
84  //ccm.getSubModel(value, 10);
85  setModel(ccm);
86  }
87 
88  public abstract void populateList(String value, LinkedList list, int nRows);
89  public abstract V getObjectFromText(String text);
90  public abstract String getTextFromObject(V value);
91 
92 }
void setAllowNotInModelValues(boolean allowNotInModelValues)
abstract String getTextFromObject(V value)
abstract void populateList(String value, LinkedList list, int nRows)