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.

LayoutAttachListenerInfo.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.vaadin.tests.components;
  2. import java.util.Arrays;
  3. import com.vaadin.ui.AbsoluteLayout;
  4. import com.vaadin.ui.Button;
  5. import com.vaadin.ui.Button.ClickEvent;
  6. import com.vaadin.ui.GridLayout;
  7. import com.vaadin.ui.HasComponents.ComponentAttachEvent;
  8. import com.vaadin.ui.HasComponents.ComponentAttachListener;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Notification;
  11. import com.vaadin.ui.VerticalLayout;
  12. import com.vaadin.v7.data.Property.ValueChangeEvent;
  13. import com.vaadin.v7.data.Property.ValueChangeListener;
  14. import com.vaadin.v7.ui.OptionGroup;
  15. public class LayoutAttachListenerInfo extends TestBase {
  16. private VerticalLayout content = new VerticalLayout();
  17. @Override
  18. protected void setup() {
  19. OptionGroup layouts = new OptionGroup("Layouts",
  20. Arrays.asList("AbsoluteLayout", "OrderedLayout", "GridLayout"));
  21. layouts.select("AbsoluteLayout");
  22. layouts.setImmediate(true);
  23. layouts.addValueChangeListener(new ValueChangeListener() {
  24. @Override
  25. public void valueChange(ValueChangeEvent event) {
  26. if (event.getProperty().getValue().equals("AbsoluteLayout")) {
  27. testAbsoluteLayout();
  28. } else if (event.getProperty().getValue()
  29. .equals("OrderedLayout")) {
  30. testOrderedLayout();
  31. } else if (event.getProperty().getValue()
  32. .equals("GridLayout")) {
  33. testGridLayout();
  34. }
  35. }
  36. });
  37. addComponent(layouts);
  38. addComponent(content);
  39. testAbsoluteLayout();
  40. }
  41. @Override
  42. protected String getDescription() {
  43. return "When pressing the attach button a Label with the value \"X\" "
  44. + "should get added to the selected layout and a notification of the position"
  45. + " of the component should be visible";
  46. }
  47. @Override
  48. protected Integer getTicketNumber() {
  49. return 6368;
  50. }
  51. private void testAbsoluteLayout() {
  52. content.removeAllComponents();
  53. final AbsoluteLayout a = new AbsoluteLayout();
  54. a.setWidth("300px");
  55. a.setHeight("300px");
  56. a.addComponentAttachListener(new ComponentAttachListener() {
  57. @Override
  58. public void componentAttachedToContainer(
  59. ComponentAttachEvent event) {
  60. AbsoluteLayout layout = (AbsoluteLayout) event.getContainer();
  61. AbsoluteLayout.ComponentPosition position = layout
  62. .getPosition(event.getAttachedComponent());
  63. getMainWindow().showNotification(
  64. "Attached to " + position.getCSSString(),
  65. Notification.TYPE_ERROR_MESSAGE);
  66. }
  67. });
  68. content.addComponent(a);
  69. content.addComponent(new Button("Attach label to layout",
  70. new Button.ClickListener() {
  71. @Override
  72. public void buttonClick(ClickEvent event) {
  73. a.addComponent(new Label("X"), "top:50px;left:50px");
  74. }
  75. }));
  76. }
  77. private void testOrderedLayout() {
  78. content.removeAllComponents();
  79. final VerticalLayout v = new VerticalLayout();
  80. v.setWidth("300px");
  81. v.setHeight("300px");
  82. v.addComponentAttachListener(new ComponentAttachListener() {
  83. @Override
  84. public void componentAttachedToContainer(
  85. ComponentAttachEvent event) {
  86. VerticalLayout layout = (VerticalLayout) event.getContainer();
  87. getMainWindow().showNotification(
  88. "Attached to index " + layout.getComponentIndex(
  89. event.getAttachedComponent()),
  90. Notification.TYPE_ERROR_MESSAGE);
  91. }
  92. });
  93. content.addComponent(v);
  94. content.addComponent(new Button("Attach label to layout",
  95. new Button.ClickListener() {
  96. @Override
  97. public void buttonClick(ClickEvent event) {
  98. v.addComponent(new Label("X"));
  99. }
  100. }));
  101. }
  102. private void testGridLayout() {
  103. content.removeAllComponents();
  104. final GridLayout g = new GridLayout(4, 4);
  105. g.setWidth("300px");
  106. g.setHeight("300px");
  107. g.setHideEmptyRowsAndColumns(true);
  108. g.addComponentAttachListener(new ComponentAttachListener() {
  109. @Override
  110. public void componentAttachedToContainer(
  111. ComponentAttachEvent event) {
  112. GridLayout layout = (GridLayout) event.getContainer();
  113. GridLayout.Area area = layout
  114. .getComponentArea(event.getAttachedComponent());
  115. getMainWindow().showNotification(
  116. "Attached to " + area.getColumn1() + ","
  117. + area.getRow1(),
  118. Notification.TYPE_ERROR_MESSAGE);
  119. }
  120. });
  121. content.addComponent(g);
  122. content.addComponent(new Button("Attach label to layout",
  123. new Button.ClickListener() {
  124. @Override
  125. public void buttonClick(ClickEvent event) {
  126. g.addComponent(new Label("X"), 2, 3);
  127. }
  128. }));
  129. }
  130. }