com.vaadin.flow.component.dnd.DropEvent Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2000-2024 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.component.dnd;
import java.util.Optional;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentUtil;
import com.vaadin.flow.component.DomEvent;
import com.vaadin.flow.component.EventData;
import com.vaadin.flow.component.dnd.internal.DndUtil;
/**
* Server side drop event. Fired when an HTML5 drop happens on a valid drop
* target.
*
* @param
* Type of the drop target component.
* @author Vaadin Ltd
* @see DropTarget#addDropListener(com.vaadin.flow.component.ComponentEventListener)
* @author Vaadin Ltd
* @since 2.0
*/
@DomEvent("drop")
public class DropEvent extends ComponentEvent {
private final EffectAllowed effectAllowed;
private final String dropEffect;
private final Component dragSourceComponent;
/**
* Creates a server side drop event.
*
* @param source
* Component that received the drop.
* @param fromClient
* true
if the event originated from the client
* side, false
otherwise
* @param effectAllowed
* the effect allowed by the drag source
*/
public DropEvent(T source, boolean fromClient,
@EventData("event.dataTransfer.effectAllowed") String effectAllowed) {
super(source, fromClient);
this.effectAllowed = EffectAllowed.fromString(effectAllowed);
// capture drop effect from server side, since it is meant for drag
// end event
dropEffect = source.getElement()
.getProperty(DndUtil.DROP_EFFECT_ELEMENT_PROPERTY);
// when the event is created, the drop target is always attached
dragSourceComponent = getComponent().getUI()
.orElseThrow(() -> new IllegalStateException(
"Drop target received a drop event but not attached "
+ "to an UI."))
.getActiveDragSourceComponent();
}
/**
* Gets the server side drag data. This data can be set during the drag
* start event on the server side and can be used to transfer data between
* drag source and drop target when they are in the same UI.
*
* @return Optional server side drag data if set and the drag source and the
* drop target are in the same UI, otherwise empty {@code Optional}.
*/
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy