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.

VAcceptCriterion.java 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui.dd;
  5. import com.vaadin.terminal.gwt.client.UIDL;
  6. public abstract class VAcceptCriterion {
  7. /**
  8. * Checks if current drag event has valid drop target and target accepts the
  9. * transferable. If drop target is valid, callback is used.
  10. *
  11. * @param drag
  12. * @param configuration
  13. * @param callback
  14. */
  15. public void accept(final VDragEvent drag, UIDL configuration,
  16. final VAcceptCallback callback) {
  17. if (needsServerSideCheck(drag, configuration)) {
  18. VDragEventServerCallback acceptCallback = new VDragEventServerCallback() {
  19. public void handleResponse(boolean accepted, UIDL response) {
  20. if (accepted) {
  21. callback.accepted(drag);
  22. }
  23. }
  24. };
  25. VDragAndDropManager.get().visitServer(acceptCallback);
  26. } else {
  27. boolean validates = validates(drag, configuration);
  28. if (validates) {
  29. callback.accepted(drag);
  30. }
  31. }
  32. }
  33. public abstract boolean validates(VDragEvent drag, UIDL configuration);
  34. public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
  35. return false;
  36. }
  37. }