summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/dd/StartHtml5Drag.java
blob: 609b2fe4fc8a10194888b6d79f8b68e487c6e9b8 (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
package com.vaadin.tests.dd;

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.ClassResource;
import com.vaadin.server.Sizeable;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;

public class StartHtml5Drag extends TestBase {

    @Override
    protected void setup() {
        DragAndDropWrapper dragStart = new DragAndDropWrapper(new Label(
                "Drag me"));
        dragStart.setDragStartMode(DragStartMode.HTML5);
        dragStart.setHTML5DataFlavor("Text", "HTML5!");
        addComponent(dragStart);

        DragAndDropWrapper dropTarget = new DragAndDropWrapper(new Label(
                "over here"));
        dropTarget.setDropHandler(new DropHandler() {

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

            @Override
            public void drop(DragAndDropEvent event) {
                getWindows()
                        .iterator()
                        .next()
                        .showNotification(
                                ((WrapperTransferable) event.getTransferable())
                                        .getText());
            }
        });
        addComponent(dropTarget);

        Embedded iframe = new Embedded("", new ClassResource("html5drop.htm"));
        iframe.setType(Embedded.TYPE_BROWSER);
        iframe.setWidth(400, Sizeable.UNITS_PIXELS);
        iframe.setHeight(400, Sizeable.UNITS_PIXELS);
        addComponent(iframe);

    }

    @Override
    protected String getDescription() {
        return "Should work. Try to e.g. drag the 'Hello Vaadin user' "
                + "label to native text editor application. In text "
                + "editor app 'HTML5!' text should appear.";
    }

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