Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TestForGridLayoutChildComponentRendering.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.GridLayout;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.ui.Link;
  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 TestForGridLayoutChildComponentRendering extends CustomComponent {
  21. private final GridLayout main = new GridLayout(2, 3);
  22. public TestForGridLayoutChildComponentRendering() {
  23. setCompositionRoot(main);
  24. createNewView();
  25. }
  26. public void createNewView() {
  27. main.removeAllComponents();
  28. main.addComponent(new Label("SDFGFHFHGJGFDSDSSSGFDD"));
  29. final Link l = new Link();
  30. l.setCaption("Siirry Vaadiniin");
  31. l.setResource(new ExternalResource("http://www.vaadin.com/"));
  32. l.setTargetHeight(200);
  33. l.setTargetWidth(500);
  34. l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);
  35. main.addComponent(l);
  36. final Select se = new Select("Tästä valitaan");
  37. se.setCaption("Whattaa select");
  38. se.addItem("valinta1");
  39. se.addItem("Valinta 2");
  40. main.addComponent(se, 0, 1, 1, 1);
  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. main.removeAllComponents();
  56. final int size = components.size();
  57. final int colspanIndex = ((int) (Math.random() * size) / 2) * 2 + 2;
  58. for (int i = components.size(); i > 0; i--) {
  59. final int index = (int) (Math.random() * i);
  60. if (i == colspanIndex) {
  61. main.addComponent(components.get(index), 0, (size - i) / 2, 1,
  62. (size - i) / 2);
  63. } else {
  64. main.addComponent(components.get(index));
  65. }
  66. components.remove(index);
  67. }
  68. }
  69. public void removeRandomComponent() {
  70. final Iterator<Component> it = main.getComponentIterator();
  71. final List<Component> components = new ArrayList<>();
  72. while (it.hasNext()) {
  73. components.add(it.next());
  74. }
  75. final int size = components.size();
  76. final int index = (int) (Math.random() * size);
  77. main.removeComponent(components.get(index));
  78. }
  79. }