Skip to content

Instantly share code, notes, and snippets.

@alejandro-du
Last active May 19, 2017 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandro-du/ce9320a1dda1ab47089a3a6e9a148cef to your computer and use it in GitHub Desktop.
Save alejandro-du/ce9320a1dda1ab47089a3a6e9a148cef to your computer and use it in GitHub Desktop.
package com.example;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.renderers.ComponentRenderer;
import com.vaadin.ui.themes.ValoTheme;
/**
* @author Alejandro Duarte.
*/
public class ComponentsInGrid extends VerticalLayout {
private Service service = new Service();
private Grid<Person> grid = new Grid<>();
public ComponentsInGrid() {
grid.setItems(service.findAll());
grid.addColumn(Person::getFirstName).setCaption("First name").setExpandRatio(1);
grid.addColumn(Person::getLastName).setCaption("Last name").setExpandRatio(1);
grid.addComponentColumn(this::buildDeleteButton);
addComponent(grid);
}
private Button buildDeleteButton(Person p) {
Button button = new Button(VaadinIcons.CLOSE);
button.addStyleName(ValoTheme.BUTTON_SMALL);
button.addClickListener(e -> deletePerson(p));
return button;
}
private void deletePerson(Person p) {
service.delete(p);
grid.setItems(service.findAll());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment