summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRobin Stocker2013-07-22 06:36:39 (EDT)
committer Robin Stocker2013-07-22 06:36:39 (EDT)
commitd7809f7a28411eca7a94638c7c4e8a8e6ee00a2e (patch)
treed9d1e94d4edd32390c8bd1a6e439b497046467e9
parent80abde2f2203f6313be6e276733dad8ccd7c8a4b (diff)
downloadorg.eclipse.swtbot-d7809f7a28411eca7a94638c7c4e8a8e6ee00a2e.zip
org.eclipse.swtbot-d7809f7a28411eca7a94638c7c4e8a8e6ee00a2e.tar.gz
org.eclipse.swtbot-d7809f7a28411eca7a94638c7c4e8a8e6ee00a2e.tar.bz2
Bug 413401: Add SWTBotTreeColumn for interacting with tree columsrefs/changes/42/14742/1
Note that the implementation is derived from SWTBotTableColumn (including the test). Change-Id: I0204f871c33eddc5817eebac212f3426850e5d8a Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumnTest.java57
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTree.java26
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumn.java87
3 files changed, 170 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumnTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumnTest.java
new file mode 100644
index 0000000..fd34a93
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumnTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Robin Stocker 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:
+ * Robin Stocker - initial implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.assertText;
+import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.assertTextContains;
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swtbot.swt.finder.test.AbstractControlExampleTest;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SWTBotTreeColumnTest extends AbstractControlExampleTest {
+
+ private SWTBotTree tree;
+
+ @Test
+ public void findsTreeColumn() throws Exception {
+ SWTBotTreeColumn header = tree.header("Name");
+ assertText("Name", header.widget);
+ assertEquals(TreeColumn.class, header.widget.getClass());
+ }
+
+ @Test
+ public void clicksTreeColumn() throws Exception {
+ SWTBotTreeColumn header = tree.header("Name");
+ header.click();
+
+ Text text = bot.textInGroup("Listeners").widget;
+
+ assertTextContains("Selection [13]: SelectionEvent{TreeColumn {Name}", text);
+ assertTextContains("MouseUp [4]: MouseEvent{Tree {}", text);
+ assertTextContains("data=null button=1 stateMask=" + toStateMask(524288, tree.widget) + " x=0 y=0 count=1}", text);
+ }
+
+ @Before
+ public void prepareExample() throws Exception {
+ bot.tabItem("Tree").activate();
+ bot.radio("SWT.MULTI").click();
+ bot.checkBox("Header Visible").select();
+ bot.checkBox("Multiple Columns").select();
+ bot.checkBox("Listen").select();
+ bot.button("Clear").click();
+ tree = bot.treeInGroup("Tree");
+ }
+
+}
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 7fbc6aa..c8739c9 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
@@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swtbot.swt.finder.ReferenceBy;
import org.eclipse.swtbot.swt.finder.SWTBot;
@@ -94,6 +95,8 @@ public class SWTBotTree extends AbstractSWTBot<Tree> {
/**
* Gets the columns of this tree.
+ * <p>
+ * To interact with one of the columns, use {@link #header(String)}.
*
* @return the list of columns in the tree.
*/
@@ -110,6 +113,29 @@ public class SWTBotTree extends AbstractSWTBot<Tree> {
}
/**
+ * Gets the column matching the given label.
+ *
+ * @param label the header text.
+ * @return the header of the tree.
+ * @throws WidgetNotFoundException if the header is not found.
+ * @since 2.1.2
+ */
+ public SWTBotTreeColumn header(final String label) throws WidgetNotFoundException {
+ TreeColumn column = syncExec(new Result<TreeColumn>() {
+ public TreeColumn run() {
+ TreeColumn[] columns = widget.getColumns();
+ for (TreeColumn column : columns) {
+ if (column.getText().equals(label))
+ return column;
+ }
+ return null;
+ }
+ });
+ return new SWTBotTreeColumn(column, widget);
+ }
+
+
+ /**
* Gets the cell data for the given row/column index.
*
* @param row the row index.
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumn.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumn.java
new file mode 100644
index 0000000..79823b8
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotTreeColumn.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Robin Stocker 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:
+ * Robin Stocker - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.WidgetResult;
+import org.hamcrest.SelfDescribing;
+
+/**
+ * Bot for a {@link TreeColumn} widget.
+ * <p>
+ * See {@link SWTBotTree#header(String)} for getting an instance from a tree
+ * bot.
+ *
+ * @since 2.1.2
+ */
+public class SWTBotTreeColumn extends AbstractSWTBot<TreeColumn> {
+
+ private final Tree parent;
+
+ /**
+ * Constructs a new instance of this object.
+ *
+ * @param w the widget.
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ */
+ public SWTBotTreeColumn(final TreeColumn w) throws WidgetNotFoundException {
+ this(w, UIThreadRunnable.syncExec(new WidgetResult<Tree>() {
+ public Tree run() {
+ return w.getParent();
+ }
+ }));
+ }
+
+ /**
+ * Constructs a new instance of this object.
+ *
+ * @param w the widget.
+ * @param parent the parent tree.
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ */
+ public SWTBotTreeColumn(TreeColumn w, Tree parent) throws WidgetNotFoundException {
+ this(w, parent, null);
+ }
+
+ /**
+ * Constructs a new instance of this object.
+ *
+ * @param w the widget.
+ * @param parent the parent tree.
+ * @param description the description of the widget, this will be reported by {@link #toString()}
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ */
+ public SWTBotTreeColumn(TreeColumn w, Tree parent, SelfDescribing description) throws WidgetNotFoundException {
+ super(w, description);
+ this.parent = parent;
+ }
+
+ /**
+ * Clicks the item.
+ */
+ @Override
+ public SWTBotTreeColumn click() {
+ waitForEnabled();
+ notify(SWT.Selection);
+ notify(SWT.MouseUp, createMouseEvent(0, 0, 1, SWT.BUTTON1, 1), parent);
+ return this;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+}