You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InitiallyDisabledGrid.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.vaadin.tests.components.grid;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.data.bean.Person;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.Grid;
  8. import com.vaadin.ui.UI;
  9. import com.vaadin.ui.VerticalLayout;
  10. public class InitiallyDisabledGrid extends UI {
  11. @Override
  12. protected void init(VaadinRequest request) {
  13. VerticalLayout layout = new VerticalLayout();
  14. layout.setMargin(false);
  15. layout.setSpacing(false);
  16. setContent(layout);
  17. layout.setSizeFull();
  18. layout.setWidth("600px");
  19. layout.setHeight("600px");
  20. final Grid<Person> grid = createGrid();
  21. Button button = new Button("Enable/Disable",
  22. event -> grid.setEnabled(!grid.isEnabled()));
  23. layout.addComponent(button);
  24. VerticalLayout l = new VerticalLayout();
  25. l.setMargin(false);
  26. l.setSpacing(false);
  27. l.setSizeFull();
  28. l.addComponent(grid);
  29. layout.addComponent(l);
  30. layout.setExpandRatio(l, 1.0f);
  31. }
  32. private Grid<Person> createGrid() {
  33. // Have some data
  34. Collection<Person> people = new ArrayList<>();
  35. for (int i = 0; i < 100; i++) {
  36. Person person = new Person();
  37. person.setFirstName("First " + i);
  38. person.setLastName("Last " + i);
  39. people.add(person);
  40. }
  41. // Have a container of some type to contain the data
  42. // Create a grid bound to the container
  43. Grid<Person> grid = new Grid<>();
  44. grid.setSizeFull();
  45. grid.setItems(people);
  46. grid.addColumn(Person::getFirstName).setCaption("First Name");
  47. grid.addColumn(Person::getLastName).setCaption("Last Name");
  48. grid.setEnabled(false);
  49. return grid;
  50. }
  51. }