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.

DragEndEvent.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. package com.vaadin.ui.dnd.event;
  17. import com.vaadin.shared.ui.dnd.DropEffect;
  18. import com.vaadin.shared.ui.dnd.EffectAllowed;
  19. import com.vaadin.ui.AbstractComponent;
  20. import com.vaadin.ui.Component;
  21. import com.vaadin.ui.dnd.DragSourceExtension;
  22. import com.vaadin.ui.dnd.DropTargetExtension;
  23. /**
  24. * HTML5 drag end event.
  25. *
  26. * @param <T>
  27. * Type of the component that was dragged.
  28. * @author Vaadin Ltd
  29. * @see DragSourceExtension#addDragEndListener(DragEndListener)
  30. * @since 8.1
  31. */
  32. public class DragEndEvent<T extends AbstractComponent> extends Component.Event {
  33. private final DropEffect dropEffect;
  34. /**
  35. * Creates a drag end event.
  36. *
  37. * @param source
  38. * Component that was dragged.
  39. * @param dropEffect
  40. * Drop effect from {@code DataTransfer.dropEffect} object.
  41. */
  42. public DragEndEvent(T source, DropEffect dropEffect) {
  43. super(source);
  44. this.dropEffect = dropEffect;
  45. }
  46. /**
  47. * Get drop effect of the dragend event. The value will be the desired
  48. * action, that is the dropEffect value of the last dragenter or dragover
  49. * event. The value depends on the effectAllowed parameter of the drag
  50. * source, the dropEffect parameter of the drop target, and its drag over
  51. * and drop criteria.
  52. * <p>
  53. * If the drop is not successful, the value will be {@code NONE}.
  54. * <p>
  55. * In case the desired drop effect is {@code MOVE}, the data being dragged
  56. * should be removed from the source.
  57. *
  58. * @return The {@code DataTransfer.dropEffect} parameter of the client side
  59. * dragend event.
  60. * @see DragSourceExtension#setEffectAllowed(EffectAllowed)
  61. * @see DropTargetExtension#setDropEffect(DropEffect)
  62. * @see DropTargetExtension#setDropCriteriaScript(String)
  63. */
  64. public DropEffect getDropEffect() {
  65. return dropEffect;
  66. }
  67. /**
  68. * Returns whether the drag event was cancelled. This is a shorthand for
  69. * {@code dropEffect == NONE}.
  70. *
  71. * @return {@code true} if the drop event was cancelled, {@code false}
  72. * otherwise.
  73. */
  74. public boolean isCanceled() {
  75. return getDropEffect() == DropEffect.NONE;
  76. }
  77. /**
  78. * Returns the drag source component where the dragend event occurred.
  79. *
  80. * @return Component which was dragged.
  81. */
  82. @Override
  83. @SuppressWarnings("unchecked")
  84. public T getComponent() {
  85. return (T) super.getComponent();
  86. }
  87. }