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