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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.GridLayout;
  6. import com.vaadin.ui.Label;
  7. import com.vaadin.ui.Notification;
  8. import com.vaadin.ui.VerticalLayout;
  9. import com.vaadin.v7.ui.OptionGroup;
  10. public class LayoutAttachListenerInfo extends TestBase {
  11. private VerticalLayout content = new VerticalLayout();
  12. @Override
  13. protected void setup() {
  14. OptionGroup layouts = new OptionGroup("Layouts",
  15. Arrays.asList("AbsoluteLayout", "OrderedLayout", "GridLayout"));
  16. layouts.select("AbsoluteLayout");
  17. layouts.setImmediate(true);
  18. layouts.addValueChangeListener(event -> {
  19. if (event.getProperty().getValue().equals("AbsoluteLayout")) {
  20. testAbsoluteLayout();
  21. } else if (event.getProperty().getValue().equals("OrderedLayout")) {
  22. testOrderedLayout();
  23. } else if (event.getProperty().getValue().equals("GridLayout")) {
  24. testGridLayout();
  25. }
  26. });
  27. addComponent(layouts);
  28. addComponent(content);
  29. testAbsoluteLayout();
  30. }
  31. @Override
  32. protected String getDescription() {
  33. return "When pressing the attach button a Label with the value \"X\" "
  34. + "should get added to the selected layout and a notification of the position"
  35. + " of the component should be visible";
  36. }
  37. @Override
  38. protected Integer getTicketNumber() {
  39. return 6368;
  40. }
  41. private void testAbsoluteLayout() {
  42. content.removeAllComponents();
  43. final AbsoluteLayout a = new AbsoluteLayout();
  44. a.setWidth("300px");
  45. a.setHeight("300px");
  46. a.addComponentAttachListener(event -> {
  47. AbsoluteLayout layout = (AbsoluteLayout) event.getContainer();
  48. AbsoluteLayout.ComponentPosition position = layout
  49. .getPosition(event.getAttachedComponent());
  50. getMainWindow().showNotification(
  51. "Attached to " + position.getCSSString(),
  52. Notification.TYPE_ERROR_MESSAGE);
  53. });
  54. content.addComponent(a);
  55. content.addComponent(new Button("Attach label to layout",
  56. event -> a.addComponent(new Label("X"), "top:50px;left:50px")));
  57. }
  58. private void testOrderedLayout() {
  59. content.removeAllComponents();
  60. final VerticalLayout v = new VerticalLayout();
  61. v.setWidth("300px");
  62. v.setHeight("300px");
  63. v.addComponentAttachListener(event -> {
  64. VerticalLayout layout = (VerticalLayout) event.getContainer();
  65. getMainWindow().showNotification(
  66. "Attached to index " + layout
  67. .getComponentIndex(event.getAttachedComponent()),
  68. Notification.TYPE_ERROR_MESSAGE);
  69. });
  70. content.addComponent(v);
  71. content.addComponent(new Button("Attach label to layout",
  72. event -> v.addComponent(new Label("X"))));
  73. }
  74. private void testGridLayout() {
  75. content.removeAllComponents();
  76. final GridLayout g = new GridLayout(4, 4);
  77. g.setWidth("300px");
  78. g.setHeight("300px");
  79. g.setHideEmptyRowsAndColumns(true);
  80. g.addComponentAttachListener(event -> {
  81. GridLayout layout = (GridLayout) event.getContainer();
  82. GridLayout.Area area = layout
  83. .getComponentArea(event.getAttachedComponent());
  84. getMainWindow().showNotification(
  85. "Attached to " + area.getColumn1() + "," + area.getRow1(),
  86. Notification.TYPE_ERROR_MESSAGE);
  87. });
  88. content.addComponent(g);
  89. content.addComponent(new Button("Attach label to layout",
  90. event -> g.addComponent(new Label("X"), 2, 3)));
  91. }
  92. }