public void buttonClick(ClickEvent event) {
toggle(table);
}
}));
GridLayout content = new GridLayout(2, 3);
root.setContent(content);
main.addComponent(root);
TextField tf = new TextField("Enabled");
tf.setImmediate(true);
content.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
content.addComponent(tf);
VerticalLayout oneLayout = new VerticalLayout();
oneLayout.setMargin(true);
one.setContent(oneLayout);
content.addComponent(one);
tf = new TextField("Enabled");
tf.setImmediate(true);
oneLayout.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
oneLayout.addComponent(tf);
VerticalLayout twoLayout = new VerticalLayout();
twoLayout.setMargin(true);
two.setContent(twoLayout);
content.addComponent(two);
tf = new TextField("Enabled");
tf.setImmediate(true);
twoLayout.addComponent(tf);
tf = new TextField("Disabled");
tf.setImmediate(true);
tf.setEnabled(false);
twoLayout.addComponent(tf);
form = new Form();
form.setCaption("Enabled");
form.setFormFieldFactory(new DefaultFieldFactory() {
@Override
public Field<?> createField(Item item, Object propertyId,
Component uiContext) {
Field<?> f = super.createField(item, propertyId, uiContext);
f.setEnabled(!"disabled".equals(propertyId));
return f;
}
});
form.setItemDataSource(new BeanItem<MyBean>(new MyBean()));
content.addComponent(form);
table = new Table("Enabled");
table.setPageLength(7);
table.addContainerProperty("Text", String.class, null);
for (int i = 0; i < 150; i++) {
Item item = table.addItem("Item" + i);
Property<String> p = item.getItemProperty("Text");
p.setValue(i % 5 == 0 ? "enabled" : "disabled");
}
table.setTableFieldFactory(new DefaultFieldFactory() {
@Override
public Field<?> createField(Container container, Object itemId,
Object propertyId, Component uiContext) {
Field<?> f = super.createField(container, itemId, propertyId,
uiContext);
Item item = container.getItem(itemId);
Property<?> p = item.getItemProperty(propertyId);
if ("disabled".equals(p.getValue())) {
f.setEnabled(false);
}
return f;
}
});
table.setEditable(true);
content.addComponent(table);
}