Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TargetDetailIs.java 2.1KB

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