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.

DragSourceIs.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.event.dd.acceptcriteria;
  8. import com.vaadin.event.TransferableImpl;
  9. import com.vaadin.event.dd.DragAndDropEvent;
  10. import com.vaadin.terminal.PaintException;
  11. import com.vaadin.terminal.PaintTarget;
  12. import com.vaadin.terminal.gwt.client.ui.dd.VDragSourceIs;
  13. import com.vaadin.ui.Component;
  14. /**
  15. * Client side criteria that checks if the drag source is one of the given
  16. * components.
  17. *
  18. * @since 6.3
  19. */
  20. @ClientCriterion(VDragSourceIs.class)
  21. public class DragSourceIs extends ClientSideCriterion {
  22. private Component[] component;
  23. public DragSourceIs(Component... component) {
  24. this.component = component;
  25. }
  26. @Override
  27. public void paintContent(PaintTarget target) throws PaintException {
  28. super.paintContent(target);
  29. target.addAttribute("c", component.length);
  30. for (int i = 0; i < component.length; i++) {
  31. target.addAttribute("component" + i, component[i]);
  32. }
  33. }
  34. public boolean accept(DragAndDropEvent dragEvent) {
  35. if (dragEvent.getTransferable() instanceof TransferableImpl) {
  36. Component sourceComponent = ((TransferableImpl) dragEvent
  37. .getTransferable()).getSourceComponent();
  38. for (Component c : component) {
  39. if (c == sourceComponent) {
  40. return true;
  41. }
  42. }
  43. }
  44. return false;
  45. }
  46. }