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 4.4KB

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