blob: a2b24533b3a1e3e2157cdd7801dcf9bb271c4a64 (
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
|
/*
@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 class DropTargetDetailEquals extends ClientSideCriterion {
private static final long serialVersionUID = 763165450054331246L;
private String propertyName;
private Object 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;
}
public DropTargetDetailEquals(String dataFlavor, Boolean true1) {
propertyName = dataFlavor;
value = true1;
}
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addAttribute("p", propertyName);
if (value instanceof Boolean) {
target.addAttribute("v", ((Boolean) value).booleanValue());
target.addAttribute("t", "b");
} else if (value instanceof String) {
target.addAttribute("v", (String) value);
}
}
public boolean accept(DragAndDropEvent dragEvent) {
Object data = dragEvent.getDropTargetDetails().getData(propertyName);
return value.equals(data);
}
@Override
protected String getIdentifier() {
// sub classes by default use VDropDetailEquals a client implementation
return DropTargetDetailEquals.class.getCanonicalName();
}
}
|