Last active
May 19, 2017 13:13
-
-
Save alejandro-du/ce9320a1dda1ab47089a3a6e9a148cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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