this.title = title;
}
@Override
public void init() {
final GridLayout layout = new GridLayout(1, 3);
layout.setWidth("100%");
layout.setMargin(false);
setMainWindow(new Window(this.title, layout));
final BeanContainer<String, Task> beans = new BeanContainer<String, Task>(Task.class);
beans.setBeanIdProperty("id");
final Form form = new Form();
form.setLocale(Locale.GERMAN);
final Table table = new Table(this.title, beans);
MenuBar menu = createMenuBar(beans, table);
layout.addComponent(menu);
table.setSelectable(true);
table.setImmediate(true);
table.setVisibleColumns(VISIBLE_COLUMNS);
table.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
Object selectedId = table.getValue();
@SuppressWarnings("unchecked")
BeanItem<Task> item = (BeanItem<Task>) table.getItem(selectedId);
form.setItemDataSource(item);
form.setVisibleItemProperties(VISIBLE_COLUMNS);
}
});
update(beans);
layout.addComponent(table);
Object first = table.getItemIds().iterator().next();
Item item = table.getItem(first);
form.setItemDataSource(item);
form.setCaption("Edit Task");
form.setVisibleItemProperties(VISIBLE_COLUMNS);
form.setImmediate(true);
form.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
@SuppressWarnings("unchecked")
BeanItem<Task> item = (BeanItem<Task>) form.getItemDataSource();
taskService.updateTask(item.getBean());
}
});
layout.addComponent(form);
}