From 1ac4f9724106fcf4abaab892210122231710c6be Mon Sep 17 00:00:00 2001 From: Adam Wagner Date: Thu, 16 Mar 2017 20:35:46 +0200 Subject: Make it possible to drop things on top of Grid rows (#8747) Fixes #8400 --- .../com/vaadin/ui/GridDropTargetExtension.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java (limited to 'server/src/main/java/com/vaadin/ui') diff --git a/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java b/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java new file mode 100644 index 0000000000..bf75e26783 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2016 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.ui; + +import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.event.dnd.grid.GridDropEvent; +import com.vaadin.event.dnd.grid.GridDropListener; +import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.grid.GridDropTargetExtensionRpc; +import com.vaadin.shared.ui.grid.GridDropTargetExtensionState; + +/** + * Makes the rows of a Grid HTML5 drop targets. This is the server side + * counterpart of GridDropTargetExtensionConnector. + * + * @param + * Type of the Grid bean. + * @author Vaadin Ltd + * @since + */ +public class GridDropTargetExtension extends DropTargetExtension> { + public GridDropTargetExtension(Grid target) { + super(target); + } + + @Override + protected void registerDropTargetRpc(Grid target) { + registerRpc((GridDropTargetExtensionRpc) (dataTransferText, rowKey) -> { + GridDropEvent event = new GridDropEvent<>(target, + dataTransferText, getUI().getActiveDragSource(), rowKey); + + fireEvent(event); + }); + } + + /** + * Attaches drop listener for the current drop target. {@link + * GridDropListener#drop(GridDropEvent)} is called when drop event happens + * on the client side. + * + * @param listener + * Listener to handle drop event. + * @return Handle to be used to remove this listener. + */ + public Registration addDropListener(GridDropListener listener) { + return addListener(GridDropEvent.class, listener, + GridDropListener.DROP_METHOD); + } + + @Override + protected GridDropTargetExtensionState getState() { + return (GridDropTargetExtensionState) super.getState(); + } + + @Override + protected GridDropTargetExtensionState getState(boolean markAsDirty) { + return (GridDropTargetExtensionState) super.getState(markAsDirty); + } +} -- cgit v1.2.3