-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComboBoxComponent.java
47 lines (35 loc) · 1.29 KB
/
ComboBoxComponent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.vaadin.elements;
import com.vaadin.annotations.HtmlImport;
import elemental.json.JsonArray;
import elemental.json.impl.JreJsonFactory;
@HtmlImport("vaadin://bower_components/vaadin-combo-box/vaadin-combo-box.html")
public class ComboBoxComponent extends AbstractElementComponent {
public static interface ValueChangeListener {
void valueChange(String option);
}
private ComboBoxElement element;
public ComboBoxComponent(String label, String... options) {
element = ComboBoxElement.create();
element.bindAttribute("value", "change");
element.setLabel(label);
if (options != null) {
JsonArray array = new JreJsonFactory().createArray();
for (int i = 0; i < options.length; i++) {
array.set(i, options[i]);
}
element.setItems(array.toJson());
}
Root root = ElementIntegration.getRoot(this);
root.appendChild(element);
}
public String getValue() {
return element.getValue();
}
public void setValue(String value) {
element.setValue(value);
}
public void addValueChangeListener(ValueChangeListener listener) {
element.addEventListener("change",
args -> listener.valueChange(getValue()));
}
}