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.

DragAndDropFocusObtain.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.vaadin.tests.components.draganddropwrapper;
  2. import com.vaadin.data.HasValue.ValueChangeListener;
  3. import com.vaadin.event.FieldEvents.FocusListener;
  4. import com.vaadin.event.dd.DragAndDropEvent;
  5. import com.vaadin.event.dd.DropHandler;
  6. import com.vaadin.event.dd.acceptcriteria.AcceptAll;
  7. import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
  8. import com.vaadin.server.VaadinRequest;
  9. import com.vaadin.tests.components.AbstractTestUIWithLog;
  10. import com.vaadin.ui.AbstractTextField;
  11. import com.vaadin.ui.DragAndDropWrapper;
  12. import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
  13. import com.vaadin.ui.HorizontalLayout;
  14. import com.vaadin.ui.TextArea;
  15. import com.vaadin.ui.TextField;
  16. import com.vaadin.ui.VerticalLayout;
  17. /**
  18. * Test UI for text area inside {@link DragAndDropWrapper}: text area should
  19. * obtain focus on click.
  20. *
  21. * @author Vaadin Ltd
  22. */
  23. public class DragAndDropFocusObtain extends AbstractTestUIWithLog {
  24. private FocusListener focusListener = event -> log(
  25. "Field '" + event.getComponent().getCaption() + "' focused");
  26. private ValueChangeListener<String> listener = event ->
  27. log("Value of " + ((AbstractTextField) event.getSource()).getCaption()
  28. + " changed to " + event.getValue());
  29. @Override
  30. protected void setup(VaadinRequest request) {
  31. HorizontalLayout hl = new HorizontalLayout();
  32. VerticalLayout dndLayout = createLayout();
  33. VerticalLayout normalLayout = createLayout();
  34. DragAndDropWrapper wrapper = new DragAndDropWrapper(dndLayout);
  35. wrapper.setDragStartMode(DragStartMode.COMPONENT);
  36. wrapper.setDropHandler(new DropHandler() {
  37. @Override
  38. public AcceptCriterion getAcceptCriterion() {
  39. return AcceptAll.get();
  40. }
  41. @Override
  42. public void drop(DragAndDropEvent event) {
  43. log("Dropped " + event.getTransferable().getSourceComponent()
  44. + " on " + event.getTargetDetails().getTarget());
  45. }
  46. });
  47. hl.addComponent(wrapper);
  48. hl.addComponent(normalLayout);
  49. addComponent(hl);
  50. }
  51. private VerticalLayout createLayout() {
  52. VerticalLayout dndLayout = new VerticalLayout();
  53. final TextArea area = new TextArea("Text area 1");
  54. area.setValue("text");
  55. area.addValueChangeListener(listener);
  56. area.addFocusListener(focusListener);
  57. dndLayout.addComponent(area);
  58. final TextArea area2 = new TextArea("Text area 2");
  59. area2.setValue("text");
  60. area2.addValueChangeListener(listener);
  61. area2.addFocusListener(focusListener);
  62. dndLayout.addComponent(area2);
  63. final TextField field = new TextField("Text field 1");
  64. field.setValue("text");
  65. field.addValueChangeListener(listener);
  66. field.addFocusListener(focusListener);
  67. dndLayout.addComponent(field);
  68. final TextField field2 = new TextField("Text field 2");
  69. field2.setValue("text");
  70. field2.addValueChangeListener(listener);
  71. field2.addFocusListener(focusListener);
  72. dndLayout.addComponent(field2);
  73. return dndLayout;
  74. }
  75. @Override
  76. protected String getTestDescription() {
  77. return "Text fields/areas inside Drag and Drop Wrappers should get focus inside DnD wrapper on click.";
  78. }
  79. @Override
  80. protected Integer getTicketNumber() {
  81. return 12838;
  82. }
  83. }