/
ShellHasChildrenOrIsNotAvailable.java
74 lines (65 loc) · 2.23 KB
/
ShellHasChildrenOrIsNotAvailable.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
66
67
68
69
70
71
72
73
74
/*******************************************************************************
* 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.swt.condition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.reddeer.common.condition.AbstractWaitCondition;
import org.eclipse.reddeer.common.exception.RedDeerException;
import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.core.handler.WidgetHandler;
import org.eclipse.reddeer.core.lookup.ShellLookup;
import org.eclipse.reddeer.swt.api.Shell;
/**
* Condition is met when shell has children or is not available anymore
* @author rawagner
*
*/
public class ShellHasChildrenOrIsNotAvailable extends AbstractWaitCondition {
private Shell shell;
private static final Logger log = Logger.getLogger(ShellHasChildrenOrIsNotAvailable.class);
private List<org.eclipse.swt.widgets.Shell> resultChildren;
/**
* Default constructor.
* @param shell instance of shell to test
*/
public ShellHasChildrenOrIsNotAvailable(Shell shell) {
this.shell = shell;
this.resultChildren = new ArrayList<>();
}
@Override
public boolean test() {
org.eclipse.swt.widgets.Shell swtShell = shell.getSWTWidget();
try {
this.resultChildren = Arrays.asList(ShellLookup.getInstance().getShells(swtShell));
} catch (RedDeerException e) {
if(swtShell != null){
return WidgetHandler.getInstance().isDisposed(swtShell);
}
return true;
}
log.debug("number of child shells: " + this.resultChildren.size());
if (this.resultChildren.size() > 0) {
return true;
}
return false;
}
@Override
public String description() {
return "Shell has children or is not available.";
}
@SuppressWarnings("unchecked")
@Override
public List<org.eclipse.swt.widgets.Shell> getResult() {
return this.resultChildren.isEmpty() ? null : this.resultChildren;
}
}