Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Bouchet2014-11-18 08:53:07 +0000
committerStephane Bouchet2014-11-25 10:38:29 +0000
commita254e4a72b35410226e643b3fd64c66a0fc01105 (patch)
tree8de8761600eb67a2f27bb3699b0f523263fd1fe8
parent54de91f0874368027f54b423ac035d13fadbedad (diff)
downloadorg.eclipse.swtbot-a254e4a72b35410226e643b3fd64c66a0fc01105.tar.gz
org.eclipse.swtbot-a254e4a72b35410226e643b3fd64c66a0fc01105.tar.xz
org.eclipse.swtbot-a254e4a72b35410226e643b3fd64c66a0fc01105.zip
[451547 ] contextMenu on multiselection on navigator tree not supported
The use case is to be able to select treeitem on navigator view for instance, in different directories and then call the contextMenu, to perform a "Compare with each other" action on the selected items. Change-Id: I646a08410d9a018d37c044adfcf83430ce8af478 Signed-off-by: Stephane Bouchet <stephane.bouchet@intel.com> Bug: https://bugs.eclipse.org/451547
-rw-r--r--org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/widgets/SWTBotEclipseProjectTest.java19
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java12
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java28
3 files changed, 29 insertions, 30 deletions
diff --git a/org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/widgets/SWTBotEclipseProjectTest.java b/org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/widgets/SWTBotEclipseProjectTest.java
index 7acba00e..fe9b225c 100644
--- a/org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/widgets/SWTBotEclipseProjectTest.java
+++ b/org.eclipse.swtbot.eclipse.finder.test/src/org/eclipse/swtbot/eclipse/finder/widgets/SWTBotEclipseProjectTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Lorenzo Bettini.
+ * Copyright (c) 2012, 2014 Lorenzo Bettini 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Lorenzo Bettini - initial API and implementation
+ * Stephane Bouchet (Intel Corporation) - added testCase for bug 451547
*******************************************************************************/
package org.eclipse.swtbot.eclipse.finder.widgets;
@@ -95,9 +96,6 @@ public class SWTBotEclipseProjectTest {
@Test
public void canAccessContextMenuWithSubmenus() {
- // this fails in e4 with current implementation of
- // SWTBotTreeItem.contextMenu
- // since "Open With" has submenus
javaClassFileTreeItem().contextMenu("Open With");
}
@@ -108,12 +106,19 @@ public class SWTBotEclipseProjectTest {
@Test
public void canAccessContextMenuSubmenu() {
- // this fails in e4 with current implementation of
- // SWTBotTreeItem.contextMenu
- // since "Open With" has submenus
SWTBotMenu openWithMenu = javaClassFileTreeItem().contextMenu("Open With");
openWithMenu.menu("Text Editor").click();
}
+
+ @Test
+ public void canAccessContextMenuOnMultipleSelection() {
+ NewJavaClass javaClass2 = new NewJavaClass();
+ javaClass2.createClass("org.eclipse.swtbot.eclipse.test.other", CLASS_NAME);
+ SWTBotTreeItem javaClass2item = packageExplorerTree().expandNode(PROJECT_NAME, "src", "org.eclipse.swtbot.eclipse.test.other",
+ CLASS_FILE_NAME);
+ packageExplorerTree().select(javaClassFileTreeItem(), javaClass2item);
+ packageExplorerTree().contextMenu("Compare With").menu("Each Other").click();
+ }
private SWTBotTreeItem javaClassFileTreeItem() {
return packageExplorerTree().expandNode(PROJECT_NAME, "src",
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java
index 58400b1d..cf0739ce 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Ketan Padegaonkar and others.
+ * Copyright (c) 2008, 2014 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
@@ -8,6 +8,7 @@
* Contributors:
* Ketan Padegaonkar - initial API and implementation
* Kristine Jetzke - Bug 420121
+ * Stephane Bouchet (Intel Corporation) - Bug 451547
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;
@@ -23,6 +24,7 @@ import org.eclipse.swtbot.swt.finder.ReferenceBy;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.SWTBotWidget;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper;
import org.eclipse.swtbot.swt.finder.results.ArrayResult;
import org.eclipse.swtbot.swt.finder.results.BoolResult;
import org.eclipse.swtbot.swt.finder.results.IntResult;
@@ -135,7 +137,6 @@ public class SWTBotTree extends AbstractSWTBot<Tree> {
return new SWTBotTreeColumn(column, widget);
}
-
/**
* Gets the cell data for the given row/column index.
*
@@ -332,7 +333,7 @@ public class SWTBotTree extends AbstractSWTBot<Tree> {
*/
public SWTBotTreeItem expandNode(String... nodes) throws WidgetNotFoundException {
// TODO: this method should be made iterative instead of recursive
- Assert.isNotEmpty((Object[])nodes);
+ Assert.isNotEmpty((Object[]) nodes);
log.debug(MessageFormat.format("Expanding nodes {0} in tree {1}", StringUtils.join(nodes, ">"), this));
@@ -507,4 +508,9 @@ public class SWTBotTree extends AbstractSWTBot<Tree> {
});
}
+ @Override
+ public SWTBotMenu contextMenu(String text) {
+ waitForEnabled();
+ return new SWTBotMenu(ContextMenuHelper.contextMenu(this, text));
+ }
}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java
index 00a3d8a5..af1154ae 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java
@@ -11,6 +11,7 @@
* Ketan Patel - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259720
* Kristine Jetzke - Bug 379185
* Aparna Argade(Cadence Design Systems, Inc.) - Bug 363916
+ * Stephane Bouchet (Intel Corporation) - Bug 451547
*******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;
@@ -19,9 +20,9 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
@@ -461,17 +462,17 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
/**
* Get the cell bounds. widget should be enabled before calling this method.
+ *
* @return the cell bounds
*/
private Rectangle getCellBounds() {
- return syncExec(new Result<Rectangle>() {
+ return syncExec(new Result<Rectangle>() {
public Rectangle run() {
return widget.getBounds();
}
});
}
-
/**
* Get the center of the given rectangle.
*
@@ -554,18 +555,7 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
notifyTree(SWT.MouseDown, createMouseEvent(0, 0, 3, 0, 1));
notifyTree(SWT.MouseUp, createMouseEvent(0, 0, 3, 0, 1));
notifyTree(SWT.MenuDetect);
- SWTBotMenu contextMenu = null;
- try {
- contextMenu = super.contextMenu(tree, text);
- } catch (WidgetNotFoundException e) {
- // in e4, if the context menu contains submenus it appears
- // as disposed after detection, so we use the ContextMenuHelper
- if (e.getMessage().contains("was disposed")) {
- return new SWTBotMenu(ContextMenuHelper.contextMenu(swtBotTree, text));
- } else
- throw e;
- }
- return contextMenu;
+ return new SWTBotMenu(ContextMenuHelper.contextMenu(swtBotTree, text));
}
/**
@@ -722,7 +712,6 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
});
}
-
/**
* Gets the tree item matching the given name.
*
@@ -773,7 +762,6 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
}
});
}
-
public boolean isGrayed() {
assertIsCheck();
@@ -789,8 +777,8 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
return UIThreadRunnable.syncExec(new Result<Rectangle>() {
public Rectangle run() {
return display.map(widget.getParent(), null, widget.getBounds());
- }
- });
- }
+ }
+ });
+ }
}

Back to the top