diff options
author | Adam Wagner <wbadam@users.noreply.github.com> | 2017-03-16 20:35:46 +0200 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-04-12 14:58:11 +0300 |
commit | 1ac4f9724106fcf4abaab892210122231710c6be (patch) | |
tree | cd63d9a7d1e689b041ca05d25385d4b39929782d /server/src/main/java/com/vaadin/ui | |
parent | 2df1b373aae547275b566fef957322af0b61b427 (diff) | |
download | vaadin-framework-1ac4f9724106fcf4abaab892210122231710c6be.tar.gz vaadin-framework-1ac4f9724106fcf4abaab892210122231710c6be.zip |
Make it possible to drop things on top of Grid rows (#8747)
Fixes #8400
Diffstat (limited to 'server/src/main/java/com/vaadin/ui')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/GridDropTargetExtension.java | 72 |
1 files changed, 72 insertions, 0 deletions
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 <T> + * Type of the Grid bean. + * @author Vaadin Ltd + * @since + */ +public class GridDropTargetExtension<T> extends DropTargetExtension<Grid<T>> { + public GridDropTargetExtension(Grid<T> target) { + super(target); + } + + @Override + protected void registerDropTargetRpc(Grid<T> target) { + registerRpc((GridDropTargetExtensionRpc) (dataTransferText, rowKey) -> { + GridDropEvent<T> 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<T> 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); + } +} |