Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6aae62b988ddce46f672e7be536dbc22b56e8da7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2008, 2015 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
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ketan Padegaonkar - initial API and implementation
 *     Patrick Tasse - Add column header context menu test
 *******************************************************************************/
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.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swtbot.swt.finder.test.AbstractControlExampleTest;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 * @version $Id$
 */
public class SWTBotTableColumnTest extends AbstractControlExampleTest {

	private SWTBotTable	 table;

	@Test
	public void findsTableColumn() throws Exception {
		SWTBotTableColumn header = table.header("Name");
		assertText("Name", header.widget);
		assertEquals(TableColumn.class, header.widget.getClass());
	}

	@Test
	public void clicksTableColumn() throws Exception {
		SWTBotTableColumn header = table.header("Name");
		header.click();

		Text text = bot.textInGroup("Listeners").widget;

		assertTextContains("Selection [13]: SelectionEvent{TableColumn {Name}", text);
		assertTextContains("MouseUp [4]: MouseEvent{Table {}", text);
		assertTextContains("data=null button=1 stateMask=" + toStateMask(524288, table.widget) + " x=0 y=0 count=1}", text);
	}

	@Test
	public void clicksHeaderContextMenuItem() throws Exception {
		Text text = bot.textInGroup("Listeners").widget;

		SWTBotTableColumn header = table.header("Name");
		header.contextMenu("Get Column Header Text").click();
		assertTextContains("Get Column Header Text returned: Name", text);

		header = table.header("Type");
		header.contextMenu("Get Column Header Text").click();
		assertTextContains("Get Column Header Text returned: Type", text);

		header = table.header("Size");
		header.contextMenu("Get Column Header Text").click();
		assertTextContains("Get Column Header Text returned: Size", text);

		header = table.header("Modified");
		header.contextMenu("Get Column Header Text").click();
		assertTextContains("Get Column Header Text returned: Modified", text);
	}

	@Before
	public void prepareExample() throws Exception {
		bot.tabItem("Table").activate();
		bot.radio("SWT.MULTI").click();
		bot.checkBox("Header Visible").select();
		bot.checkBox("Multiple Columns").select();
		bot.checkBox("Popup Menu").select();
		bot.checkBox("Listen").select();
		bot.button("Clear").click();
		table = bot.tableInGroup("Table");
	}
	
}

Back to the top