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.

TestComponentAddAndRecursion.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. *
  3. */
  4. package com.vaadin.tests;
  5. import com.vaadin.server.Page;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.CustomComponent;
  8. import com.vaadin.ui.GridLayout;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Notification;
  11. import com.vaadin.ui.Panel;
  12. import com.vaadin.ui.VerticalLayout;
  13. /**
  14. * @author marc
  15. *
  16. */
  17. public class TestComponentAddAndRecursion extends CustomComponent {
  18. Panel p;
  19. VerticalLayout pl;
  20. Panel p2;
  21. VerticalLayout p2l;
  22. Label l;
  23. Label l2;
  24. Panel p3;
  25. VerticalLayout p3l;
  26. public TestComponentAddAndRecursion() {
  27. VerticalLayout main = new VerticalLayout();
  28. setCompositionRoot(main);
  29. l = new Label("A");
  30. l2 = new Label("B");
  31. pl = new VerticalLayout();
  32. pl.setMargin(true);
  33. p = new Panel("p", pl);
  34. pl.addComponent(l);
  35. pl.addComponent(l2);
  36. main.addComponent(p);
  37. p2l = new VerticalLayout();
  38. p2l.setMargin(true);
  39. p2 = new Panel("p2", p2l);
  40. p2l.addComponent(l);
  41. main.addComponent(p2);
  42. p3l = new VerticalLayout();
  43. p3l.setMargin(true);
  44. p3 = new Panel("p3", p3l);
  45. p2l.addComponent(p3);
  46. Button b = new Button("use gridlayout", event -> {
  47. p.setContent(new GridLayout());
  48. p2.setContent(new GridLayout());
  49. p3.setContent(new GridLayout());
  50. });
  51. main.addComponent(b);
  52. b = new Button("use orderedlayout", event -> {
  53. p.setContent(new VerticalLayout());
  54. p2.setContent(new VerticalLayout());
  55. p3.setContent(new VerticalLayout());
  56. });
  57. main.addComponent(b);
  58. b = new Button("move B", event -> p2l.addComponent(l2));
  59. main.addComponent(b);
  60. b = new Button("move p", event -> p3l.addComponent(p));
  61. main.addComponent(b);
  62. b = new Button("add to both", event -> {
  63. Label l = new Label("both");
  64. pl.addComponent(l);
  65. p2l.addComponent(l);
  66. });
  67. main.addComponent(b);
  68. b = new Button("recurse", event -> {
  69. try {
  70. p3l.addComponent(p2);
  71. new Notification("ERROR", "This should have failed",
  72. Notification.TYPE_ERROR_MESSAGE)
  73. .show(Page.getCurrent());
  74. } catch (Exception e) {
  75. new Notification("OK", "threw, as expected",
  76. Notification.TYPE_ERROR_MESSAGE)
  77. .show(Page.getCurrent());
  78. }
  79. });
  80. main.addComponent(b);
  81. b = new Button("recurse2", event -> {
  82. VerticalLayout layout = new VerticalLayout();
  83. Panel p = new Panel("dynamic", layout);
  84. layout.addComponent(p2);
  85. try {
  86. p3l.addComponent(p);
  87. new Notification("ERROR", "This should have failed",
  88. Notification.TYPE_ERROR_MESSAGE)
  89. .show(Page.getCurrent());
  90. } catch (Exception e) {
  91. new Notification("OK", "threw, as expected",
  92. Notification.TYPE_ERROR_MESSAGE)
  93. .show(Page.getCurrent());
  94. }
  95. });
  96. main.addComponent(b);
  97. /*
  98. * And that's it! The framework will display the main window and its
  99. * contents when the application is accessed with the terminal.
  100. */
  101. }
  102. }