You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DropTargetDetailEquals.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.event.dd.acceptcriteria;
  8. import com.vaadin.event.dd.DragAndDropEvent;
  9. import com.vaadin.event.dd.DropTargetDetails;
  10. import com.vaadin.terminal.PaintException;
  11. import com.vaadin.terminal.PaintTarget;
  12. import com.vaadin.terminal.gwt.client.ui.dd.VDropDetailEquals;
  13. /**
  14. * Criterion for checking if drop target details contains the specific property
  15. * with the specific value. Currently only String values are supported.
  16. *
  17. * @since 6.3
  18. *
  19. * TODO add support for other basic data types that we support in UIDL.
  20. *
  21. */
  22. @ClientCriterion(VDropDetailEquals.class)
  23. public class DropTargetDetailEquals extends ClientSideCriterion {
  24. private static final long serialVersionUID = 763165450054331246L;
  25. private String propertyName;
  26. private Object value;
  27. /**
  28. * Constructs a criterion which ensures that the value there is a value in
  29. * {@link DropTargetDetails} that equals the reference value.
  30. *
  31. * @param dataFlavor
  32. * the type of data to be checked
  33. * @param value
  34. * the reference value to which the drop target detail will be
  35. * compared
  36. */
  37. public DropTargetDetailEquals(String dataFlavor, String value) {
  38. propertyName = dataFlavor;
  39. this.value = value;
  40. }
  41. public DropTargetDetailEquals(String dataFlavor, Boolean true1) {
  42. propertyName = dataFlavor;
  43. value = true1;
  44. }
  45. @Override
  46. public void paintContent(PaintTarget target) throws PaintException {
  47. super.paintContent(target);
  48. target.addAttribute("p", propertyName);
  49. if (value instanceof Boolean) {
  50. target.addAttribute("v", ((Boolean) value).booleanValue());
  51. target.addAttribute("t", "b");
  52. } else if (value instanceof String) {
  53. target.addAttribute("v", (String) value);
  54. }
  55. }
  56. public boolean accept(DragAndDropEvent dragEvent) {
  57. Object data = dragEvent.getDropTargetDetails().getData(propertyName);
  58. return value.equals(data);
  59. }
  60. @Override
  61. protected String getIdentifier() {
  62. // sub classes by default use VDropDetailEquals a client implementation
  63. return DropTargetDetailEquals.class.getCanonicalName();
  64. }
  65. }