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.3KB

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