123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package com.vaadin.tests.components.grid;
-
- import java.io.Serializable;
- import java.util.Arrays;
- import java.util.List;
-
- import com.vaadin.data.Binder;
- import com.vaadin.data.Binder.Binding;
- import com.vaadin.server.VaadinRequest;
- import com.vaadin.tests.components.AbstractReindeerTestUI;
- import com.vaadin.ui.CheckBox;
- import com.vaadin.ui.Grid;
- import com.vaadin.ui.Grid.Column;
- import com.vaadin.ui.TextField;
-
- public class GridCheckBoxDisplay extends AbstractReindeerTestUI {
-
- private static final long serialVersionUID = -5575892909354637168L;
-
- @Override
- protected void setup(VaadinRequest request) {
- List<Todo> items = Arrays.asList(new Todo("Done task", true),
- new Todo("Not done", false));
-
- Grid<Todo> grid = new Grid<>();
- grid.setSizeFull();
-
- TextField taskField = new TextField();
- CheckBox doneField = new CheckBox();
-
- Binder<Todo> binder = grid.getEditor().getBinder();
-
- Binding<Todo, Boolean> doneBinding = binder.bind(doneField,
- Todo::isDone, Todo::setDone);
-
- Column<Todo, String> column = grid
- .addColumn(todo -> String.valueOf(todo.isDone()));
- column.setWidth(75);
- column.setEditorBinding(doneBinding);
-
- grid.addColumn(Todo::getTask).setExpandRatio(1)
- .setEditorComponent(taskField, Todo::setTask);
-
- grid.getEditor().setEnabled(true);
-
- grid.setSelectionMode(Grid.SelectionMode.SINGLE);
-
- grid.setItems(items);
-
- getLayout().addComponent(grid);
- getLayout().setExpandRatio(grid, 1);
-
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 16976;
- }
-
- @Override
- protected String getTestDescription() {
- return "Verify that checkbox state is correct for all items in editor";
- }
-
- public class Todo implements Serializable {
- private static final long serialVersionUID = -5961103142478316018L;
-
- private boolean done;
- private String task = "";
-
- public Todo(String task, boolean done) {
- this.task = task;
- this.done = done;
- }
-
- public boolean isDone() {
- return done;
- }
-
- public void setDone(boolean done) {
- this.done = done;
- }
-
- public String getTask() {
- return task;
- }
-
- public void setTask(String task) {
- this.task = task;
- }
- }
-
- }
|