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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 com.vaadin.event.ItemClickEvent;
  18. import com.vaadin.event.ItemClickEvent.ItemClickListener;
  19. import com.vaadin.server.VaadinRequest;
  20. import com.vaadin.tests.components.AbstractTestUI;
  21. import com.vaadin.ui.Component;
  22. import com.vaadin.ui.HorizontalLayout;
  23. import com.vaadin.ui.Label;
  24. import com.vaadin.ui.LegacyGrid;
  25. import com.vaadin.ui.LegacyGrid.DetailsGenerator;
  26. import com.vaadin.ui.LegacyGrid.RowReference;
  27. /**
  28. * Tests the layouting of Grid's details row when it contains a HorizontalLayout
  29. * with expand ratios.
  30. *
  31. * @author Vaadin Ltd
  32. */
  33. @SuppressWarnings("serial")
  34. public class GridDetailsLayoutExpand extends AbstractTestUI {
  35. @Override
  36. protected void setup(VaadinRequest request) {
  37. final LegacyGrid grid = new LegacyGrid();
  38. grid.setSizeFull();
  39. grid.addColumn("name", String.class);
  40. grid.addColumn("born", Integer.class);
  41. grid.addRow("Nicolaus Copernicus", 1543);
  42. grid.addRow("Galileo Galilei", 1564);
  43. grid.addRow("Johannes Kepler", 1571);
  44. addComponent(grid);
  45. grid.setDetailsGenerator(new DetailsGenerator() {
  46. @Override
  47. public Component getDetails(final RowReference rowReference) {
  48. final HorizontalLayout detailsLayout = new HorizontalLayout();
  49. detailsLayout.setSizeFull();
  50. detailsLayout.setHeightUndefined();
  51. // Label 1 first element of the detailsLayout, taking 200 pixels
  52. final Label lbl1 = new Label("test1");
  53. lbl1.setWidth("200px");
  54. detailsLayout.addComponent(lbl1);
  55. // layout2 second element of the detailsLayout, taking the rest
  56. // of the available space
  57. final HorizontalLayout layout2 = new HorizontalLayout();
  58. layout2.setSizeFull();
  59. layout2.setHeightUndefined();
  60. detailsLayout.addComponent(layout2);
  61. detailsLayout.setExpandRatio(layout2, 1);
  62. // 2 Labels added to the layout2
  63. final Label lbl2 = new Label("test2");
  64. lbl2.setId("lbl2");
  65. layout2.addComponent(lbl2);
  66. final Label lbl3 = new Label("test3");
  67. lbl3.setId("lbl3");
  68. layout2.addComponent(lbl3);
  69. return detailsLayout;
  70. }
  71. });
  72. grid.addItemClickListener(new ItemClickListener() {
  73. @Override
  74. public void itemClick(final ItemClickEvent event) {
  75. final Object itemId = event.getItemId();
  76. grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
  77. }
  78. });
  79. }
  80. @Override
  81. protected Integer getTicketNumber() {
  82. return 18821;
  83. }
  84. @Override
  85. protected String getTestDescription() {
  86. return "Details row must be the same after opening another details row";
  87. }
  88. }