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.

TestForGridLayoutChildComponentRendering.java 3.5KB

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;
  17. import java.util.ArrayList;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import com.vaadin.server.ExternalResource;
  21. import com.vaadin.ui.Button;
  22. import com.vaadin.ui.Component;
  23. import com.vaadin.ui.CustomComponent;
  24. import com.vaadin.ui.GridLayout;
  25. import com.vaadin.ui.Label;
  26. import com.vaadin.ui.Link;
  27. import com.vaadin.v7.ui.Select;
  28. /**
  29. *
  30. * This Component contains some simple test to see that component updates its
  31. * contents propertly.
  32. *
  33. * @author Vaadin Ltd.
  34. */
  35. public class TestForGridLayoutChildComponentRendering extends CustomComponent {
  36. private final GridLayout main = new GridLayout(2, 3);
  37. public TestForGridLayoutChildComponentRendering() {
  38. setCompositionRoot(main);
  39. createNewView();
  40. }
  41. public void createNewView() {
  42. main.removeAllComponents();
  43. main.addComponent(new Label("SDFGFHFHGJGFDSDSSSGFDD"));
  44. final Link l = new Link();
  45. l.setCaption("Siirry Vaadiniin");
  46. l.setResource(new ExternalResource("http://www.vaadin.com/"));
  47. l.setTargetHeight(200);
  48. l.setTargetWidth(500);
  49. l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);
  50. main.addComponent(l);
  51. final Select se = new Select("Tästä valitaan");
  52. se.setCaption("Whattaa select");
  53. se.addItem("valinta1");
  54. se.addItem("Valinta 2");
  55. main.addComponent(se, 0, 1, 1, 1);
  56. Button b = new Button("refresh view", event -> createNewView());
  57. main.addComponent(b);
  58. b = new Button("reorder view", event -> randomReorder());
  59. main.addComponent(b);
  60. b = new Button("remove randomly one component",
  61. event -> removeRandomComponent());
  62. main.addComponent(b);
  63. }
  64. public void randomReorder() {
  65. final Iterator<Component> it = main.getComponentIterator();
  66. final List<Component> components = new ArrayList<>();
  67. while (it.hasNext()) {
  68. components.add(it.next());
  69. }
  70. main.removeAllComponents();
  71. final int size = components.size();
  72. final int colspanIndex = ((int) (Math.random() * size) / 2) * 2 + 2;
  73. for (int i = components.size(); i > 0; i--) {
  74. final int index = (int) (Math.random() * i);
  75. if (i == colspanIndex) {
  76. main.addComponent(components.get(index), 0, (size - i) / 2, 1,
  77. (size - i) / 2);
  78. } else {
  79. main.addComponent(components.get(index));
  80. }
  81. components.remove(index);
  82. }
  83. }
  84. public void removeRandomComponent() {
  85. final Iterator<Component> it = main.getComponentIterator();
  86. final List<Component> components = new ArrayList<>();
  87. while (it.hasNext()) {
  88. components.add(it.next());
  89. }
  90. final int size = components.size();
  91. final int index = (int) (Math.random() * size);
  92. main.removeComponent(components.get(index));
  93. }
  94. }