Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GridMemory.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.performance;
  17. import java.util.List;
  18. import java.util.Optional;
  19. import javax.servlet.annotation.WebServlet;
  20. import com.vaadin.annotations.VaadinServletConfiguration;
  21. import com.vaadin.server.VaadinServlet;
  22. import com.vaadin.tests.data.bean.Address;
  23. import com.vaadin.tests.data.bean.Person;
  24. import com.vaadin.ui.Grid;
  25. /**
  26. * @author Vaadin Ltd
  27. *
  28. */
  29. public class GridMemory extends AbstractBeansMemoryTest<Grid<Person>> {
  30. public static final String PATH = "/grid-memory/";
  31. /**
  32. * The main servlet for the application.
  33. */
  34. @WebServlet(urlPatterns = PATH
  35. + "*", name = "GridServlet", asyncSupported = true)
  36. @VaadinServletConfiguration(ui = GridMemory.class, productionMode = false)
  37. public static class Servlet extends VaadinServlet {
  38. }
  39. @Override
  40. protected Grid<Person> createComponent() {
  41. Grid<Person> grid = new Grid<>();
  42. grid.addColumn(Person::getFirstName).setCaption("First Name");
  43. grid.addColumn(Person::getLastName).setCaption("Last Name");
  44. grid.addColumn(person -> Optional.ofNullable(person.getAddress())
  45. .map(Address::getStreetAddress).orElse(null))
  46. .setCaption("Street");
  47. grid.addColumn(person -> Optional.ofNullable(person.getAddress())
  48. .map(Address::getPostalCode).map(Object::toString).orElse(""))
  49. .setCaption("Zip");
  50. grid.addColumn(person -> Optional.ofNullable(person.getAddress())
  51. .map(Address::getCity).orElse(null)).setCaption("City");
  52. return grid;
  53. }
  54. @Override
  55. protected void setInMemoryContainer(Grid<Person> grid,
  56. List<Person> persons) {
  57. grid.setItems(persons);
  58. }
  59. @Override
  60. protected void setBackendContainer(Grid<Person> component,
  61. List<Person> data) {
  62. throw new UnsupportedOperationException();
  63. }
  64. }