/
ShellMatchingMatcherIsActive.java
65 lines (57 loc) · 1.93 KB
/
ShellMatchingMatcherIsActive.java
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
/*******************************************************************************
* Copyright (c) 2017 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.core.condition;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.reddeer.common.condition.AbstractWaitCondition;
import org.eclipse.reddeer.common.matcher.AndMatcher;
import org.eclipse.reddeer.core.util.InstanceValidator;
import org.eclipse.reddeer.core.lookup.ShellLookup;
/**
* Condition is met when a shell with specified text (title) is active.
*
* @author Vlado Pakan
* @author jniederm
*/
public class ShellMatchingMatcherIsActive extends AbstractWaitCondition {
private AndMatcher matcher;
/**
* Constructs ShellWithTextIsActive wait condition. Condition is met when
* a shell matching matcher is active.
*
* @param matchers matchers matching shell
*/
public ShellMatchingMatcherIsActive(org.hamcrest.Matcher<?>... matchers) {
InstanceValidator.checkNotNull(matchers, "matchers");
AndMatcher am = new AndMatcher(matchers);
this.matcher = am;
}
/* (non-Javadoc)
* @see org.eclipse.reddeer.common.condition.WaitCondition#test()
*/
@Override
public boolean test() {
Shell currentActiveShell = ShellLookup.getInstance().getCurrentActiveShell();
if(currentActiveShell != null){
if(matcher.matches(currentActiveShell)){
return true;
}
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.reddeer.common.condition.AbstractWaitCondition#description()
*/
@Override
public String description() {
return "shell matching " + matcher.toString() + " is active";
}
}