Merge "Bug 259908: Double click listeners are notified now on table.doubleclick: Changed Table.doubleClickXY() to send SWT.DefaultSelection in order to notify double click listener as suggested in bug comment."
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTableDoubleClickListenerTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTableDoubleClickListenerTest.java
new file mode 100644
index 0000000..2d5aaf1
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTableDoubleClickListenerTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Kristine Jetzke and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kristine Jetzke - initial implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.UIThread;
+import org.eclipse.swtbot.swt.finder.test.AbstractSWTTest;
+import org.junit.Test;
+
+public class SWTBotTableDoubleClickListenerTest extends AbstractSWTTest {
+
+ @Test
+ public void doubleClickOnCell() throws Exception {
+ bot.table().doubleClick(0, 0);
+ assertEquals("row 1", bot.label().getText());
+ bot.table().doubleClick(1, 0);
+ assertEquals("row 2", bot.label().getText());
+ }
+
+ @UIThread
+ public void runUIThread() {
+ Display display = Display.getDefault();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new TableViewerWithDoubleClickListener(shell);
+ shell.open();
+ }
+
+ private static class TableViewerWithDoubleClickListener {
+
+ public TableViewerWithDoubleClickListener(Shell shell) {
+ final Label label = new Label(shell, SWT.NONE);
+
+ final TableViewer viewer = new TableViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION);
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+
+ label.setText(((StructuredSelection) event.getSelection())
+ .getFirstElement().toString());
+ }
+ });
+ viewer.setInput(new String[] { "row 1", "row 2" });
+ }
+
+ }
+}
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemDoubleClickListenerTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemDoubleClickListenerTest.java
new file mode 100644
index 0000000..7fc7012
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemDoubleClickListenerTest.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Kristine Jetzke and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Kristine Jetzke - initial implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.UIThread;
+import org.eclipse.swtbot.swt.finder.test.AbstractSWTTest;
+import org.junit.Test;
+
+public class SWTBotTreeItemDoubleClickListenerTest extends AbstractSWTTest {
+
+ @Test
+ public void doubleClickOnCell() throws Exception {
+ final SWTBotTreeItem treeItem1 = bot.tree().getTreeItem("1");
+ treeItem1.doubleClick();
+ assertEquals("1", bot.label().getText());
+ treeItem1.expand().getNode(0).doubleClick();
+ assertEquals("1 child 1", bot.label().getText());
+
+ final SWTBotTreeItem treeItem2 = bot.tree().getTreeItem("2");
+ treeItem2.doubleClick();
+ assertEquals("2", bot.label().getText());
+ treeItem2.expand().getNode(1).doubleClick();
+ assertEquals("2 child 2", bot.label().getText());
+
+ }
+
+ @UIThread
+ public void runUIThread() {
+ Display display = Display.getDefault();
+
+ Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+ new TreeViewerWithDoubleClickListener(shell);
+ shell.open();
+ }
+
+ private static class TreeViewerWithDoubleClickListener {
+
+ public TreeViewerWithDoubleClickListener(Shell shell) {
+ final Label label = new Label(shell, SWT.NONE);
+
+ final TreeViewer viewer = new TreeViewer(shell, SWT.BORDER
+ | SWT.FULL_SELECTION);
+ viewer.setContentProvider(new ITreeContentProvider() {
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean hasChildren(Object element) {
+ return !(element instanceof String);
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof Model[]) {
+ return (Object[]) inputElement;
+ }
+ if (inputElement instanceof Model) {
+ return ((Model) inputElement).children.toArray();
+ }
+ return new Object[0];
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Model[]) {
+ return (Object[]) parentElement;
+ }
+ if (parentElement instanceof Model) {
+ return ((Model) parentElement).children.toArray();
+ }
+ return new Object[0];
+ }
+ });
+
+ viewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+
+ label.setText(((StructuredSelection) event.getSelection())
+ .getFirstElement().toString());
+ }
+ });
+
+ viewer.setInput(new Model[] { new Model("1"), new Model("2") });
+ }
+ }
+
+ private static class Model {
+
+ private List<String> children = new ArrayList<String>();
+
+ private String name;
+
+ public Model(String name) {
+ this.name = name;
+ children.add(name + " child 1");
+ children.add(name + " child 2");
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ }
+}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTable.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTable.java
index b3d8128..cc4a788 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTable.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2013 Ketan Padegaonkar and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,7 @@
* Hans Schwaebli - http://swtbot.org/bugzilla/show_bug.cgi?id=100
* http://www.inria.fr/ - http://swtbot.org/bugzilla/show_bug.cgi?id=114
* Hans Schwaebli - http://swtbot.org/bugzilla/show_bug.cgi?id=122
+ * Kristine Jetzke - Bug 259908
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;
@@ -417,6 +418,32 @@
}
});
}
+
+ /**
+ * Double-click on the table at given coordinates
+ *
+ * @param x the x co-ordinate of the click
+ * @param y the y co-ordinate of the click
+ */
+ @Override
+ protected void doubleClickXY(int x, int y) {
+ log.debug(MessageFormat.format("Double-clicking on {0}", widget)); //$NON-NLS-1$
+ notify(SWT.MouseEnter);
+ notify(SWT.MouseMove);
+ notify(SWT.Activate);
+ notify(SWT.FocusIn);
+ notify(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1));
+ notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
+ notify(SWT.Selection, createSelectionEvent(SWT.BUTTON1));
+ notify(SWT.MouseDoubleClick, createMouseEvent(x, y, 1, SWT.BUTTON1, 2));
+ notify(SWT.DefaultSelection); // super implementation misses this line. Required for notification of double click listeners.
+ notify(SWT.MouseHover);
+ notify(SWT.MouseMove);
+ notify(SWT.MouseExit);
+ notify(SWT.Deactivate);
+ notify(SWT.FocusOut);
+ log.debug(MessageFormat.format("Double-clicked on {0}", widget)); //$NON-NLS-1$
+ }
/**
* Asserts that the row and column are legal for this instance of the table.