BrightSide Workbench Full Report + Source Code
EnumListbox.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 org.turro.i18n.I_;
21 import org.zkoss.zul.Listitem;
22 
27 public class EnumListbox<V extends Enum<V>> extends GenericListbox<V> {
28 
29  private V[] values;
30  private boolean allowNull;
31  private String nullLabel = "None";
32 
33  public EnumListbox(V[] values) {
34  this.values = values;
35  }
36 
37  public boolean isAllowNull() {
38  return allowNull;
39  }
40 
41  public void setAllowNull(boolean allowNull) {
42  this.allowNull = allowNull;
43  }
44 
45  public String getNullLabel() {
46  return nullLabel;
47  }
48 
49  public void setNullLabel(String nullLabel) {
50  this.nullLabel = nullLabel;
51  }
52 
53  public V[] getValues() {
54  return values;
55  }
56 
57  public void setValues(V[] values) {
58  this.values = values;
59  }
60 
61  @Override
62  protected void populateList() {
63  if(values == null) return;
64  if(allowNull) {
65  Listitem li = new Listitem(I_.get(nullLabel), null);
66  appendChild(li);
67  }
68  for(V v : values) {
69  Listitem li = new Listitem(getString(v), v);
70  appendChild(li);
71  }
72  }
73 
74  protected String getString(V v) {
75  return I_.byKey(v.toString());
76  }
77 
78 }
static String byKey(String key)
Definition: I_.java:83
static String get(String msg)
Definition: I_.java:41