summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/calendar/CalendarDragAndDrop.java
blob: 56c4eacba1a97c2eb7fe575e59f6ad973510b51c (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright 2000-2014 Vaadin Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

/**
 * 
 */
package com.vaadin.tests.components.calendar;

import java.util.GregorianCalendar;
import java.util.Locale;

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.AbstractTestUI;
import com.vaadin.ui.Calendar;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.TableDragMode;
import com.vaadin.ui.Table.TableTransferable;
import com.vaadin.ui.components.calendar.CalendarTargetDetails;
import com.vaadin.ui.components.calendar.event.BasicEvent;

public class CalendarDragAndDrop extends AbstractTestUI {

    private Calendar calendar;

    private Table table;

    private class TestDropHandler implements DropHandler {

        @Override
        public void drop(DragAndDropEvent event) {
            CalendarTargetDetails details = (CalendarTargetDetails) event
                    .getTargetDetails();

            TableTransferable transferable = (TableTransferable) event
                    .getTransferable();

            calendar.addEvent(new BasicEvent(transferable.getItemId()
                    .toString(), "This event was dragged here", details
                    .getDropTime()));

            table.removeItem(transferable.getItemId());
        }

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

    @Override
    protected void setup(VaadinRequest request) {
        setSizeFull();
        getContent().setSizeFull();
        getLayout().setSizeFull();

        HorizontalLayout root = new HorizontalLayout();
        root.setSizeFull();
        addComponent(root);

        Locale locale = new Locale("en", "US");
        GregorianCalendar cal = new GregorianCalendar(locale);
        cal.set(2013, 0, 1);

        calendar = new Calendar();
        calendar.setId("Calendar");
        calendar.setLocale(locale);
        calendar.setDropHandler(new TestDropHandler());
        calendar.setSizeFull();
        root.addComponent(calendar);

        calendar.setStartDate(cal.getTime());
        cal.add(java.util.Calendar.MONTH, 1);
        calendar.setEndDate(cal.getTime());

        table = new Table();
        table.setSizeFull();
        table.setDragMode(TableDragMode.ROW);
        table.addGeneratedColumn("COLUMN", new Table.ColumnGenerator() {

            @Override
            public Object generateCell(Table source, Object itemId,
                    Object columnId) {
                return itemId;
            }
        });

        for (int eventNum = 1; eventNum < 50; eventNum++) {
            table.addItem("Event " + eventNum);
        }

        root.addComponent(table);
    }

    @Override
    protected String getTestDescription() {
        // TODO Auto-generated method stub
        return null;
    }

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

}