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.

SourceIsTarget.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.event.dd.acceptcriteria;
  8. import com.vaadin.event.Transferable;
  9. import com.vaadin.event.TransferableImpl;
  10. import com.vaadin.event.dd.DragAndDropEvent;
  11. import com.vaadin.event.dd.DropTarget;
  12. import com.vaadin.ui.Component;
  13. import com.vaadin.ui.Table;
  14. import com.vaadin.ui.Tree;
  15. /**
  16. *
  17. * A criterion that ensures the drag source is the same as drop target. Eg.
  18. * {@link Tree} or {@link Table} could support only re-ordering of items, but no
  19. * {@link Transferable}s coming outside.
  20. * <p>
  21. * Note! Class is singleton, use {@link #get()} method to get the instance.
  22. *
  23. * @since 6.3
  24. *
  25. */
  26. public class SourceIsTarget extends ClientSideCriterion {
  27. private static final long serialVersionUID = -451399314705532584L;
  28. private static SourceIsTarget instance = new SourceIsTarget();
  29. private SourceIsTarget() {
  30. }
  31. public boolean accept(DragAndDropEvent dragEvent) {
  32. if (dragEvent.getTransferable() instanceof TransferableImpl) {
  33. Component sourceComponent = ((TransferableImpl) dragEvent
  34. .getTransferable()).getSourceComponent();
  35. DropTarget target = dragEvent.getTargetDetails().getTarget();
  36. return sourceComponent == target;
  37. }
  38. return false;
  39. }
  40. public static synchronized SourceIsTarget get() {
  41. return instance;
  42. }
  43. }