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.

IsSameSourceAndTarget.java 1.5KB

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