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.

GridDetailsLayoutExpand.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.components.grid;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import com.vaadin.server.VaadinRequest;
  20. import com.vaadin.tests.components.AbstractTestUI;
  21. import com.vaadin.tests.data.bean.Person;
  22. import com.vaadin.ui.Grid;
  23. import com.vaadin.ui.HorizontalLayout;
  24. import com.vaadin.ui.Label;
  25. import com.vaadin.ui.renderers.NumberRenderer;
  26. /**
  27. * Tests the layouting of Grid's details row when it contains a HorizontalLayout
  28. * with expand ratios.
  29. *
  30. * @author Vaadin Ltd
  31. */
  32. @SuppressWarnings("serial")
  33. public class GridDetailsLayoutExpand extends AbstractTestUI {
  34. @Override
  35. protected void setup(VaadinRequest request) {
  36. final Grid<Person> grid = new Grid<>();
  37. grid.setSizeFull();
  38. grid.addColumn(Person::getFirstName);
  39. grid.addColumn(Person::getAge, new NumberRenderer());
  40. List<Person> persons = new ArrayList<>();
  41. Person person = new Person();
  42. person.setFirstName("Nicolaus Copernicus");
  43. person.setAge(1543);
  44. persons.add(person);
  45. person = new Person();
  46. person.setFirstName("Galileo Galilei");
  47. person.setAge(1564);
  48. persons.add(person);
  49. person = new Person();
  50. person.setFirstName("Johannes Kepler");
  51. person.setAge(1571);
  52. persons.add(person);
  53. grid.setItems(persons);
  54. addComponent(grid);
  55. grid.setDetailsGenerator(item -> {
  56. final HorizontalLayout detailsLayout = new HorizontalLayout();
  57. detailsLayout.setSpacing(false);
  58. detailsLayout.setSizeFull();
  59. detailsLayout.setHeightUndefined();
  60. // Label 1 first element of the detailsLayout, taking 200 pixels
  61. final Label lbl1 = new Label("test1");
  62. lbl1.setWidth("200px");
  63. detailsLayout.addComponent(lbl1);
  64. // layout2 second element of the detailsLayout, taking the rest
  65. // of the available space
  66. final HorizontalLayout layout2 = new HorizontalLayout();
  67. layout2.setSpacing(false);
  68. layout2.setSizeFull();
  69. layout2.setHeightUndefined();
  70. detailsLayout.addComponent(layout2);
  71. detailsLayout.setExpandRatio(layout2, 1);
  72. // 2 Labels added to the layout2
  73. final Label lbl2 = new Label("test2");
  74. lbl2.setWidth("100%");
  75. lbl2.setId("lbl2");
  76. layout2.addComponent(lbl2);
  77. final Label lbl3 = new Label("test3");
  78. lbl3.setWidth("100%");
  79. lbl3.setId("lbl3");
  80. layout2.addComponent(lbl3);
  81. return detailsLayout;
  82. });
  83. grid.addItemClickListener(event -> {
  84. final Person itemId = event.getItem();
  85. grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
  86. });
  87. }
  88. @Override
  89. protected Integer getTicketNumber() {
  90. return 18821;
  91. }
  92. @Override
  93. protected String getTestDescription() {
  94. return "Details row must be the same after opening another details row";
  95. }
  96. }