aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Koskinen <anna@vaadin.com>2014-11-05 14:09:45 +0200
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-10 13:21:01 +0200
commit63302d572257f2200355c44098e8df9f9c17842e (patch)
treeee0a4bd0f5d767c932913bc9bb22073dcab8d3db
parentfead7a7435a360776a93df55e5e9ca9e24fa3fd0 (diff)
downloadvaadin-framework-63302d572257f2200355c44098e8df9f9c17842e.tar.gz
vaadin-framework-63302d572257f2200355c44098e8df9f9c17842e.zip
Column drag'n'drop disables HeaderClickEvents until left-click (#15167)
Change-Id: Ic64c0eb685c3dd9d7fdb10d9e19745ae2cc36be5
-rw-r--r--client/src/com/vaadin/client/ui/VScrollTable.java19
-rw-r--r--uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java86
-rw-r--r--uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java72
3 files changed, 169 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java
index 42fef9f0c0..961e32b290 100644
--- a/client/src/com/vaadin/client/ui/VScrollTable.java
+++ b/client/src/com/vaadin/client/ui/VScrollTable.java
@@ -3138,6 +3138,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
&& Util.isTouchEventOrLeftMouseButton(event)) {
dragging = false;
DOM.releaseCapture(getElement());
+
+ if (Util.isTouchEvent(event)) {
+ /*
+ * Prevent using in e.g. scrolling and prevent generated
+ * events.
+ */
+ event.preventDefault();
+ event.stopPropagation();
+ }
if (moved) {
hideFloatingCopy();
tHead.removeSlotFocus();
@@ -3149,14 +3158,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
reOrderColumn(cid, closestSlot);
}
}
- }
- if (Util.isTouchEvent(event)) {
- /*
- * Prevent using in e.g. scrolling and prevent generated
- * events.
- */
- event.preventDefault();
- event.stopPropagation();
+ moved = false;
+ break;
}
}
diff --git a/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java
new file mode 100644
index 0000000000..e9c948ddf7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDrag.java
@@ -0,0 +1,86 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Window;
+
+public class HeaderRightClickAfterDrag extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Table table = new Table();
+ table.setContainerDataSource(new BeanItemContainer<TestBean>(
+ TestBean.class));
+ for (int i = 0; i < 10; i++) {
+ table.addItem(new TestBean(i));
+ }
+
+ table.setPageLength(10);
+ table.setColumnReorderingAllowed(true);
+ table.addHeaderClickListener(new Table.HeaderClickListener() {
+ @Override
+ public void headerClick(Table.HeaderClickEvent event) {
+ if (MouseEventDetails.MouseButton.RIGHT.equals(event
+ .getButton())) {
+ Window window = new Window("Right-clicked:", new Label(
+ "<center>"
+ + event.getPropertyId().toString()
+ .toUpperCase() + "</center>",
+ ContentMode.HTML));
+ window.setPositionX(event.getClientX());
+ window.setPositionY(event.getClientY());
+ window.setResizable(false);
+ addWindow(window);
+ }
+ }
+ });
+
+ addComponent(table);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "1) Right click a column header and see a popup<br>"
+ + "2) Reorder (or at least start dragging) that column<br>"
+ + "3) Right click that same column header, and you should get a popup again.<br>"
+ + "Before fix: no popup, unless you first left-click the header.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15167;
+ }
+
+ public class TestBean {
+
+ private String foo, bar, baz, fiz;
+
+ public TestBean(int i) {
+ foo = "Foo " + i;
+ bar = "Bar " + i;
+ baz = "Baz " + i;
+ fiz = "Fix " + i;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ public String getBar() {
+ return bar;
+ }
+
+ public String getBaz() {
+ return baz;
+ }
+
+ public String getFiz() {
+ return fiz;
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java
new file mode 100644
index 0000000000..f5f8bcce2a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/HeaderRightClickAfterDragTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2014 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.tests.components.table;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests whether right-click on a column header works after the column is
+ * dragged.
+ *
+ * @author Vaadin Ltd
+ */
+public class HeaderRightClickAfterDragTest extends MultiBrowserTest {
+
+ @Test
+ public void dragAndRightClick() {
+ openTestURL();
+
+ waitForElementPresent(By.className("v-table"));
+
+ TableElement table = $(TableElement.class).first();
+ TestBenchElement header0 = table.getHeaderCell(0);
+ Actions actions = new Actions(getDriver());
+ actions.contextClick(header0).perform();
+
+ // check that right-click opened a window
+ waitForElementPresent(By.className("v-window"));
+
+ closeWindow();
+
+ actions.clickAndHold(header0).moveToElement(table.getHeaderCell(1))
+ .release();
+
+ actions.contextClick(header0).perform();
+
+ // check that right-click still opened a window
+ waitForElementPresent(By.className("v-window"));
+ }
+
+ private void closeWindow() {
+ WindowElement window = $(WindowElement.class).first();
+ window.findElement(By.className("v-window-closebox")).click();
+ waitUntil(new ExpectedCondition<Boolean>() {
+ @Override
+ public Boolean apply(WebDriver driver) {
+ return findElements(By.className("v-window")).isEmpty();
+ }
+ });
+ }
+}