summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorAdam Wagner <wbadam@users.noreply.github.com>2017-04-10 16:28:22 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-04-10 16:28:22 +0300
commit125d2a926c1bc7213e732da053cc7ea5cb019c50 (patch)
treeb4f78aa32c5bd5e33e97f44fcd02f8ace254c1af /client/src
parent3cf3d1b564571f272e84dc152d8a606acf6ce808 (diff)
downloadvaadin-framework-125d2a926c1bc7213e732da053cc7ea5cb019c50.tar.gz
vaadin-framework-125d2a926c1bc7213e732da053cc7ea5cb019c50.zip
Make Button component draggable (#9038)
* Make Button component draggable (#9037) * Add own state to button drag source
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java58
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VButton.java30
2 files changed, 87 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java b/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java
new file mode 100644
index 0000000000..4c07d7a7e1
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/extensions/ButtonDragSourceConnector.java
@@ -0,0 +1,58 @@
+/*
+ * 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/ui/VButton.java b/client/src/main/java/com/vaadin/client/ui/VButton.java
index d3bba9549c..6a32b32439 100644
--- a/client/src/main/java/com/vaadin/client/ui/VButton.java
+++ b/client/src/main/java/com/vaadin/client/ui/VButton.java
@@ -67,6 +67,13 @@ public class VButton extends FocusWidget implements ClickHandler {
private int tabIndex = 0;
+ /**
+ * Switch for disabling mouse capturing.
+ *
+ * @see #isCapturing
+ */
+ private boolean capturingEnabled = true;
+
/*
* BELOW PRIVATE MEMBERS COPY-PASTED FROM GWT CustomButton
*/
@@ -199,7 +206,7 @@ public class VButton extends FocusWidget implements ClickHandler {
clickPending = true;
setFocus(true);
DOM.setCapture(getElement());
- isCapturing = true;
+ isCapturing = isCapturingEnabled();
addStyleName(CLASSNAME_PRESSED);
}
break;
@@ -412,6 +419,27 @@ public class VButton extends FocusWidget implements ClickHandler {
}
}
+ /**
+ * Enables or disables the widget's capturing of mouse events with the mouse
+ * held down.
+ *
+ * @param enabled
+ * {@literal true} if capturing enabled, {@literal false} otherwise
+ */
+ public void setCapturingEnabled(boolean enabled) {
+ capturingEnabled = enabled;
+ }
+
+ /**
+ * Returns if the widget's capturing of mouse events are enabled.
+ *
+ * @return {@literal true} if mouse capturing is enabled, {@literal false}
+ * otherwise
+ */
+ public boolean isCapturingEnabled() {
+ return capturingEnabled;
+ }
+
private static native int getHorizontalBorderAndPaddingWidth(Element elem)
/*-{
// THIS METHOD IS ONLY USED FOR INTERNET EXPLORER, IT DOESN'T WORK WITH OTHERS