Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2019-06-12 11:00:34 -0400
committerPatrick Tasse2019-06-12 11:00:34 -0400
commit2377612904ceab6a49a81b127a6573da5b88a5c8 (patch)
tree4d93f97fc853193036565bf61b56ce159f6cc84e
parentfffc7dc2ce68def00c154d5784781a0b2842cd7c (diff)
downloadorg.eclipse.swtbot-2377612904ceab6a49a81b127a6573da5b88a5c8.tar.gz
org.eclipse.swtbot-2377612904ceab6a49a81b127a6573da5b88a5c8.tar.xz
org.eclipse.swtbot-2377612904ceab6a49a81b127a6573da5b88a5c8.zip
Add SWTBotTreeItem.unselect()2.8.0
Change-Id: I2c2fd37d67a359f6e9b126d419ce2b42b343bdf9 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemTest.java14
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItem.java42
2 files changed, 56 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemTest.java
index c0b7b60f..c25f2805 100644
--- a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemTest.java
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeItemTest.java
@@ -176,6 +176,20 @@ public class SWTBotTreeItemTest extends AbstractControlExampleTest {
}
@Test
+ public void unselects() {
+ bot.radio("SWT.MULTI").click();
+ tree = bot.tree();
+ tree.select("Node 1", "Node 2");
+ assertEquals(2, tree.selectionCount());
+ tree.getTreeItem("Node 1").unselect();
+ assertEquals(1, tree.selectionCount());
+ TableCollection selection = tree.selection();
+ assertEquals("Node 2", selection.get(0, 0));
+ tree.getTreeItem("Node 2").unselect();
+ assertEquals(0, tree.selectionCount());
+ }
+
+ @Test
public void canCheckANode() throws Exception {
bot.checkBox("SWT.CHECK").select();
tree = bot.tree();
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 832f2451..642ebc89 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
@@ -360,6 +360,23 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
}
/**
+ * Unselects the current tree item. The tree must have the SWT.MULTI style.
+ *
+ * @return the current node.
+ * @since 2.8
+ */
+ public SWTBotTreeItem unselect() {
+ assertMultiSelect();
+ if (!isSelected()) {
+ return this;
+ }
+ waitForEnabled();
+ setFocus();
+ notifyUnselect(widget);
+ return this;
+ }
+
+ /**
* Click on the tree at given coordinates
*
* @param x the x co-ordinate of the click
@@ -635,6 +652,31 @@ public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> {
}
/**
+ * Unselects the given tree item.
+ *
+ * @param item
+ * tree item to unselect
+ */
+ private Runnable unselectRunnable(final TreeItem item) {
+ return new Runnable() {
+ @Override
+ public void run() {
+ tree.deselect(item);
+ }
+ };
+ }
+
+ /**
+ * Unselects the specified item and sends notifications.
+ *
+ * @param unselected
+ * the tree item to unselect
+ */
+ private void notifyUnselect(TreeItem unselected) {
+ notifySelect(unselected, SWT.MOD1, unselectRunnable(unselected));
+ }
+
+ /**
* Selects the specified item and sends notifications.
*
* @param selected the tree item to select.

Back to the top