summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-04-27 16:58:55 +0300
committerVaadin Code Review <review@vaadin.com>2014-08-25 13:52:16 +0000
commit9ea4409bbe7079887a5a3c497494d4986ddabefd (patch)
tree0140375ae30ac956f9a6e41ad05b3ae70dbdb54e
parent117c45ae1c3753e38c2ac41296ebc043c74b835e (diff)
downloadvaadin-framework-9ea4409bbe7079887a5a3c497494d4986ddabefd.tar.gz
vaadin-framework-9ea4409bbe7079887a5a3c497494d4986ddabefd.zip
Make getMouseEvent() method available in the TargetDetailsImpl (#13416).
Change-Id: Ie2b142fbfbe690aad741c668480e9bb3a1898fb5
-rw-r--r--server/src/com/vaadin/event/dd/TargetDetailsImpl.java10
-rw-r--r--server/src/com/vaadin/ui/Calendar.java3
-rw-r--r--server/src/com/vaadin/ui/DragAndDropWrapper.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetails.java47
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetailsTest.java37
-rw-r--r--uitest/src/com/vaadin/tests/components/table/DndTableTargetDetails.java129
-rw-r--r--uitest/src/com/vaadin/tests/components/table/DndTableTargetDetailsTest.java70
-rw-r--r--uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetails.java48
-rw-r--r--uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java37
9 files changed, 380 insertions, 10 deletions
diff --git a/server/src/com/vaadin/event/dd/TargetDetailsImpl.java b/server/src/com/vaadin/event/dd/TargetDetailsImpl.java
index 1138215f3f..8a6ec506ba 100644
--- a/server/src/com/vaadin/event/dd/TargetDetailsImpl.java
+++ b/server/src/com/vaadin/event/dd/TargetDetailsImpl.java
@@ -18,6 +18,8 @@ package com.vaadin.event.dd;
import java.util.HashMap;
import java.util.Map;
+import com.vaadin.shared.MouseEventDetails;
+
/**
* A HashMap backed implementation of {@link TargetDetails} for terminal
* implementation and for extension.
@@ -41,6 +43,14 @@ public class TargetDetailsImpl implements TargetDetails {
this.dropTarget = dropTarget;
}
+ /**
+ * @return details about the actual event that caused the event details.
+ * Practically mouse move or mouse up.
+ */
+ public MouseEventDetails getMouseEvent() {
+ return MouseEventDetails.deSerialize((String) getData("mouseEvent"));
+ }
+
@Override
public Object getData(String key) {
return data.get(key);
diff --git a/server/src/com/vaadin/ui/Calendar.java b/server/src/com/vaadin/ui/Calendar.java
index 59dfceec9b..888a443be3 100644
--- a/server/src/com/vaadin/ui/Calendar.java
+++ b/server/src/com/vaadin/ui/Calendar.java
@@ -1430,7 +1430,7 @@ public class Calendar extends AbstractComponent implements
@Override
public TargetDetails translateDropTargetDetails(
Map<String, Object> clientVariables) {
- Map<String, Object> serverVariables = new HashMap<String, Object>(1);
+ Map<String, Object> serverVariables = new HashMap<String, Object>();
if (clientVariables.containsKey("dropSlotIndex")) {
int slotIndex = (Integer) clientVariables.get("dropSlotIndex");
@@ -1450,6 +1450,7 @@ public class Calendar extends AbstractComponent implements
currentCalendar.add(java.util.Calendar.DATE, dayIndex);
serverVariables.put("dropDay", currentCalendar.getTime());
}
+ serverVariables.put("mouseEvent", clientVariables.get("mouseEvent"));
CalendarTargetDetails td = new CalendarTargetDetails(serverVariables,
this);
diff --git a/server/src/com/vaadin/ui/DragAndDropWrapper.java b/server/src/com/vaadin/ui/DragAndDropWrapper.java
index 0e2e8f6d2f..6e4ec903d2 100644
--- a/server/src/com/vaadin/ui/DragAndDropWrapper.java
+++ b/server/src/com/vaadin/ui/DragAndDropWrapper.java
@@ -132,15 +132,6 @@ public class DragAndDropWrapper extends CustomComponent implements DropTarget,
}
/**
- * @return details about the actual event that caused the event details.
- * Practically mouse move or mouse up.
- */
- public MouseEventDetails getMouseEvent() {
- return MouseEventDetails
- .deSerialize((String) getData("mouseEvent"));
- }
-
- /**
* @return a detail about the drags vertical position over the wrapper.
*/
public VerticalDropLocation getVerticalDropLocation() {
diff --git a/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetails.java b/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetails.java
new file mode 100644
index 0000000000..f96a04c5a3
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetails.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2013 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.calendar;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.table.DndTableTargetDetails;
+import com.vaadin.ui.Calendar;
+
+/**
+ * Test UI for calendar as a drop target: CalendarTargetDetails should provide
+ * getMouseEvent() method.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndCalendarTargetDetails extends DndTableTargetDetails {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ createSourceTable();
+
+ Calendar calendar = new Calendar();
+ calendar.addStyleName("target");
+ calendar.setDropHandler(new TestDropHandler());
+ calendar.setWidth(100, Unit.PERCENTAGE);
+ addComponent(calendar);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mouse details should be available for CalendarTargetDetails DnD when calendar is a target";
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetailsTest.java b/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetailsTest.java
new file mode 100644
index 0000000000..19413e678f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/DndCalendarTargetDetailsTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2013 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.calendar;
+
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.components.table.DndTableTargetDetailsTest;
+
+/**
+ * Test for mouse details in CalendarTargetDetails class when DnD target is a
+ * calendar.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndCalendarTargetDetailsTest extends DndTableTargetDetailsTest {
+
+ @Override
+ protected WebElement getTarget() {
+ return driver.findElement(By.className("v-datecellslot-even"));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetails.java b/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetails.java
new file mode 100644
index 0000000000..cdac8d1da0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetails.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2000-2013 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 com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.TargetDetailsImpl;
+import com.vaadin.event.dd.acceptcriteria.AcceptAll;
+import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Table.TableDragMode;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Test UI for table as a drop target: AbstractSelectTargetDetails should
+ * provide getMouseEvent() method.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndTableTargetDetails extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ createSourceTable();
+
+ Table target = new Table();
+ BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
+ TestBean.class);
+ container.addBean(new TestBean("target-item"));
+ target.setContainerDataSource(container);
+ target.setPageLength(1);
+ target.addStyleName("target");
+ target.setWidth(100, Unit.PERCENTAGE);
+ target.setDropHandler(new TestDropHandler());
+ addComponent(target);
+ }
+
+ protected void createSourceTable() {
+ Table table = new Table();
+ table.setPageLength(1);
+ table.setDragMode(TableDragMode.ROW);
+ table.setWidth(100, Unit.PERCENTAGE);
+ BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
+ TestBean.class);
+ container.addBean(new TestBean("item"));
+ table.setContainerDataSource(container);
+ addComponent(table);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mouse details should be available for AbstractSelectTargetDetails DnD when table is a target";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 13416;
+ }
+
+ protected static class TestDropHandler implements DropHandler {
+
+ public TestDropHandler() {
+ }
+
+ @Override
+ public void drop(DragAndDropEvent event) {
+ TargetDetailsImpl details = (TargetDetailsImpl) event
+ .getTargetDetails();
+ MouseEventDetails mouseDetails = details.getMouseEvent();
+
+ VerticalLayout layout = (VerticalLayout) details.getTarget()
+ .getUI().getContent();
+
+ Label name = new Label("Button name="
+ + mouseDetails.getButtonName());
+ name.addStyleName("dnd-button-name");
+ layout.addComponent(name);
+ if (mouseDetails.isCtrlKey()) {
+ name.addStyleName("ctrl");
+ }
+ if (mouseDetails.isAltKey()) {
+ name.addStyleName("alt");
+ }
+ if (mouseDetails.isShiftKey()) {
+ name.addStyleName("shift");
+ }
+
+ layout.addComponent(name);
+ }
+
+ @Override
+ public AcceptCriterion getAcceptCriterion() {
+ return AcceptAll.get();
+ }
+
+ }
+
+ public static class TestBean {
+ private String name;
+
+ public TestBean(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetailsTest.java b/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetailsTest.java
new file mode 100644
index 0000000000..36b2a82688
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/DndTableTargetDetailsTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2000-2013 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 java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test for mouse details in AbstractSelectTargetDetails class when DnD target
+ * is a table.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndTableTargetDetailsTest extends MultiBrowserTest {
+
+ @Test
+ public void testMouseDetails() throws IOException, InterruptedException {
+ openTestURL();
+
+ WebElement row = driver.findElement(By
+ .className("v-table-cell-wrapper"));
+
+ Actions actions = new Actions(driver);
+ actions.moveToElement(row);
+ pressKeys(actions);
+ actions.clickAndHold();
+ actions.release(getTarget());
+ actions.build().perform();
+
+ WebElement label = driver.findElement(By.className("dnd-button-name"));
+ Assert.assertEquals("Button name=left", label.getText());
+ checkPressedKeys();
+ }
+
+ protected WebElement getTarget() {
+ return driver.findElement(By.className("target")).findElement(
+ By.className("v-table-row-spacer"));
+ }
+
+ protected void pressKeys(Actions actions) {
+ actions.keyDown(Keys.CONTROL);
+ }
+
+ protected void checkPressedKeys() {
+ Assert.assertTrue(isElementPresent(By.className("ctrl")));
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetails.java b/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetails.java
new file mode 100644
index 0000000000..853e6fe35e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetails.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2013 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.tree;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.table.DndTableTargetDetails;
+import com.vaadin.ui.Tree;
+
+/**
+ * Test UI for tree as a drop target: AbstractSelectTargetDetails should provide
+ * getMouseEvent() method.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndTreeTargetDetails extends DndTableTargetDetails {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ createSourceTable();
+
+ Tree target = new Tree();
+ target.addStyleName("target");
+ target.setWidth(100, Unit.PERCENTAGE);
+ target.addItem("treeItem");
+ target.setDropHandler(new TestDropHandler());
+ addComponent(target);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mouse details should be available for AbstractSelectTargetDetails DnD when tree is a target";
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java b/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java
new file mode 100644
index 0000000000..384034b70f
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/tree/DndTreeTargetDetailsTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2013 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.tree;
+
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.components.table.DndTableTargetDetailsTest;
+
+/**
+ * Test for mouse details in AbstractSelectTargetDetails class when DnD target
+ * is a tree.
+ *
+ * @since 7.3
+ * @author Vaadin Ltd
+ */
+public class DndTreeTargetDetailsTest extends DndTableTargetDetailsTest {
+
+ @Override
+ protected WebElement getTarget() {
+ return driver.findElement(By.className("target"));
+ }
+
+}