tmf.ui.swtbot: add filterview tests
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / shared / org / eclipse / tracecompass / tmf / ui / swtbot / tests / shared / ConditionHelpers.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Alexandre Montplaisir - Replaced separate Condition objects by anonymous classes
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared;
15
16
17 import org.eclipse.jface.wizard.IWizardContainer;
18 import org.eclipse.jface.wizard.IWizardPage;
19 import org.eclipse.jface.wizard.Wizard;
20 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
21 import org.eclipse.swtbot.swt.finder.SWTBot;
22 import org.eclipse.swtbot.swt.finder.waits.ICondition;
23 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
24 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
25 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
26
27 /**
28 * Is a tree node available
29 *
30 * @author Matthew Khouzam
31 */
32 public final class ConditionHelpers {
33
34 private ConditionHelpers() {}
35
36 /**
37 * Provide default implementations for some {@link ICondition} methods.
38 */
39 private abstract static class SWTBotTestCondition implements ICondition {
40
41 @Override
42 public abstract boolean test() throws Exception;
43
44 @Override
45 public final void init(SWTBot bot) {
46 }
47
48 @Override
49 public final String getFailureMessage() {
50 return null;
51 }
52 }
53
54 /**
55 * Is a tree node available
56 *
57 * @param name
58 * the name of the node
59 * @param tree
60 * the parent tree
61 * @return true or false, it should swallow all exceptions
62 */
63 public static ICondition IsTreeNodeAvailable(final String name, final SWTBotTree tree) {
64 return new SWTBotTestCondition() {
65 @Override
66 public boolean test() throws Exception {
67 try {
68 final SWTBotTreeItem[] treeItems = tree.getAllItems();
69 for (SWTBotTreeItem ti : treeItems) {
70 final String text = ti.getText();
71 if (text.equals(name)) {
72 return true;
73 }
74 }
75 } catch (Exception e) {
76 }
77 return false;
78 }
79 };
80 }
81
82 /**
83 * Is the treeItem's node available
84 *
85 * @param name
86 * the name of the node
87 * @param treeItem
88 * the treeItem
89 * @return true or false, it should swallow all exceptions
90 */
91 public static ICondition IsTreeChildNodeAvailable(final String name, final SWTBotTreeItem treeItem) {
92 return new SWTBotTestCondition() {
93 @Override
94 public boolean test() throws Exception {
95 try {
96 return treeItem.getNode(name) != null;
97 } catch (Exception e) {
98 }
99 return false;
100 }
101 };
102 }
103
104 /**
105 * Checks if the wizard's shell is null
106 *
107 * @param wizard
108 * the null
109 * @return false if either are null
110 */
111 public static ICondition isWizardReady(final Wizard wizard) {
112 return new SWTBotTestCondition() {
113 @Override
114 public boolean test() throws Exception {
115 if (wizard.getShell() == null) {
116 return false;
117 }
118 return true;
119 }
120 };
121 }
122
123 /**
124 * Is the wizard on the page you want?
125 *
126 * @param wizard
127 * wizard
128 * @param page
129 * the desired page
130 * @return true or false
131 */
132 public static ICondition isWizardOnPage(final Wizard wizard, final IWizardPage page) {
133 return new SWTBotTestCondition() {
134 @Override
135 public boolean test() throws Exception {
136 if (wizard == null || page == null) {
137 return false;
138 }
139 final IWizardContainer container = wizard.getContainer();
140 if (container == null) {
141 return false;
142 }
143 IWizardPage currentPage = container.getCurrentPage();
144 return page.equals(currentPage);
145 }
146 };
147 }
148
149 /**
150 * Wait for a view to close
151 *
152 * @param view
153 * bot view for the view
154 * @return true if the view is closed, false if it's active.
155 */
156 public static ICondition ViewIsClosed(final SWTBotView view) {
157 return new SWTBotTestCondition() {
158 @Override
159 public boolean test() throws Exception {
160 return (view != null) && (!view.isActive());
161 }
162 };
163 }
164
165 /**
166 * Wait till table cell has a given content.
167 *
168 * @param table
169 * the table bot reference
170 * @param content
171 * the content to check
172 * @param row
173 * the row of the cell
174 * @param column
175 * the column of the cell
176 * @return ICondition for verification
177 */
178 public static ICondition isTableCellFilled(final SWTBotTable table,
179 final String content, final int row, final int column) {
180 return new SWTBotTestCondition() {
181 @Override
182 public boolean test() throws Exception {
183 try {
184 String cell = table.cell(row, column);
185 if( cell == null ) {
186 return false;
187 }
188 return cell.endsWith(content);
189 } catch (Exception e) {
190 }
191 return false;
192 }
193 };
194 }
195 }
This page took 0.035573 seconds and 5 git commands to generate.