aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/event/dd/acceptCriteria/OverTreeNode.java
blob: e1bcf506b82cef6dc3130ebbc1cecf3719181262 (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
/**
 * 
 */
package com.vaadin.event.dd.acceptCriteria;

import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Tree.Location;
import com.vaadin.ui.Tree.TreeDropDetails;

/**
 * Accepts transferable only on tree Node (middle of the node + can has child)
 * 
 * TODO relocate close to {@link Tree} as this is tree specifif
 * 
 */
public class OverTreeNode extends ClientSideCriterion {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public boolean accepts(DragAndDropEvent dragEvent) {
        try {
            // must be over tree node and in the middle of it (not top or bottom
            // part)
            TreeDropDetails eventDetails = (TreeDropDetails) dragEvent
                    .getDropTargetData();

            Object itemIdOver = eventDetails.getItemIdOver();
            if (!eventDetails.getTarget().areChildrenAllowed(itemIdOver)) {
                return false;
            }

            return eventDetails.getDropLocation() == Location.MIDDLE;
        } catch (Exception e) {
            return false;
        }
    }

}