summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2017-02-09 07:52:15 +0100
committerPekka Hyvönen <pekka@vaadin.com>2017-02-10 15:59:44 +0200
commita9c8e66d14899796e786e643d434daf6f16cf062 (patch)
tree59253d3b06d3223bc2e19b2f8b1b4fd5fb8e3b77 /shared
parent4445eae397818196ba1818470c73ccf34e2033ce (diff)
downloadvaadin-framework-a9c8e66d14899796e786e643d434daf6f16cf062.tar.gz
vaadin-framework-a9c8e66d14899796e786e643d434daf6f16cf062.zip
HTML5 Drag and Drop Support (#8264)
* Add DragSource Extension (#8169) * Add DropTarget Extension (#8170) * Add DragStart Event to DragSource Extension (#8171) * Make DataTransfer.dropEffect configurable (#8174) * Make DragSource.dataTransfer data configurable (#8172) * Add server-side Event for drop (#8177) * Added license headers * Extract handler methods, move DropEvent and DropListener to new file, move enums to top * Replaced LinkedHashMap with Map and added List to preserve order of data * Add API for adding a JS acceptance criteria for dragover and drop (#8178, #8179) * Make DragSource Extension extendable (#8175) * Make DropTarget Extension extendable (#8176) * Added javadoc to protected methods * Moved EffectAllowed to shared so that it could be used in shared state directly * Moved DropEffect to separate file, some review fixes and javadoc * Added list to DropTargetRpc to preserve order of data * Remove event listeners on unregister * Changed method names set/getData() to more descriptive set/getTransferData() * Add server side dragStart event (#8171) * Add style to prevent text selection to allow drag * Remove target indicator style on drop * Add client side dragend event listener for drag source * Add server side dragend listener. Attach client side listener only when server side listener added. * Add drag source information to server side dragstart and dragend events. * Fixed some issues addressed in review * Trigger server side dragstart only when there is a listener attached * Criteria script can be set as null to clear * Use Js Interop instead of JSNI for handling event listeners * Use elemental package instead of Js Interop for handling event listeners * Add missing javadoc for public methods * Add default value "uninitialized" to effectAllowed parameter * Simple test UI for HTML5 DnD functionality (#8395) * Add javadoc and other minor changes
Diffstat (limited to 'shared')
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java35
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceState.java55
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DropEffect.java41
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java42
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetState.java38
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/dnd/EffectAllowed.java81
6 files changed, 292 insertions, 0 deletions
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java
new file mode 100644
index 0000000000..bbad423044
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceRpc.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import com.vaadin.shared.communication.ServerRpc;
+
+/**
+ * RPC for firing server side event when client side dragstart event happens on
+ * drag source.
+ */
+public interface DragSourceRpc extends ServerRpc {
+
+ /**
+ * Called when dragsource event happens on client side.
+ */
+ public void dragStart();
+
+ /**
+ * Called when dragend event happens on client side.
+ */
+ public void dragEnd();
+}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceState.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceState.java
new file mode 100644
index 0000000000..aeb4dd816b
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DragSourceState.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.vaadin.shared.communication.SharedState;
+
+/**
+ * State class containing parameters for DragSourceExtension.
+ */
+public class DragSourceState extends SharedState {
+
+ /**
+ * Event identifier for dragend event.
+ */
+ public static final String EVENT_DRAGEND = "dragend";
+
+ /**
+ * Event identifier for dragstart event.
+ */
+ public static final String EVENT_DRAGSTART = "dragstart";
+
+ /**
+ * {@code DataTransfer.effectAllowed} parameter for the drag event.
+ */
+ public EffectAllowed effectAllowed = EffectAllowed.UNINITIALIZED;
+
+ /**
+ * {@code DataTransfer.types} parameter. Used to keep track of data formats
+ * set for the drag event.
+ */
+ public List<String> types = new ArrayList<>();
+
+ /**
+ * Used to store data in the {@code DataTransfer} object for the drag event.
+ */
+ public Map<String, String> data = new HashMap<>();
+}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DropEffect.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropEffect.java
new file mode 100644
index 0000000000..5056ecfd78
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropEffect.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * Used to specify the drop effect to use on dragenter or dragover events.
+ */
+public enum DropEffect {
+ /**
+ * A copy of the source item is made at the new location.
+ */
+ COPY,
+
+ /**
+ * An item is moved to a new location.
+ */
+ MOVE,
+
+ /**
+ * A link is established to the source at the new location.
+ */
+ LINK,
+
+ /**
+ * The item may not be dropped.
+ */
+ NONE
+}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java
new file mode 100644
index 0000000000..dd21278277
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetRpc.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.util.List;
+import java.util.Map;
+
+import com.vaadin.shared.communication.ServerRpc;
+
+/**
+ * RPC for firing server side drop event when client side drop event happens on
+ * drop target.
+ */
+public interface DropTargetRpc extends ServerRpc {
+
+ /**
+ * Called when drop event happens on client side.
+ *
+ * @param types
+ * Data types that are present in {@code data} map in the same order
+ * as found in {@code DataTransfer.types}.
+ * @param data
+ * Contains data from {@code DataTransfer} object.
+ * @param dropEffect
+ * Drop effect set for the drop target where drop happened.
+ */
+ public void drop(List<String> types, Map<String, String> data,
+ DropEffect dropEffect);
+}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetState.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetState.java
new file mode 100644
index 0000000000..3021c0bd6b
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/DropTargetState.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import com.vaadin.shared.communication.SharedState;
+
+/**
+ * State class containing parameters for DropTargetExtension.
+ */
+public class DropTargetState extends SharedState {
+ /**
+ * {@code DataTransfer.dropEffect} parameter for the drag event
+ */
+ public DropEffect dropEffect;
+
+ /**
+ * Criteria script to allow dragOver event on the element
+ */
+ public String dragOverCriteria;
+
+ /**
+ * Criteria script to allow drop event on the element
+ */
+ public String dropCriteria;
+}
diff --git a/shared/src/main/java/com/vaadin/shared/ui/dnd/EffectAllowed.java b/shared/src/main/java/com/vaadin/shared/ui/dnd/EffectAllowed.java
new file mode 100644
index 0000000000..2ff9f21980
--- /dev/null
+++ b/shared/src/main/java/com/vaadin/shared/ui/dnd/EffectAllowed.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+/**
+ * Used to specify the effect that is allowed for a drag operation.
+ */
+public enum EffectAllowed {
+ /**
+ * The item may not be dropped.
+ */
+ NONE("none"),
+
+ /**
+ * A copy of the source item may be made at the new location.
+ */
+ COPY("copy"),
+
+ /**
+ * An item may be moved to a new location.
+ */
+ MOVE("move"),
+
+ /**
+ * A link may be established to the source at the new location.
+ */
+ LINK("link"),
+
+ /**
+ * A copy or move operation is permitted.
+ */
+ COPY_MOVE("copyMove"),
+
+ /**
+ * A copy or link operation is permitted.
+ */
+ COPY_LINK("copyLink"),
+
+ /**
+ * A link or move operation is permitted.
+ */
+ LINK_MOVE("linkMove"),
+
+ /**
+ * All operations are permitted.
+ */
+ ALL("all"),
+
+ /**
+ * Default state, equivalent to ALL
+ */
+ UNINITIALIZED("uninitialized");
+
+ private final String value;
+
+ EffectAllowed(String value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the string value that is accepted by the client side drag event.
+ *
+ * @return String value accepted by the client side drag event.
+ */
+ public String getValue() {
+ return value;
+ }
+}