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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. /**
  17. *
  18. */
  19. package com.vaadin.client.ui.dd;
  20. import java.util.HashSet;
  21. import com.vaadin.client.UIDL;
  22. /**
  23. *
  24. */
  25. public class VLazyInitItemIdentifiers extends VAcceptCriterion {
  26. private boolean loaded = false;
  27. private HashSet<String> hashSet;
  28. private VDragEvent lastDragEvent;
  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. @Override
  44. public void handleResponse(boolean accepted, UIDL response) {
  45. hashSet = new HashSet<>();
  46. String[] stringArrayAttribute = response
  47. .getStringArrayAttribute("allowedIds");
  48. for (int i = 0; i < stringArrayAttribute.length; i++) {
  49. hashSet.add(stringArrayAttribute[i]);
  50. }
  51. loaded = true;
  52. if (accepted) {
  53. callback.accepted(drag);
  54. }
  55. }
  56. };
  57. VDragAndDropManager.get().visitServer(acceptCallback);
  58. }
  59. }
  60. @Override
  61. public boolean needsServerSideCheck(VDragEvent drag, UIDL criterioUIDL) {
  62. return loaded;
  63. }
  64. @Override
  65. protected boolean accept(VDragEvent drag, UIDL configuration) {
  66. return false; // not used is this implementation
  67. }
  68. }