final Button addItemButton = new Button("addItem()",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Item item = container.addItem("addItem() " + nextToAdd);
if (item != null) {
item.getItemProperty("column1").setValue(
"addItem() " + nextToAdd);
}
nextToAdd++;
nextLabel.setCaption("Next id: " + nextToAdd);
}
});
addItemButton.setImmediate(true);
vl.addComponent(addItemButton);
final Button addItemAfterButton = new Button("addItemAfter()",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Object selection = table.getValue();
if (selection == null) {
return;
}
String id = "addItemAfter() " + nextToAdd;
Item item = container.addItemAfter(selection, id);
if (item != null) {
item.getItemProperty("column1").setValue(id);
table.setValue(id);
} else {
getMainWindow().showNotification(
"Adding item after " + selection
+ " failed");
}
nextToAdd++;
nextLabel.setCaption("Next id: " + nextToAdd);
}
});
addItemAfterButton.setImmediate(true);
vl.addComponent(addItemAfterButton);
position = new TextField("Position:", "0");
vl.addComponent(position);
final Button addItemAtButton = new Button("addItemAt()",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
int index = Integer.parseInt(position.getValue()
.toString());
String id = "addItemAt() " + nextToAdd;
Item item = container.addItemAt(index, id);
if (item != null) {
item.getItemProperty("column1").setValue(id);
table.setValue(id);
} else {
getMainWindow().showNotification(
"Adding item at index "
+ position.getValue() + " failed");