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

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