blob: b97f0159bbdf8ab5b155f18ce76be58f698f07b3 (
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
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
/**
*
*/
package com.vaadin.event.dd.acceptCriteria;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropTargetDetails;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals;
/**
* Criterion for checking if drop target details contains the specific property
* with the specific value. Currently only String values are supported.
*
* @since 6.3
*
* TODO add support for other basic data types that we support in UIDL.
*
*/
@ClientCriterion(VDropDetailEquals.class)
public final class DropTargetDetailEquals extends ClientSideCriterion {
private String propertyName;
private String value;
/**
* Constructs a criterion which ensures that the value there is a value in
* {@link DropTargetDetails} that equals the reference value.
*
* @param dataFlavor
* the type of data to be checked
* @param value
* the reference value to which the drop target detail will be
* compared
*/
public DropTargetDetailEquals(String dataFlavor, String value) {
propertyName = dataFlavor;
this.value = value;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addAttribute("p", propertyName);
target.addAttribute("v", value);
}
public boolean accepts(DragAndDropEvent dragEvent) {
Object data = dragEvent.getDropTargetDetails().getData(propertyName);
return value.equals(data);
}
}
|