* 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 APItags/8.1.0.alpha8
@@ -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 |
@@ -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); |
@@ -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(); | |||
} | |||
} |
@@ -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; | |||
}-*/; |
@@ -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); | |||
} | |||
@@ -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; |
@@ -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() { | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
/** | |||
* |
@@ -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. |
@@ -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; | |||
/** | |||
* |
@@ -15,7 +15,7 @@ | |||
*/ | |||
package com.vaadin.client.ui.dd; | |||
import com.vaadin.event.dnd.DropTargetExtension; | |||
import com.vaadin.ui.dnd.DropTargetExtension; | |||
/** | |||
* Generated by |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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 |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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; | |||
/** | |||
* |
@@ -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. |
@@ -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 |
@@ -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 |
@@ -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. |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
@@ -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 |
@@ -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; |
@@ -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; |
@@ -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); | |||
} | |||
} |
@@ -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. |
@@ -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 |
@@ -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); | |||
} | |||
} |
@@ -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. |
@@ -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. |
@@ -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. |
@@ -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); |
@@ -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; | |||
@@ -162,20 +192,13 @@ public class DragSourceExtension<T extends AbstractComponent> extends | |||
return getState(false).dataTransferText; | |||
} | |||
/** | |||
* 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); |
@@ -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,28 +45,48 @@ 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. | |||
@@ -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 |
@@ -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 |
@@ -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 { |
@@ -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. |
@@ -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 |
@@ -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. |
@@ -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 |
@@ -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. |
@@ -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 |
@@ -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 |
@@ -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 { |
@@ -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 { | |||
} |
@@ -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; |
@@ -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") |
@@ -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") |
@@ -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 |
@@ -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 { | |||