blob: 66346287ba4bc4253663490f67c602463e0cfeb0 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package com.vaadin.tests.components.customfield;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;
public class BooleanFieldExample extends TestBase {
/**
* Data model class with two boolean fields.
*/
public static class TwoBooleans {
private boolean normal;
private boolean custom;
public void setNormal(boolean normal) {
this.normal = normal;
}
public boolean isNormal() {
return normal;
}
public void setCustom(boolean custom) {
this.custom = custom;
}
public boolean isCustom() {
return custom;
}
}
@Override
protected void setup() {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
final Form form = new Form();
form.setFooter(null);
form.setFormFieldFactory(new DefaultFieldFactory() {
@Override
public Field createField(Item item, Object propertyId,
Component uiContext) {
if ("custom".equals(propertyId)) {
return new BooleanField();
}
return super.createField(item, propertyId, uiContext);
}
});
final TwoBooleans data = new TwoBooleans();
form.setItemDataSource(new BeanItem<TwoBooleans>(data));
layout.addComponent(form);
Button submit = new Button("Submit", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
form.commit();
Notification.show("The custom boolean field value is "
+ data.isCustom() + ".\n"
+ "The checkbox (default boolean field) value is "
+ data.isNormal() + ".");
}
});
layout.addComponent(submit);
addComponent(layout);
}
@Override
protected String getDescription() {
return "A customized field (a two-state button) for editing a boolean value.";
}
@Override
protected Integer getTicketNumber() {
return null;
}
}
|