blob: 5b0ad651edb60eaaf62022de0cc4db5c58d108c0 (
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
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
/**
*
*/
package com.vaadin.event.dd.acceptCriteria;
import com.vaadin.event.TransferableImpl;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VDragSourceIs;
import com.vaadin.ui.Component;
/**
* Client side criteria that checks if the drag source is one of the given
* components.
*
* @since 6.3
*/
@ClientCriterion(VDragSourceIs.class)
public class DragSourceIs extends ClientSideCriterion {
private Component[] component;
public DragSourceIs(Component... component) {
this.component = component;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addAttribute("c", component.length);
for (int i = 0; i < component.length; i++) {
target.addAttribute("component" + i, component[i]);
}
}
public boolean accepts(DragAndDropEvent dragEvent) {
if (dragEvent.getTransferable() instanceof TransferableImpl) {
Component sourceComponent = ((TransferableImpl) dragEvent
.getTransferable()).getSourceComponent();
for (Component c : component) {
if (c == sourceComponent) {
return true;
}
}
}
return false;
}
}
|