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.

VLazyInitItemIdentifiers.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. /**
  5. *
  6. */
  7. package com.vaadin.terminal.gwt.client.ui.dd;
  8. import java.util.HashSet;
  9. import com.vaadin.terminal.gwt.client.UIDL;
  10. /**
  11. *
  12. */
  13. public class VLazyInitItemIdentifiers extends VAcceptCriterion {
  14. private boolean loaded = false;
  15. private HashSet<String> hashSet;
  16. private VDragEvent lastDragEvent;
  17. @AcceptCriterion("com.vaadin.ui.Table.TableDropCriterion")
  18. final public static class VTableLazyInitItemIdentifiers extends
  19. VLazyInitItemIdentifiers {
  20. // all logic in superclass
  21. }
  22. @AcceptCriterion("com.vaadin.ui.Tree.TreeDropCriterion")
  23. final public static class VTreeLazyInitItemIdentifiers extends
  24. VLazyInitItemIdentifiers {
  25. // all logic in superclass
  26. }
  27. @Override
  28. public void accept(final VDragEvent drag, UIDL configuration,
  29. final VAcceptCallback callback) {
  30. if (lastDragEvent == null || lastDragEvent != drag) {
  31. loaded = false;
  32. lastDragEvent = drag;
  33. }
  34. if (loaded) {
  35. Object object = drag.getDropDetails().get("itemIdOver");
  36. if (hashSet.contains(object)) {
  37. callback.accepted(drag);
  38. }
  39. } else {
  40. VDragEventServerCallback acceptCallback = new VDragEventServerCallback() {
  41. public void handleResponse(boolean accepted, UIDL response) {
  42. hashSet = new HashSet<String>();
  43. String[] stringArrayAttribute = response
  44. .getStringArrayAttribute("allowedIds");
  45. for (int i = 0; i < stringArrayAttribute.length; i++) {
  46. hashSet.add(stringArrayAttribute[i]);
  47. }
  48. loaded = true;
  49. if (accepted) {
  50. callback.accepted(drag);
  51. }
  52. }
  53. };
  54. VDragAndDropManager.get().visitServer(acceptCallback);
  55. }
  56. }
  57. @Override
  58. public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
  59. return loaded;
  60. }
  61. @Override
  62. protected boolean accept(VDragEvent drag, UIDL configuration) {
  63. return false; // not used is this implementation
  64. }
  65. }