diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2017-05-12 11:33:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-12 11:33:55 +0300 |
commit | 76892855a7c3f37a1fef5caee3c0debf6aa712e2 (patch) | |
tree | 5f990c860d922439528b548c22d3df8bc45c03d4 | |
parent | 22848f3420b5aded4d35c84f368dd9c44041200f (diff) | |
download | vaadin-framework-76892855a7c3f37a1fef5caee3c0debf6aa712e2.tar.gz vaadin-framework-76892855a7c3f37a1fef5caee3c0debf6aa712e2.zip |
Refactor Html5 DnD feature based on API review (#9306)
* Refactor Html5 DnD client side based on API review
- Moved classes to "correct" packages.
- Removed method DragSourceExtension.clearDataTransferText()
- Remove ButtonDragSource in favor of more generic API
61 files changed, 459 insertions, 400 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java index 64e9c2e7b5..39af55515b 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridDragSourceConnector.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.stream.Collectors; import com.google.gwt.animation.client.AnimationScheduler; -import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; @@ -43,7 +42,7 @@ import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.grid.GridDragSourceRpc; import com.vaadin.shared.ui.grid.GridDragSourceState; import com.vaadin.shared.ui.grid.GridState; -import com.vaadin.ui.GridDragSource; +import com.vaadin.ui.components.grid.GridDragSource; import elemental.events.Event; import elemental.json.Json; @@ -82,7 +81,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { // Set newly added rows draggable getGridBody().setNewEscalatorRowCallback( - rows -> rows.forEach(this::setDraggable)); + rows -> rows.forEach(this::addDraggable)); // Add drag listeners to body element addDragListeners(getGridBody().getElement()); @@ -101,7 +100,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { } // Collect the keys of dragged rows - draggedItemKeys = getDraggedRows(event).stream() + draggedItemKeys = getDraggedRows(nativeEvent).stream() .map(row -> row.getString(GridState.JSONKEY_ROWKEY)) .collect(Collectors.toList()); @@ -153,7 +152,6 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { AnimationScheduler.get().requestAnimationFrame(timestamp -> { badge.removeFromParent(); }, (Element) dragStartEvent.getEventTarget().cast()); - setDraggable(draggedRowElement); } fixDragImageForSafari(draggedRowElement); } @@ -170,24 +168,25 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { } @Override - protected String createDataTransferText(Event dragStartEvent) { + protected String createDataTransferText(NativeEvent dragStartEvent) { JsonArray dragData = toJsonArray(getDraggedRows(dragStartEvent).stream() .map(this::getDragData).collect(Collectors.toList())); return dragData.toJson(); } @Override - protected void sendDragStartEventToServer(Event dragStartEvent) { + protected void sendDragStartEventToServer(NativeEvent dragStartEvent) { // Start server RPC with dragged item keys getRpcProxy(GridDragSourceRpc.class).dragStart(draggedItemKeys); } - private List<JsonObject> getDraggedRows(Event dragStartEvent) { + private List<JsonObject> getDraggedRows(NativeEvent dragStartEvent) { List<JsonObject> draggedRows = new ArrayList<>(); - if (TableRowElement.is((JavaScriptObject) dragStartEvent.getTarget())) { - TableRowElement row = (TableRowElement) dragStartEvent.getTarget(); + if (TableRowElement.is(dragStartEvent.getEventTarget())) { + TableRowElement row = (TableRowElement) dragStartEvent + .getEventTarget().cast(); int rowIndex = ((Escalator.AbstractRowContainer) getGridBody()) .getLogicalRowIndex(row); @@ -224,7 +223,7 @@ public class GridDragSourceConnector extends DragSourceExtensionConnector { } @Override - protected void sendDragEndEventToServer(Event dragEndEvent, + protected void sendDragEndEventToServer(NativeEvent dragEndEvent, DropEffect dropEffect) { // Send server RPC with dragged item keys diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java index 8126f85c1e..cc84392156 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridDropTargetConnector.java @@ -33,7 +33,7 @@ import com.vaadin.shared.ui.grid.DropMode; import com.vaadin.shared.ui.grid.GridDropTargetRpc; import com.vaadin.shared.ui.grid.GridDropTargetState; import com.vaadin.shared.ui.grid.GridState; -import com.vaadin.ui.GridDropTarget; +import com.vaadin.ui.components.grid.GridDropTarget; import elemental.events.Event; import elemental.json.JsonObject; @@ -82,18 +82,17 @@ public class GridDropTargetConnector extends DropTargetExtensionConnector { @Override protected void sendDropEventToServer(String dataTransferText, - String dropEffect, Event dropEvent) { + String dropEffect, NativeEvent dropEvent) { String rowKey = null; DropLocation dropLocation = null; Optional<TableRowElement> targetRow = getTargetRow( - (Element) dropEvent.getTarget()); + (Element) dropEvent.getEventTarget().cast()); if (targetRow.isPresent()) { rowKey = getRowData(targetRow.get()) .getString(GridState.JSONKEY_ROWKEY); - dropLocation = getDropLocation(targetRow.get(), - (NativeEvent) dropEvent); + dropLocation = getDropLocation(targetRow.get(), dropEvent); } getRpcProxy(GridDropTargetRpc.class).drop(dataTransferText, dropEffect, @@ -147,21 +146,22 @@ public class GridDropTargetConnector extends DropTargetExtensionConnector { } @Override - protected void setTargetClassIndicator(Event event) { - getTargetRow(((Element) event.getTarget())).ifPresent(target -> { - - // Get required class name - String className = getTargetClassName(target, (NativeEvent) event); - - // Add or replace class name if changed - if (!target.hasClassName(className)) { - if (currentStyleName != null) { - target.removeClassName(currentStyleName); - } - target.addClassName(className); - currentStyleName = className; - } - }); + protected void addTargetClassIndicator(NativeEvent event) { + getTargetRow(((Element) event.getEventTarget().cast())) + .ifPresent(target -> { + + // Get required class name + String className = getTargetClassName(target, event); + + // Add or replace class name if changed + if (!target.hasClassName(className)) { + if (currentStyleName != null) { + target.removeClassName(currentStyleName); + } + target.addClassName(className); + currentStyleName = className; + } + }); } private String getTargetClassName(Element target, NativeEvent event) { @@ -184,10 +184,10 @@ public class GridDropTargetConnector extends DropTargetExtensionConnector { } @Override - protected void removeTargetClassIndicator(Event event) { + protected void removeTargetClassIndicator(NativeEvent event) { // Remove all possible style names - getTargetRow((Element) event.getTarget()).ifPresent(e -> { + getTargetRow((Element) event.getEventTarget().cast()).ifPresent(e -> { e.removeClassName(styleDragCenter); e.removeClassName(styleDragTop); e.removeClassName(styleDragBottom); diff --git a/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java b/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java deleted file mode 100644 index 4c07d7a7e1..0000000000 --- a/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.client.extensions; - -import com.vaadin.client.ServerConnector; -import com.vaadin.client.ui.VButton; -import com.vaadin.client.ui.button.ButtonConnector; -import com.vaadin.event.dnd.ButtonDragSource; -import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.dnd.ButtonDragSourceState; - -/** - * Extension to make Button a drag source for HTML5 drag and drop functionality. - * - * @author Vaadin Ltd. - * @since 8.1 - */ -@Connect(ButtonDragSource.class) -public class ButtonDragSourceConnector extends DragSourceExtensionConnector { - - private VButton buttonWidget; - - @Override - protected void extend(ServerConnector target) { - super.extend(target); - - buttonWidget = ((ButtonConnector) target).getWidget(); - - // Disable mouse event capturing to make the widget draggable - buttonWidget.setCapturingEnabled(false); - } - - @Override - public void onUnregister() { - super.onUnregister(); - - // Reset mouse event capturing - buttonWidget.setCapturingEnabled(true); - } - - @Override - public ButtonDragSourceState getState() { - return (ButtonDragSourceState) super.getState(); - } -} diff --git a/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java b/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java index ed04f2d00f..d714cf4016 100644 --- a/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/DragSourceExtensionConnector.java @@ -27,11 +27,12 @@ import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.annotations.OnStateChange; -import com.vaadin.event.dnd.DragSourceExtension; +import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.dnd.DragSourceRpc; import com.vaadin.shared.ui.dnd.DragSourceState; import com.vaadin.shared.ui.dnd.DropEffect; +import com.vaadin.ui.dnd.DragSourceExtension; import elemental.events.Event; import elemental.events.EventListener; @@ -73,17 +74,19 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { return; } - setDraggable(getDraggableElement()); + addDraggable(getDraggableElement()); addDragListeners(getDraggableElement()); + + ((AbstractComponentConnector) target).onDragSourceAttached(); } /** - * Sets the given element draggable and adds class name. + * Makes the given element draggable and adds class name. * * @param element * Element to be set draggable. */ - protected void setDraggable(Element element) { + protected void addDraggable(Element element) { element.setDraggable(Element.DRAGGABLE_TRUE); element.addClassName( getStylePrimaryName(element) + STYLE_SUFFIX_DRAGSOURCE); @@ -138,6 +141,8 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { removeDraggable(dragSource); removeDragListeners(dragSource); + + ((AbstractComponentConnector) getParent()).onDragSourceDetached(); } @OnStateChange("resources") @@ -178,7 +183,7 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { setDragImage(nativeEvent); // Set text data parameter - String dataTransferText = createDataTransferText(event); + String dataTransferText = createDataTransferText(nativeEvent); // Always set something as the text data, or DnD won't work in FF ! if (dataTransferText == null) { dataTransferText = ""; @@ -189,7 +194,7 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { // Initiate firing server side dragstart event when there is a // DragStartListener attached on the server side if (hasEventListener(DragSourceState.EVENT_DRAGSTART)) { - sendDragStartEventToServer(event); + sendDragStartEventToServer(nativeEvent); } // Stop event bubbling @@ -246,7 +251,7 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { * Event to set the data for. * @return Textual data to be set for the event or {@literal null}. */ - protected String createDataTransferText(Event dragStartEvent) { + protected String createDataTransferText(NativeEvent dragStartEvent) { return getState().dataTransferText; } @@ -259,12 +264,15 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { * @param dragStartEvent * Client side dragstart event. */ - protected void sendDragStartEventToServer(Event dragStartEvent) { + protected void sendDragStartEventToServer(NativeEvent dragStartEvent) { getRpcProxy(DragSourceRpc.class).dragStart(); } /** * Sets the drag image to be displayed. + * <p> + * Override this method in case you need custom drag image setting. Called + * from {@link #onDragStart(Event)}. * * @param dragStartEvent * The drag start event. @@ -307,7 +315,7 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { assert dropEffect != null : "Drop effect should never be null"; - sendDragEndEventToServer(event, + sendDragEndEventToServer(nativeEvent, DropEffect.valueOf(dropEffect.toUpperCase())); } } @@ -321,7 +329,7 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { * Drop effect of the dragend event, extracted from {@code * DataTransfer.dropEffect} parameter. */ - protected void sendDragEndEventToServer(Event dragEndEvent, + protected void sendDragEndEventToServer(NativeEvent dragEndEvent, DropEffect dropEffect) { getRpcProxy(DragSourceRpc.class).dragEnd(dropEffect); } @@ -329,6 +337,12 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { /** * Finds the draggable element within the widget. By default, returns the * topmost element. + * <p> + * Override this method to make some other than the root element draggable + * instead. + * <p> + * In case you need to make more than whan element draggable, override + * {@link #extend(ServerConnector)} instead. * * @return the draggable element in the parent widget. */ @@ -376,7 +390,14 @@ public class DragSourceExtensionConnector extends AbstractExtensionConnector { dataTransfer.effectAllowed = effectAllowed; }-*/; - static native String getDropEffect(DataTransfer dataTransfer) + /** + * Returns the dropEffect for the given data transfer. + * + * @param dataTransfer + * the data transfer with drop effect + * @return the currently set drop effect + */ + protected static native String getDropEffect(DataTransfer dataTransfer) /*-{ return dataTransfer.dropEffect; }-*/; diff --git a/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java b/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java index acd6d48575..0f3d6413cb 100644 --- a/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/DropTargetExtensionConnector.java @@ -22,12 +22,13 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.dnd.DragSourceState; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.DropTargetRpc; import com.vaadin.shared.ui.dnd.DropTargetState; +import com.vaadin.ui.dnd.DropTargetExtension; import elemental.events.Event; import elemental.events.EventListener; @@ -87,6 +88,8 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { } addDropListeners(getDropTargetElement()); + + ((AbstractComponentConnector) target).onDropTargetAttached(); } /** @@ -96,7 +99,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { * @param element * DOM element to attach event listeners to. */ - protected void addDropListeners(Element element) { + private void addDropListeners(Element element) { EventTarget target = element.cast(); target.addEventListener(Event.DRAGENTER, dragEnterListener); @@ -112,7 +115,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { * @param element * DOM element to remove event listeners from. */ - protected void removeDropListeners(Element element) { + private void removeDropListeners(Element element) { EventTarget target = element.cast(); target.removeEventListener(Event.DRAGENTER, dragEnterListener); @@ -126,6 +129,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { super.onUnregister(); removeDropListeners(getDropTargetElement()); + ((AbstractComponentConnector) getParent()).onDropTargetDetached(); } /** @@ -140,6 +144,9 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { /** * Event handler for the {@code dragenter} event. + * <p> + * Override this method in case custom handling for the dragstart event is + * required. If the drop is allowed, the event should prevent default. * * @param event * browser event to be handled @@ -152,7 +159,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { + STYLE_SUFFIX_DRAG_CENTER; if (isDropAllowed(nativeEvent)) { - setTargetClassIndicator(event); + addTargetClassIndicator(nativeEvent); setDropEffect(nativeEvent); @@ -181,7 +188,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { * @param event * the dragenter or dragover event. */ - protected void setDropEffect(NativeEvent event) { + private void setDropEffect(NativeEvent event) { if (getState().dropEffect != null) { DataTransfer.DropEffect dropEffect = DataTransfer.DropEffect @@ -194,6 +201,9 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { /** * Event handler for the {@code dragover} event. + * <p> + * Override this method in case custom handling for the dragover event is + * required. If the drop is allowed, the event should prevent default. * * @param event * browser event to be handled @@ -204,7 +214,7 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { setDropEffect(nativeEvent); // Add drop target indicator in case the element doesn't have one - setTargetClassIndicator(event); + addTargetClassIndicator(nativeEvent); // Prevent default to allow drop nativeEvent.preventDefault(); @@ -215,22 +225,28 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { .setDropEffect(DataTransfer.DropEffect.NONE); // Remove drop target indicator - removeTargetClassIndicator(event); + removeTargetClassIndicator(nativeEvent); } } /** * Event handler for the {@code dragleave} event. + * <p> + * Override this method in case custom handling for the dragleave event is + * required. * * @param event * browser event to be handled */ protected void onDragLeave(Event event) { - removeTargetClassIndicator(event); + removeTargetClassIndicator((NativeEvent) event); } /** * Event handler for the {@code drop} event. + * <p> + * Override this method in case custom handling for the drop event is + * required. If the drop is allowed, the event should prevent default. * * @param event * browser event to be handled @@ -247,10 +263,10 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { String dropEffect = DragSourceExtensionConnector .getDropEffect(nativeEvent.getDataTransfer()); - sendDropEventToServer(dataTransferText, dropEffect, event); + sendDropEventToServer(dataTransferText, dropEffect, nativeEvent); } - removeTargetClassIndicator(event); + removeTargetClassIndicator(nativeEvent); } private boolean isDropAllowed(NativeEvent event) { @@ -284,30 +300,40 @@ public class DropTargetExtensionConnector extends AbstractExtensionConnector { * Client side drop event. */ protected void sendDropEventToServer(String dataTransferText, - String dropEffect, Event dropEvent) { + String dropEffect, NativeEvent dropEvent) { getRpcProxy(DropTargetRpc.class).drop(dataTransferText, dropEffect); } /** * Add class that indicates that the component is a target. + * <p> + * This is triggered on {@link #onDragEnter(Event) dragenter} and + * {@link #onDragOver(Event) dragover} events pending if the drop is + * possible. The drop is possible if the drop effect for the target and + * source do match and the drop criteria script evaluates to true or is not + * set. * * @param event - * The drag enter or dragover event that triggered the - * indication. + * the dragenter or dragover event that triggered the indication. */ - protected void setTargetClassIndicator(Event event) { + protected void addTargetClassIndicator(NativeEvent event) { getDropTargetElement().addClassName(styleDragCenter); } /** * Remove the drag target indicator class name from the target element. * <p> - * This is triggered on dragleave, drop and dragover events. + * This is triggered on {@link #onDrop(Event) drop}, + * {@link #onDragLeave(Event) dragleave} and {@link #onDragOver(Event) + * dragover} events pending on whether the drop has happened or if it is not + * possible. The drop is not possible if the drop effect for the source and + * target don't match or if there is a drop criteria script that evaluates + * to false. * * @param event * the event that triggered the removal of the indicator */ - protected void removeTargetClassIndicator(Event event) { + protected void removeTargetClassIndicator(NativeEvent event) { getDropTargetElement().removeClassName(styleDragCenter); } diff --git a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java index df236b6072..aba52f7e6b 100644 --- a/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/FileDropTargetConnector.java @@ -27,7 +27,7 @@ import com.vaadin.shared.ui.dnd.FileDropTargetClientRpc; import com.vaadin.shared.ui.dnd.FileDropTargetRpc; import com.vaadin.shared.ui.dnd.FileDropTargetState; import com.vaadin.shared.ui.dnd.FileParameters; -import com.vaadin.ui.FileDropTarget; +import com.vaadin.ui.dnd.FileDropTarget; import elemental.events.Event; import elemental.html.File; diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java index 9985d77477..8ba94f9ba7 100644 --- a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java @@ -48,6 +48,8 @@ import com.vaadin.client.VConsole; import com.vaadin.client.WidgetUtil; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; +import com.vaadin.client.extensions.DragSourceExtensionConnector; +import com.vaadin.client.extensions.DropTargetExtensionConnector; import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.Type; import com.vaadin.client.metadata.TypeData; @@ -811,4 +813,66 @@ public abstract class AbstractComponentConnector extends AbstractConnector public boolean isErrorIndicatorVisible() { return getState().errorMessage != null; } + + /** + * Invoked when a {@link DragSourceExtensionConnector} has been attached to + * this component. + * <p> + * By default, does nothing. If you need to apply some changes to the + * widget, override this method. + * <p> + * This is a framework internal method, and should not be invoked manually. + * + * @since 8.1 + * @see #onDragSourceDetached() + */ + public void onDragSourceAttached() { + + } + + /** + * Invoked when a {@link DragSourceExtensionConnector} has been removed from + * this component. + * <p> + * By default, does nothing. + * <p> + * This is a framework internal method, and should not be invoked manually. + * + * @since 8.1 + * @see #onDragSourceAttached() + */ + public void onDragSourceDetached() { + + } + + /** + * Invoked when a {@link DropTargetExtensionConnector} has been attached to + * this component. + * <p> + * By default, does nothing. If you need to apply some changes to the + * widget, override this method. + * <p> + * This is a framework internal method, and should not be invoked manually. + * + * @since 8.1 + * @see #onDropTargetDetached() + */ + public void onDropTargetAttached() { + + } + + /** + * Invoked when a {@link DropTargetExtensionConnector} has been removed from + * this component. + * <p> + * By default, does nothing. + * <p> + * This is a framework internal method, and should not be invoked manually. + * + * @since 8.1 + * @see #onDropTargetAttached() + */ + public void onDropTargetDetached() { + + } } diff --git a/client/src/main/java/com/vaadin/client/ui/button/ButtonConnector.java b/client/src/main/java/com/vaadin/client/ui/button/ButtonConnector.java index 28b1c6ffc5..f8e51a5dcc 100644 --- a/client/src/main/java/com/vaadin/client/ui/button/ButtonConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/button/ButtonConnector.java @@ -128,4 +128,16 @@ public class ButtonConnector extends AbstractComponentConnector getRpcProxy(ButtonServerRpc.class).click(details); } + + @Override + public void onDragSourceAttached() { + // Disable mouse event capturing to make the widget draggable + getWidget().setCapturingEnabled(false); + } + + @Override + public void onDragSourceDetached() { + // Reset mouse event capturing + getWidget().setCapturingEnabled(true); + } } diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptAll.java b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptAll.java index 315adc6e29..f7c7574476 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptAll.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptAll.java @@ -17,9 +17,9 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.AcceptAll; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriteria.java b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriteria.java index f13b23e3a4..1e8704e92b 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriteria.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriteria.java @@ -16,7 +16,7 @@ package com.vaadin.client.ui.dd; import com.google.gwt.core.client.GWT; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * A class via all AcceptCriteria instances are fetched by an identifier. diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java index e23346d582..f1fe4fb409 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java @@ -16,7 +16,7 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterionFactory.java b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterionFactory.java index ea9858b8ef..b48a27a142 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterionFactory.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterionFactory.java @@ -15,7 +15,7 @@ */ package com.vaadin.client.ui.dd; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * Generated by diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAnd.java b/client/src/main/java/com/vaadin/client/ui/dd/VAnd.java index 94cddaafc6..1aebfa2e27 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAnd.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAnd.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.And; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VContainsDataFlavor.java b/client/src/main/java/com/vaadin/client/ui/dd/VContainsDataFlavor.java index fde060951d..98565713b2 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VContainsDataFlavor.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VContainsDataFlavor.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VDragSourceIs.java b/client/src/main/java/com/vaadin/client/ui/dd/VDragSourceIs.java index a75fb8e771..5c1c9b75a0 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VDragSourceIs.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VDragSourceIs.java @@ -19,8 +19,8 @@ import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorMap; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.SourceIs; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VDropHandler.java b/client/src/main/java/com/vaadin/client/ui/dd/VDropHandler.java index a674a5839e..d402467489 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VDropHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VDropHandler.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; -import com.vaadin.event.dnd.DropListener; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.event.DropListener; /** * Vaadin Widgets that want to receive something via drag and drop implement diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java b/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java index 6ea88d57f9..41b8c6b8e0 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java @@ -18,7 +18,7 @@ package com.vaadin.client.ui.dd; import java.util.HashSet; import com.vaadin.client.UIDL; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VNot.java b/client/src/main/java/com/vaadin/client/ui/dd/VNot.java index 3a79da5fb6..ffa0b25aff 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VNot.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VNot.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; import com.vaadin.event.dd.acceptcriteria.Not; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VOr.java b/client/src/main/java/com/vaadin/client/ui/dd/VOr.java index fd17c44bef..2856f692dc 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VOr.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VOr.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.Or; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VOverTreeNode.java b/client/src/main/java/com/vaadin/client/ui/dd/VOverTreeNode.java index 7e2476acc9..e310fd479d 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VOverTreeNode.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VOverTreeNode.java @@ -16,7 +16,7 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; -import com.vaadin.event.dnd.DropTargetExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java b/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java index 78a37bd16d..69bb013e5c 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VSourceIsTarget.java b/client/src/main/java/com/vaadin/client/ui/dd/VSourceIsTarget.java index 9c989c4f40..d5d8178a76 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VSourceIsTarget.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VSourceIsTarget.java @@ -18,8 +18,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.ComponentConnector; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.SourceIsTarget; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VTargetDetailIs.java b/client/src/main/java/com/vaadin/client/ui/dd/VTargetDetailIs.java index 908613ee1b..fd93f2468b 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VTargetDetailIs.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VTargetDetailIs.java @@ -17,8 +17,8 @@ package com.vaadin.client.ui.dd; import com.vaadin.client.UIDL; import com.vaadin.event.dd.acceptcriteria.TargetDetailIs; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dd.AcceptCriterion; +import com.vaadin.ui.dnd.DropTargetExtension; /** * diff --git a/server/src/main/java/com/vaadin/event/Transferable.java b/server/src/main/java/com/vaadin/event/Transferable.java index f75974a1cc..1f0ed866c1 100644 --- a/server/src/main/java/com/vaadin/event/Transferable.java +++ b/server/src/main/java/com/vaadin/event/Transferable.java @@ -18,9 +18,9 @@ package com.vaadin.event; import java.io.Serializable; import java.util.Collection; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropEvent; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.event.DropEvent; /** * Transferable wraps the data that is to be imported into another component. diff --git a/server/src/main/java/com/vaadin/event/dd/DragAndDropEvent.java b/server/src/main/java/com/vaadin/event/dd/DragAndDropEvent.java index 6f66036e5a..6bf8a7f319 100644 --- a/server/src/main/java/com/vaadin/event/dd/DragAndDropEvent.java +++ b/server/src/main/java/com/vaadin/event/dd/DragAndDropEvent.java @@ -19,7 +19,7 @@ import java.io.Serializable; import com.vaadin.event.Transferable; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; -import com.vaadin.event.dnd.DropEvent; +import com.vaadin.ui.dnd.event.DropEvent; /** * DragAndDropEvent wraps information related to drag and drop operation. It is diff --git a/server/src/main/java/com/vaadin/event/dd/DragSource.java b/server/src/main/java/com/vaadin/event/dd/DragSource.java index 8a3c8c32dc..6361925864 100644 --- a/server/src/main/java/com/vaadin/event/dd/DragSource.java +++ b/server/src/main/java/com/vaadin/event/dd/DragSource.java @@ -19,8 +19,8 @@ import java.util.Map; import com.vaadin.event.Transferable; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; -import com.vaadin.event.dnd.DragSourceExtension; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DragSourceExtension; /** * DragSource is a {@link Component} that builds a {@link Transferable} for a diff --git a/server/src/main/java/com/vaadin/event/dd/DropHandler.java b/server/src/main/java/com/vaadin/event/dd/DropHandler.java index d6183940e9..a96b6206d5 100644 --- a/server/src/main/java/com/vaadin/event/dd/DropHandler.java +++ b/server/src/main/java/com/vaadin/event/dd/DropHandler.java @@ -21,7 +21,7 @@ import com.vaadin.event.Transferable; import com.vaadin.event.dd.acceptcriteria.AcceptAll; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion; -import com.vaadin.event.dnd.DropListener; +import com.vaadin.ui.dnd.event.DropListener; /** * DropHandlers contain the actual business logic for drag and drop operations. diff --git a/server/src/main/java/com/vaadin/event/dd/DropTarget.java b/server/src/main/java/com/vaadin/event/dd/DropTarget.java index 3d346418c0..5202718109 100644 --- a/server/src/main/java/com/vaadin/event/dd/DropTarget.java +++ b/server/src/main/java/com/vaadin/event/dd/DropTarget.java @@ -17,8 +17,8 @@ package com.vaadin.event.dd; import java.util.Map; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DropTargetExtension; /** * DropTarget is an interface for components supporting drop operations. A diff --git a/server/src/main/java/com/vaadin/event/dd/TargetDetails.java b/server/src/main/java/com/vaadin/event/dd/TargetDetails.java index 4a22958952..710fc5792f 100644 --- a/server/src/main/java/com/vaadin/event/dd/TargetDetails.java +++ b/server/src/main/java/com/vaadin/event/dd/TargetDetails.java @@ -17,7 +17,7 @@ package com.vaadin.event.dd; import java.io.Serializable; -import com.vaadin.event.dnd.DropEvent; +import com.vaadin.ui.dnd.event.DropEvent; /** * TargetDetails wraps drop target related information about diff --git a/server/src/main/java/com/vaadin/event/dd/TargetDetailsImpl.java b/server/src/main/java/com/vaadin/event/dd/TargetDetailsImpl.java index fadc1877cf..3ede6a20e0 100644 --- a/server/src/main/java/com/vaadin/event/dd/TargetDetailsImpl.java +++ b/server/src/main/java/com/vaadin/event/dd/TargetDetailsImpl.java @@ -18,8 +18,8 @@ package com.vaadin.event.dd; import java.util.HashMap; import java.util.Map; -import com.vaadin.event.dnd.DropEvent; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.ui.dnd.event.DropEvent; /** * A HashMap backed implementation of {@link TargetDetails} for terminal diff --git a/server/src/main/java/com/vaadin/event/dnd/ButtonDragSource.java b/server/src/main/java/com/vaadin/event/dnd/ButtonDragSource.java deleted file mode 100644 index 3d0d93dfa2..0000000000 --- a/server/src/main/java/com/vaadin/event/dnd/ButtonDragSource.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.event.dnd; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.shared.ui.dnd.ButtonDragSourceState; -import com.vaadin.ui.Button; - -/** - * Extension to make Button a drag source for HTML5 drag and drop functionality. - * - * @author Vaadin Ltd. - * @since 8.1 - */ -@Widgetset("com.vaadin.DefaultWidgetSet") -public class ButtonDragSource extends DragSourceExtension<Button> { - - public ButtonDragSource(Button target) { - super(target); - } - - @Override - protected ButtonDragSourceState getState() { - return (ButtonDragSourceState) super.getState(); - } - - @Override - protected ButtonDragSourceState getState(boolean markAsDirty) { - return (ButtonDragSourceState) super.getState(markAsDirty); - } -} diff --git a/server/src/main/java/com/vaadin/server/DragAndDropService.java b/server/src/main/java/com/vaadin/server/DragAndDropService.java index 11b830352f..64926c531c 100644 --- a/server/src/main/java/com/vaadin/server/DragAndDropService.java +++ b/server/src/main/java/com/vaadin/server/DragAndDropService.java @@ -33,14 +33,14 @@ import com.vaadin.event.dd.DropTarget; import com.vaadin.event.dd.TargetDetails; import com.vaadin.event.dd.TargetDetailsImpl; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Registration; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.ui.dd.DragEventType; import com.vaadin.ui.Component; import com.vaadin.ui.UI; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; import elemental.json.JsonObject; diff --git a/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java b/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java index 591cee6be5..194a354ad0 100644 --- a/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java +++ b/server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java @@ -33,8 +33,6 @@ import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.DropTarget; import com.vaadin.event.dd.TargetDetails; import com.vaadin.event.dd.TargetDetailsImpl; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.StreamVariable; @@ -45,6 +43,8 @@ import com.vaadin.shared.ui.draganddropwrapper.DragAndDropWrapperConstants; import com.vaadin.shared.ui.draganddropwrapper.DragAndDropWrapperServerRpc; import com.vaadin.shared.ui.draganddropwrapper.DragAndDropWrapperState; import com.vaadin.ui.declarative.DesignContext; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * @author Vaadin Ltd diff --git a/server/src/main/java/com/vaadin/ui/Html5File.java b/server/src/main/java/com/vaadin/ui/Html5File.java index b4434e75c9..4480e3d59b 100644 --- a/server/src/main/java/com/vaadin/ui/Html5File.java +++ b/server/src/main/java/com/vaadin/ui/Html5File.java @@ -32,7 +32,17 @@ public class Html5File implements Serializable { private StreamVariable streamVariable; private final String type; - Html5File(String name, long size, String mimeType) { + /** + * Constructs a new Html5 file wrapper. + * + * @param name + * the file name + * @param size + * the size of the file + * @param mimeType + * the type of the file + */ + public Html5File(String name, long size, String mimeType) { this.name = name; this.size = size; type = mimeType; diff --git a/server/src/main/java/com/vaadin/ui/UI.java b/server/src/main/java/com/vaadin/ui/UI.java index 1928aabe87..ed2d58df3c 100644 --- a/server/src/main/java/com/vaadin/ui/UI.java +++ b/server/src/main/java/com/vaadin/ui/UI.java @@ -44,8 +44,6 @@ import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.event.UIEvents.PollEvent; import com.vaadin.event.UIEvents.PollListener; import com.vaadin.event.UIEvents.PollNotifier; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.navigator.Navigator; import com.vaadin.server.ClientConnector; import com.vaadin.server.ComponentSizeValidator; @@ -83,6 +81,8 @@ import com.vaadin.ui.Component.Focusable; import com.vaadin.ui.Dependency.Type; import com.vaadin.ui.Window.WindowOrderChangeListener; import com.vaadin.ui.declarative.Design; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; import com.vaadin.util.ConnectorHelper; import com.vaadin.util.CurrentInstance; import com.vaadin.util.ReflectTools; diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragEndEvent.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragEndEvent.java index 06c583fc57..27fcf222fa 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragEndEvent.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragEndEvent.java @@ -13,14 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; +import java.util.Collections; import java.util.Set; -import com.vaadin.event.dnd.DragEndEvent; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.ui.Grid; -import com.vaadin.ui.GridDragSource; +import com.vaadin.ui.dnd.event.DragEndEvent; /** * Drop event on an HTML5 drop target {@link Grid} row. @@ -55,9 +55,9 @@ public class GridDragEndEvent<T> extends DragEndEvent<Grid<T>> { /** * Get the dragged row items. * - * @return Set of row items that were being dragged. + * @return an unmodifiable set of items that were being dragged. */ public Set<T> getDraggedItems() { - return draggedItems; + return Collections.unmodifiableSet(draggedItems); } } diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragEndListener.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragEndListener.java index eb2b90fa64..d41a58bbb6 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragEndListener.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragEndListener.java @@ -13,12 +13,11 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; -import com.vaadin.ui.GridDragSource; /** * Drop listener for HTML5 drop on a Grid row. diff --git a/server/src/main/java/com/vaadin/ui/GridDragSource.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java index a7798b581a..741ba043c6 100644 --- a/server/src/main/java/com/vaadin/ui/GridDragSource.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.ui; +package com.vaadin.ui.components.grid; import java.util.List; import java.util.Optional; @@ -21,17 +21,14 @@ import java.util.Set; import java.util.stream.Collectors; import com.vaadin.data.provider.DataGenerator; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.grid.GridDragEndEvent; -import com.vaadin.event.dnd.grid.GridDragEndListener; -import com.vaadin.event.dnd.grid.GridDragStartEvent; -import com.vaadin.event.dnd.grid.GridDragStartListener; import com.vaadin.server.SerializableFunction; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.dnd.DragSourceState; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.grid.GridDragSourceRpc; import com.vaadin.shared.ui.grid.GridDragSourceState; +import com.vaadin.ui.Grid; +import com.vaadin.ui.dnd.DragSourceExtension; import elemental.json.JsonObject; @@ -71,18 +68,18 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> { dragDataGenerator = this::generateDragData; // Add drag data generator to Grid - target.addDataGenerator(dragDataGenerator); + target.getDataCommunicator().addDataGenerator(dragDataGenerator); } @Override - protected void registerDragSourceRpc(Grid<T> target) { + protected void registerDragSourceRpc() { registerRpc(new GridDragSourceRpc() { @Override public void dragStart(List<String> draggedItemKeys) { - GridDragStartEvent<T> event = new GridDragStartEvent<>(target, - getState(false).effectAllowed, - getDraggedItems(target, draggedItemKeys)); + GridDragStartEvent<T> event = new GridDragStartEvent<>( + getParent(), getState(false).effectAllowed, + getDraggedItems(getParent(), draggedItemKeys)); fireEvent(event); } @@ -91,8 +88,9 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> { public void dragEnd(DropEffect dropEffect, List<String> draggedItemKeys) { - GridDragEndEvent<T> event = new GridDragEndEvent<>(target, - dropEffect, getDraggedItems(target, draggedItemKeys)); + GridDragEndEvent<T> event = new GridDragEndEvent<>(getParent(), + dropEffect, + getDraggedItems(getParent(), draggedItemKeys)); fireEvent(event); } @@ -135,7 +133,7 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> { * {@link JsonObject} to be appended to the row data. * <p> * Example: - * + * * <pre> * dragSourceExtension.setDragDataGenerator(item -> { * JsonObject dragData = Json.createObject(); @@ -211,7 +209,8 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> { public void remove() { super.remove(); - getParent().removeDataGenerator(dragDataGenerator); + getParent().getDataCommunicator() + .removeDataGenerator(dragDataGenerator); } @Override diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragStartEvent.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragStartEvent.java index 35691d20c2..576dca4ef5 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragStartEvent.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragStartEvent.java @@ -13,14 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; +import java.util.Collections; import java.util.Set; -import com.vaadin.event.dnd.DragStartEvent; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.Grid; -import com.vaadin.ui.GridDragSource; +import com.vaadin.ui.dnd.event.DragStartEvent; /** * Drag start event on an HTML5 drag source {@link Grid} row. @@ -55,9 +55,9 @@ public class GridDragStartEvent<T> extends DragStartEvent<Grid<T>> { /** * Get the dragged row items. * - * @return Set of row items that are being dragged. + * @return an unmodifiable set of items that are being dragged. */ public Set<T> getDraggedItems() { - return draggedItems; + return Collections.unmodifiableSet(draggedItems); } } diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragStartListener.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDragStartListener.java index 0d1e071eea..10f57e85c1 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDragStartListener.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDragStartListener.java @@ -13,12 +13,11 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; -import com.vaadin.ui.GridDragSource; /** * Drag start listener for HTML5 drag start on a Grid row. diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java index df634cf559..40df9f254f 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropEvent.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDropEvent.java @@ -13,15 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropEvent; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.grid.DropLocation; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Grid; -import com.vaadin.ui.GridDropTarget; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.event.DropEvent; /** * Drop event on an HTML5 drop target {@link Grid} row. diff --git a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropListener.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDropListener.java index 0bd48db2ca..efac802ae7 100644 --- a/server/src/main/java/com/vaadin/event/dnd/grid/GridDropListener.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDropListener.java @@ -13,12 +13,11 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd.grid; +package com.vaadin.ui.components.grid; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; -import com.vaadin.ui.GridDropTarget; /** * Drop listener for HTML5 drop on a Grid row. diff --git a/server/src/main/java/com/vaadin/ui/GridDropTarget.java b/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java index 021051130c..435f40da6e 100644 --- a/server/src/main/java/com/vaadin/ui/GridDropTarget.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridDropTarget.java @@ -13,16 +13,15 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.ui; +package com.vaadin.ui.components.grid; -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.dnd.DropEffect; import com.vaadin.shared.ui.grid.DropMode; import com.vaadin.shared.ui.grid.GridDropTargetRpc; import com.vaadin.shared.ui.grid.GridDropTargetState; +import com.vaadin.ui.Grid; +import com.vaadin.ui.dnd.DropTargetExtension; /** * Makes the rows of a Grid HTML5 drop targets. This is the server side @@ -130,14 +129,14 @@ public class GridDropTarget<T> extends DropTargetExtension<Grid<T>> { } @Override - protected void registerDropTargetRpc(Grid<T> target) { + protected void registerDropTargetRpc() { registerRpc((GridDropTargetRpc) (dataTransferText, dropEffect, rowKey, dropLocation) -> { - T dropTargetRow = target.getDataCommunicator().getKeyMapper() + T dropTargetRow = getParent().getDataCommunicator().getKeyMapper() .get(rowKey); - GridDropEvent<T> event = new GridDropEvent<>(target, + GridDropEvent<T> event = new GridDropEvent<>(getParent(), dataTransferText, DropEffect.valueOf(dropEffect.toUpperCase()), getUI().getActiveDragSource(), dropTargetRow, dropLocation); diff --git a/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java b/server/src/main/java/com/vaadin/ui/dnd/DragSourceExtension.java index 7ff84757d9..24192fa592 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragSourceExtension.java +++ b/server/src/main/java/com/vaadin/ui/dnd/DragSourceExtension.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd; import java.util.Objects; @@ -25,18 +25,22 @@ import com.vaadin.shared.ui.dnd.DragSourceState; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.event.DragEndEvent; +import com.vaadin.ui.dnd.event.DragEndListener; +import com.vaadin.ui.dnd.event.DragStartEvent; +import com.vaadin.ui.dnd.event.DragStartListener; /** * Extension to make a component drag source for HTML5 drag and drop * functionality. * * @param <T> - * Type of the component to be extended. + * Type of the component to be extended. * @author Vaadin Ltd * @since 8.1 */ -public class DragSourceExtension<T extends AbstractComponent> extends - AbstractExtension { +public class DragSourceExtension<T extends AbstractComponent> + extends AbstractExtension { private Registration dragStartListenerHandle; private Registration dragEndListenerHandle; @@ -51,22 +55,19 @@ public class DragSourceExtension<T extends AbstractComponent> extends * Extends {@code target} component and makes it a drag source. * * @param target - * Component to be extended. + * Component to be extended. */ public DragSourceExtension(T target) { - - registerDragSourceRpc(target); - super.extend(target); initListeners(); } /** - * Initializes the event listeners this drag source is using. + * Initializes dragstart and -end event listeners for this drag source to + * capture the active drag source for the UI. */ - protected void initListeners() { - + private void initListeners() { // Set current extension as active drag source in the UI dragStartListenerHandle = addDragStartListener( event -> getUI().setActiveDragSource(this)); @@ -76,29 +77,58 @@ public class DragSourceExtension<T extends AbstractComponent> extends event -> getUI().setActiveDragSource(null)); } + @Override + public void attach() { + super.attach(); + + registerDragSourceRpc(); + } + /** - * Register server RPC. - * - * @param target - * Extended component. + * Registers the server side RPC methods invoked from client side on + * <code>dragstart</code> and <code>dragend</code> events. + * <p> + * Override this method if you have custom RPC interface for transmitting + * those events with more data. If just need to do additional things before + * firing the events, then you should override {@link #onDragStart()} and + * {@link #onDragEnd(DropEffect)} instead. */ - protected void registerDragSourceRpc(T target) { + protected void registerDragSourceRpc() { registerRpc(new DragSourceRpc() { @Override public void dragStart() { - DragStartEvent<T> event = new DragStartEvent<>(target, - getState(false).effectAllowed); - fireEvent(event); + onDragStart(); } @Override public void dragEnd(DropEffect dropEffect) { - DragEndEvent<T> event = new DragEndEvent<>(target, dropEffect); - fireEvent(event); + onDragEnd(dropEffect); } }); } + /** + * Method invoked when a <code>dragstart</code> has been sent from client + * side. Fires the {@link DragStartEvent}. + */ + protected void onDragStart() { + DragStartEvent<T> event = new DragStartEvent<>(getParent(), + getState(false).effectAllowed); + fireEvent(event); + } + + /** + * Method invoked when a <code>dragend</code> has been sent from client + * side. Fires the {@link DragEndEvent}. + * + * @param dropEffect + * the drop effect on the dragend + */ + protected void onDragEnd(DropEffect dropEffect) { + DragEndEvent<T> event = new DragEndEvent<>(getParent(), dropEffect); + fireEvent(event); + } + @Override public void remove() { super.remove(); @@ -117,7 +147,7 @@ public class DragSourceExtension<T extends AbstractComponent> extends * equivalent to {@link EffectAllowed#ALL}. * * @param effect - * Effects to allow for this draggable element. Cannot be {@code + * Effects to allow for this draggable element. Cannot be {@code * null}. */ public void setEffectAllowed(EffectAllowed effect) { @@ -146,7 +176,7 @@ public class DragSourceExtension<T extends AbstractComponent> extends * data)} method. * * @param data - * Data to be set for the client side draggable element. + * Data to be set for the client side draggable element. */ public void setDataTransferText(String data) { getState().dataTransferText = data; @@ -163,19 +193,12 @@ public class DragSourceExtension<T extends AbstractComponent> extends } /** - * Clears data of type {@code "text"} in this drag source element. - */ - public void clearDataTransferText() { - getState().dataTransferText = null; - } - - /** * Set server side drag data. This data is available in the drop event and * can be used to transfer data between drag source and drop target if they * are in the same UI. * * @param data - * Data to transfer to drop event. + * Data to transfer to drop event. */ public void setDragData(Object data) { dragData = data; @@ -193,12 +216,12 @@ public class DragSourceExtension<T extends AbstractComponent> extends } /** - * Attaches dragstart listener for the current drag source. {@link - * DragStartListener#dragStart(DragStartEvent)} is called when dragstart - * event happens on the client side. + * Attaches dragstart listener for the current drag source. + * {@link DragStartListener#dragStart(DragStartEvent)} is called when + * dragstart event happens on the client side. * * @param listener - * Listener to handle dragstart event. + * Listener to handle dragstart event. * @return Handle to be used to remove this listener. */ public Registration addDragStartListener(DragStartListener<T> listener) { @@ -208,12 +231,12 @@ public class DragSourceExtension<T extends AbstractComponent> extends } /** - * Attaches dragend listener for the current drag source. {@link - * DragEndListener#dragEnd(DragEndEvent)} is called when dragend + * Attaches dragend listener for the current drag source. + * {@link DragEndListener#dragEnd(DragEndEvent)} is called when dragend * event happens on the client side. * * @param listener - * Listener to handle dragend event. + * Listener to handle dragend event. * @return Handle to be used to remove this listener. */ public Registration addDragEndListener(DragEndListener<T> listener) { @@ -225,7 +248,7 @@ public class DragSourceExtension<T extends AbstractComponent> extends * Set a custom drag image for the current drag source. * * @param imageResource - * Resource of the image to be displayed as drag image. + * Resource of the image to be displayed as drag image. */ public void setDragImage(Resource imageResource) { setResource(DragSourceState.RESOURCE_DRAG_IMAGE, imageResource); diff --git a/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java index 53266a2eea..24a0372f50 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropTargetExtension.java +++ b/server/src/main/java/com/vaadin/ui/dnd/DropTargetExtension.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd; import java.util.Objects; @@ -23,10 +23,12 @@ import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.DropTargetRpc; import com.vaadin.shared.ui.dnd.DropTargetState; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.event.DropEvent; +import com.vaadin.ui.dnd.event.DropListener; /** - * Extension to add drop target functionality to a widget for using HTML5 drag - * and drop. + * Extension to make a component a drop target for HTML5 drag and drop + * functionality. * * @param <T> * Type of the component to be extended. @@ -43,29 +45,49 @@ public class DropTargetExtension<T extends AbstractComponent> * Component to be extended. */ public DropTargetExtension(T target) { + super.extend(target); + } - registerDropTargetRpc(target); + @Override + public void attach() { + super.attach(); - super.extend(target); + registerDropTargetRpc(); } /** - * Register server RPC. - * - * @param target - * Extended component. + * Registers the server side RPC methods invoked from client side on + * <code>drop</code> event. + * <p> + * Override this method if you need to have a custom RPC interface for + * transmitting the drop event with more data. If just need to do additional + * things before firing the drop event, then you should override + * {@link #onDrop(String, DropEffect)} instead. */ - protected void registerDropTargetRpc(T target) { + protected void registerDropTargetRpc() { registerRpc((DropTargetRpc) (dataTransferText, dropEffect) -> { - DropEvent<T> event = new DropEvent<>(target, dataTransferText, - DropEffect.valueOf(dropEffect.toUpperCase()), - getUI().getActiveDragSource()); - - fireEvent(event); + onDrop(dataTransferText, + DropEffect.valueOf(dropEffect.toUpperCase())); }); } /** + * Invoked when a <code>drop</code> has been received from client side. + * Fires the {@link DropEvent}. + * + * @param dataTransferText + * the data transfer of type 'text' for the drop + * @param dropEffect + * the drop effect + */ + protected void onDrop(String dataTransferText, DropEffect dropEffect) { + DropEvent<T> event = new DropEvent<>(getParent(), dataTransferText, + dropEffect, getUI().getActiveDragSource()); + + fireEvent(event); + } + + /** * Sets the drop effect for the current drop target. This is set to the * dropEffect on {@code dragenter} and {@code dragover} events. * <p> @@ -104,9 +126,11 @@ public class DropTargetExtension<T extends AbstractComponent> } /** - * Sets criteria to allow drop on this drop target. The script executes when - * something is dragged on top of the target, and the drop is not allowed in - * case the script returns {@code false}. + * Sets a criteria script in JavaScript to allow drop on this drop target. + * The script is executed when something is dragged on top of the target, + * and the drop is not allowed in case the script returns {@code false}. If + * no script is set, then the drop is always accepted, if the set + * {@link #setDropEffect(DropEffect) dropEffect} matches the drag source. * <p> * <b>IMPORTANT:</b> Construct the criteria script carefully and do not * include untrusted sources such as user input. Always keep in mind that diff --git a/server/src/main/java/com/vaadin/event/dnd/FileDropHandler.java b/server/src/main/java/com/vaadin/ui/dnd/FileDropHandler.java index 5e74e44349..b9eb7d90eb 100644 --- a/server/src/main/java/com/vaadin/event/dnd/FileDropHandler.java +++ b/server/src/main/java/com/vaadin/ui/dnd/FileDropHandler.java @@ -13,11 +13,12 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd; import java.io.Serializable; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.event.FileDropEvent; /** * Handles the drop event on a file drop target. @@ -26,7 +27,7 @@ import com.vaadin.ui.AbstractComponent; * Type of the file drop target component. * @author Vaadin Ltd * @see FileDropEvent - * @see com.vaadin.ui.FileDropTarget + * @see com.vaadin.ui.dnd.FileDropTarget * @since 8.1 */ public interface FileDropHandler<T extends AbstractComponent> extends diff --git a/server/src/main/java/com/vaadin/ui/FileDropTarget.java b/server/src/main/java/com/vaadin/ui/dnd/FileDropTarget.java index 88d2550691..bfb66c4fc4 100644 --- a/server/src/main/java/com/vaadin/ui/FileDropTarget.java +++ b/server/src/main/java/com/vaadin/ui/dnd/FileDropTarget.java @@ -13,15 +13,12 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.ui; +package com.vaadin.ui.dnd; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; -import com.vaadin.event.dnd.DropTargetExtension; -import com.vaadin.event.dnd.FileDropEvent; -import com.vaadin.event.dnd.FileDropHandler; import com.vaadin.server.ServletPortletHelper; import com.vaadin.server.StreamVariable; import com.vaadin.shared.ApplicationConstants; @@ -29,18 +26,28 @@ import com.vaadin.shared.ui.dnd.FileDropTargetClientRpc; import com.vaadin.shared.ui.dnd.FileDropTargetRpc; import com.vaadin.shared.ui.dnd.FileDropTargetState; import com.vaadin.shared.ui.dnd.FileParameters; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.ConnectorTracker; +import com.vaadin.ui.Html5File; +import com.vaadin.ui.UI; +import com.vaadin.ui.dnd.event.FileDropEvent; /** * Extension to add drop target functionality to a widget for accepting and * uploading files. + * <p> + * Dropped files are handled in the {@link FileDropHandler} given in the + * constructor. The file details are first sent to the handler, which can then + * decide which files to upload to server by setting a {@link StreamVariable} + * with {@link Html5File#setStreamVariable(StreamVariable)}. * * @param <T> - * Type of the component to be extended. + * Type of the component to be extended. * @author Vaadin Ltd * @since 8.1 */ -public class FileDropTarget<T extends AbstractComponent> extends - DropTargetExtension<T> { +public class FileDropTarget<T extends AbstractComponent> + extends DropTargetExtension<T> { /** * Handles the file drop event. @@ -52,45 +59,57 @@ public class FileDropTarget<T extends AbstractComponent> extends * drop handler needs to be added to handle the file drop event. * * @param target - * Component to be extended. + * Component to be extended. * @param fileDropHandler - * File drop handler that handles the file drop event. + * File drop handler that handles the file drop event. * @see FileDropEvent */ public FileDropTarget(T target, FileDropHandler<T> fileDropHandler) { super(target); this.fileDropHandler = fileDropHandler; - } - - @Override - protected void registerDropTargetRpc(T target) { - super.registerDropTargetRpc(target); registerRpc(new FileDropTargetRpc() { @Override public void drop(Map<String, FileParameters> fileParams) { - Map<String, Html5File> files = new HashMap<>(); - Map<String, String> urls = new HashMap<>(); - - // Create a collection of html5 files - fileParams.forEach((id, fileParameters) -> { - Html5File html5File = new Html5File( - fileParameters.getName(), fileParameters.getSize(), - fileParameters.getMime()); - files.put(id, html5File); - }); + onDrop(fileParams); + } - // Call drop handler with the collection of dropped files - FileDropEvent<T> event = new FileDropEvent<>(target, - files.values()); - fileDropHandler.drop(event); + @Override + public void poll() { + // Polling server for changes after upload finished + } + }); + } - // Create upload URLs for the files that the drop handler - // attached stream variable to - files.entrySet().stream() - .filter(entry -> entry.getValue().getStreamVariable() - != null).forEach(entry -> { + /** + * Invoked when a file or files have been dropped on client side. Fires the + * {@link FileDropEvent}. + * + * @param fileParams + * map from file ids to actual file details + */ + protected void onDrop(Map<String, FileParameters> fileParams) { + Map<String, Html5File> files = new HashMap<>(); + Map<String, String> urls = new HashMap<>(); + + // Create a collection of html5 files + fileParams.forEach((id, fileParameters) -> { + Html5File html5File = new Html5File(fileParameters.getName(), + fileParameters.getSize(), fileParameters.getMime()); + files.put(id, html5File); + }); + + // Call drop handler with the collection of dropped files + FileDropEvent<T> event = new FileDropEvent<>(getParent(), + files.values()); + fileDropHandler.drop(event); + + // Create upload URLs for the files that the drop handler + // attached stream variable to + files.entrySet().stream() + .filter(entry -> entry.getValue().getStreamVariable() != null) + .forEach(entry -> { String id = entry.getKey(); Html5File file = entry.getValue(); @@ -98,28 +117,20 @@ public class FileDropTarget<T extends AbstractComponent> extends urls.put(id, url); }); - // Send upload URLs to the client if there are files to be - // uploaded - if (urls.size() > 0) { - getRpcProxy(FileDropTargetClientRpc.class) - .sendUploadUrl(urls); - } - } - - @Override - public void poll() { - // Polling server for changes after upload finished - } - }); + // Send upload URLs to the client if there are files to be + // uploaded + if (urls.size() > 0) { + getRpcProxy(FileDropTargetClientRpc.class).sendUploadUrl(urls); + } } /** * Creates an upload URL for the given file and file ID. * * @param file - * File to be uploaded. + * File to be uploaded. * @param id - * Generated ID for the file. + * Generated ID for the file. * @return Upload URL for uploading the file to the server. */ private String createUrl(Html5File file, String id) { @@ -147,7 +158,6 @@ public class FileDropTarget<T extends AbstractComponent> extends return (FileDropTargetState) super.getState(); } - @Override protected FileDropTargetState getState(boolean markAsDirty) { return (FileDropTargetState) super.getState(markAsDirty); @@ -161,7 +171,7 @@ public class FileDropTarget<T extends AbstractComponent> extends @Override @SuppressWarnings("unchecked") public T getParent() { - return (T) super.getParent(); + return super.getParent(); } private class FileReceiver implements StreamVariable { diff --git a/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java b/server/src/main/java/com/vaadin/ui/dnd/event/DragEndEvent.java index 5e0739d2d9..592a81497f 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragEndEvent.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DragEndEvent.java @@ -13,12 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * HTML5 drag end event. diff --git a/server/src/main/java/com/vaadin/event/dnd/DragEndListener.java b/server/src/main/java/com/vaadin/ui/dnd/event/DragEndListener.java index 55b55b2bcd..b8ab67279e 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragEndListener.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DragEndListener.java @@ -13,12 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.DragSourceExtension; /** * Interface to be implemented when creating a dragend listener on a drag diff --git a/server/src/main/java/com/vaadin/event/dnd/DragStartEvent.java b/server/src/main/java/com/vaadin/ui/dnd/event/DragStartEvent.java index 2022f42a00..14d04bad96 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragStartEvent.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DragStartEvent.java @@ -13,11 +13,12 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DragSourceExtension; /** * HTML5 drag start event. diff --git a/server/src/main/java/com/vaadin/event/dnd/DragStartListener.java b/server/src/main/java/com/vaadin/ui/dnd/event/DragStartListener.java index 530a0f113b..42c702f7db 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DragStartListener.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DragStartListener.java @@ -13,12 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.DragSourceExtension; /** * Interface to be implemented when creating a dragstart listener on a drag diff --git a/server/src/main/java/com/vaadin/event/dnd/DropEvent.java b/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java index caa80a88ae..45dabd0a62 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropEvent.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DropEvent.java @@ -13,13 +13,15 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import java.util.Optional; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; /** * Server side drop event. Fired when an HTML5 drop happens. diff --git a/server/src/main/java/com/vaadin/event/dnd/DropListener.java b/server/src/main/java/com/vaadin/ui/dnd/event/DropListener.java index c10f51569c..5f31676468 100644 --- a/server/src/main/java/com/vaadin/event/dnd/DropListener.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/DropListener.java @@ -13,12 +13,13 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import java.lang.reflect.Method; import com.vaadin.event.ConnectorEventListener; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.dnd.DropTargetExtension; /** * Interface to be implemented when creating a drop listener on a drop target diff --git a/server/src/main/java/com/vaadin/event/dnd/FileDropEvent.java b/server/src/main/java/com/vaadin/ui/dnd/event/FileDropEvent.java index 7ad5f410bf..331b83c784 100644 --- a/server/src/main/java/com/vaadin/event/dnd/FileDropEvent.java +++ b/server/src/main/java/com/vaadin/ui/dnd/event/FileDropEvent.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.event.dnd; +package com.vaadin.ui.dnd.event; import java.util.Collection; import java.util.List; @@ -21,6 +21,7 @@ import java.util.List; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; import com.vaadin.ui.Html5File; +import com.vaadin.ui.dnd.FileDropHandler; /** * File drop event that contains the collection of files dropped on a file drop diff --git a/server/src/test/java/com/vaadin/tests/event/dnd/DragAndDropBookExamples.java b/server/src/test/java/com/vaadin/tests/event/dnd/DragAndDropBookExamples.java index 14c8e10452..76bebdec01 100644 --- a/server/src/test/java/com/vaadin/tests/event/dnd/DragAndDropBookExamples.java +++ b/server/src/test/java/com/vaadin/tests/event/dnd/DragAndDropBookExamples.java @@ -2,14 +2,14 @@ package com.vaadin.tests.event.dnd; import java.util.Optional; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.shared.ui.dnd.DropEffect; import com.vaadin.shared.ui.dnd.EffectAllowed; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; import com.vaadin.ui.themes.ValoTheme; public class DragAndDropBookExamples { diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/ButtonDragSourceState.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/ButtonDragSourceState.java deleted file mode 100644 index d035c4d35c..0000000000 --- a/shared/src/main/java/com/vaadin/shared/ui/dnd/ButtonDragSourceState.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.shared.ui.dnd; - -/** - * State class containing parameters for ButtonDragSourceExtension. - * - * @author Vaadin Ltd - * @since 8.1 - */ -public class ButtonDragSourceState extends DragSourceState { - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java index 059c963658..874cb59b91 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java @@ -34,11 +34,11 @@ import com.vaadin.tests.components.AbstractTestUIWithLog; import com.vaadin.tests.util.Person; import com.vaadin.tests.util.TestDataGenerator; import com.vaadin.ui.Grid; -import com.vaadin.ui.GridDragSource; -import com.vaadin.ui.GridDropTarget; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Layout; import com.vaadin.ui.RadioButtonGroup; +import com.vaadin.ui.components.grid.GridDragSource; +import com.vaadin.ui.components.grid.GridDropTarget; import elemental.json.Json; import elemental.json.JsonObject; diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java index 8f72fe225e..d842907c45 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/DragAndDropCardShuffle.java @@ -20,8 +20,6 @@ import java.util.List; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Widgetset; -import com.vaadin.event.dnd.DragSourceExtension; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.server.Page; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.dnd.DropEffect; @@ -31,6 +29,8 @@ import com.vaadin.ui.CheckBox; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; @Theme("valo") @Widgetset("com.vaadin.DefaultWidgetSet") diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/DragImage.java b/uitest/src/main/java/com/vaadin/tests/dnd/DragImage.java index b4ef7ea035..d64958305f 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/DragImage.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/DragImage.java @@ -4,7 +4,6 @@ import java.util.stream.Stream; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Widgetset; -import com.vaadin.event.dnd.DragSourceExtension; import com.vaadin.server.Page; import com.vaadin.server.Page.Styles; import com.vaadin.server.ThemeResource; @@ -14,6 +13,7 @@ import com.vaadin.tests.components.uitest.TestSampler; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.dnd.DragSourceExtension; @Theme("valo") @Widgetset("com.vaadin.DefaultWidgetSet") diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/DraggableButton.java b/uitest/src/main/java/com/vaadin/tests/dnd/DraggableButton.java index 3a4db48eb5..b154045b54 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/DraggableButton.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/DraggableButton.java @@ -15,8 +15,6 @@ */ package com.vaadin.tests.dnd; -import com.vaadin.event.dnd.ButtonDragSource; -import com.vaadin.event.dnd.DropTargetExtension; import com.vaadin.server.Page; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; @@ -24,6 +22,8 @@ import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.dnd.DragSourceExtension; +import com.vaadin.ui.dnd.DropTargetExtension; public class DraggableButton extends AbstractTestUIWithLog { @@ -31,7 +31,7 @@ public class DraggableButton extends AbstractTestUIWithLog { protected void setup(VaadinRequest request) { Button draggableButton = new Button("Draggable Button"); - ButtonDragSource dragSourceExtension = new ButtonDragSource( + DragSourceExtension<Button> dragSourceExtension = new DragSourceExtension<>( draggableButton); dragSourceExtension.setDataTransferText( "If you see this, the drop was successful"); @@ -54,16 +54,10 @@ public class DraggableButton extends AbstractTestUIWithLog { private void setStyle() { Page.Styles styles = Page.getCurrent().getStyles(); - styles.add(".drop-target {" - + "width: 150px;" - + "height: 100px;" - + "border: 1px solid black;" - + "border-radius: 4px;" - + "text-align: center;" - + "}"); - styles.add(".v-drag-over {" - + "border-style: dashed;" - + "}"); + styles.add(".drop-target {" + "width: 150px;" + "height: 100px;" + + "border: 1px solid black;" + "border-radius: 4px;" + + "text-align: center;" + "}"); + styles.add(".v-label-drag-center {" + "border-style: dashed;" + "}"); } @Override diff --git a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java index c01e0293c1..d58e7aa43f 100644 --- a/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/dnd/Html5FileDragAndDropUpload.java @@ -24,13 +24,13 @@ import com.vaadin.server.StreamVariable; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.dnd.FileParameters; import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.FileDropTarget; import com.vaadin.ui.Grid; import com.vaadin.ui.Html5File; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.dnd.FileDropTarget; public class Html5FileDragAndDropUpload extends AbstractTestUIWithLog { |