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.

TestForChildComponentRendering.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.vaadin.tests;
  2. import java.util.ArrayList;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import com.vaadin.server.ExternalResource;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.Component;
  8. import com.vaadin.ui.CustomComponent;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Link;
  11. import com.vaadin.ui.VerticalLayout;
  12. import com.vaadin.v7.ui.Select;
  13. /**
  14. *
  15. * This Component contains some simple test to see that component updates its
  16. * contents propertly.
  17. *
  18. * @author Vaadin Ltd.
  19. */
  20. public class TestForChildComponentRendering extends CustomComponent {
  21. private final VerticalLayout main;
  22. public TestForChildComponentRendering() {
  23. main = new VerticalLayout();
  24. setCompositionRoot(main);
  25. createNewView();
  26. }
  27. public void createNewView() {
  28. main.removeAllComponents();
  29. main.addComponent(new Label("SDFGFHFHGJGFDSDSSSGFDD"));
  30. final Link l = new Link();
  31. l.setCaption("Siirry Vaadiniin");
  32. l.setResource(new ExternalResource("http://www.vaadin.com/"));
  33. l.setTargetHeight(200);
  34. l.setTargetWidth(500);
  35. l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);
  36. main.addComponent(l);
  37. final Select se = new Select();
  38. se.setCaption("VALITSET TÄSTÄ");
  39. se.addItem("valinta1");
  40. se.addItem("Valinta 2");
  41. Button b = new Button("refresh view", event -> createNewView());
  42. main.addComponent(b);
  43. b = new Button("reorder view", event -> randomReorder());
  44. main.addComponent(b);
  45. b = new Button("remove randomly one component",
  46. event -> removeRandomComponent());
  47. main.addComponent(b);
  48. }
  49. public void randomReorder() {
  50. final Iterator<Component> it = main.getComponentIterator();
  51. final List<Component> components = new ArrayList<>();
  52. while (it.hasNext()) {
  53. components.add(it.next());
  54. }
  55. final VerticalLayout v = main;
  56. v.removeAllComponents();
  57. for (int i = components.size(); i > 0; i--) {
  58. final int index = (int) (Math.random() * i);
  59. v.addComponent(components.get(index));
  60. components.remove(index);
  61. }
  62. }
  63. public void removeRandomComponent() {
  64. final Iterator<Component> it = main.getComponentIterator();
  65. final List<Component> components = new ArrayList<>();
  66. while (it.hasNext()) {
  67. components.add(it.next());
  68. }
  69. final int size = components.size();
  70. final int index = (int) (Math.random() * size);
  71. main.removeComponent(components.get(index));
  72. }
  73. }