aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/dd/DDInterrupt.java
blob: 1939bbbce553a2af45dc30896fbfa43552a3d884 (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
package com.vaadin.tests.dd;

import com.vaadin.annotations.Widgetset;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.TargetDetailsImpl;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.widgetset.TestingWidgetSet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
import com.vaadin.ui.Label;

/**
 * Test for interrupting drag-and-drop.
 * 
 * @author Vaadin Ltd
 */
@Widgetset(TestingWidgetSet.NAME)
public class DDInterrupt extends AbstractTestUI {

    private SpacebarPanner sp;

    @Override
    protected void setup(VaadinRequest vaadinRequest) {
        final CssLayout layout = new CssLayout();
        layout.setWidth("500px");
        layout.setHeight("500px");

        addButton("Click to interrupt next drag.", new Button.ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                sp.interruptNext();
            }
        });

        final Label draggableLabel = new Label("Drag me");
        draggableLabel.setId("draggable");

        DragAndDropWrapper dndLayoutWrapper = new DragAndDropWrapper(layout);
        addComponent(dndLayoutWrapper);

        DragAndDropWrapper labelWrapper = new DragAndDropWrapper(draggableLabel);
        draggableLabel.setSizeUndefined();
        labelWrapper.setDragStartMode(DragStartMode.COMPONENT);
        labelWrapper.setSizeUndefined();

        layout.addComponent(labelWrapper);

        dndLayoutWrapper.setDropHandler(new DropHandler() {

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return AcceptAll.get();
            }

            @Override
            public void drop(DragAndDropEvent event) {
                TargetDetailsImpl targetDetails = (TargetDetailsImpl) event
                        .getTargetDetails();
                int x = targetDetails.getMouseEvent().getRelativeX();
                int y = targetDetails.getMouseEvent().getRelativeY();

                draggableLabel.setWidth(x, Unit.PIXELS);
                draggableLabel.setHeight(y, Unit.PIXELS);
            }
        });

        sp = SpacebarPanner.wrap(this);
    }

    @Override
    protected Integer getTicketNumber() {
        return 17163;
    }

    @Override
    protected String getTestDescription() {
        return "Hold space while clicking and dragging the label, or click the button before draggin the label. There should be no client-side exception.";
    }
}