/
DefaultExpandableComposite.java
152 lines (136 loc) · 4.79 KB
/
DefaultExpandableComposite.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*******************************************************************************
* 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.uiforms.impl.expandablecomposite;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.eclipse.reddeer.common.matcher.MatcherBuilder;
import org.eclipse.reddeer.core.lookup.WidgetLookup;
import org.eclipse.reddeer.core.matcher.ClassMatcher;
import org.eclipse.reddeer.core.matcher.WithMnemonicTextMatcher;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
/**
* Default implementation of {@link ExpandableComposite}.
*
* @author Radoslav Rabara
*
*/
public class DefaultExpandableComposite extends AbstractExpandableComposite {
/**
* {@link StrictClassMatcher} is used when the {@link WidgetLookup} is
* searching for {@link ExpandableComposite} because WidgetLookup
* is matching for {@link Widget} with given type or with type extending
* given type. The problem is that
* {@link import org.eclipse.ui.forms.widgets.Section} extends
* {@link org.eclipse.ui.forms.widgets.ExpandableComposite} so the
* WidgetLookup can return Section instead of ExpandableComposite.
*/
private static final StrictClassMatcher classMatcher = new StrictClassMatcher();
/**
* Represents the first expandable composite.
*/
public DefaultExpandableComposite() {
this(0);
}
public DefaultExpandableComposite(ExpandableComposite widget) {
super(widget);
}
/**
* Represents the first expandable composite inside the specified
* {@link ReferencedComposite}.
*
* @param referencedComposite the referenced composite
*/
public DefaultExpandableComposite(ReferencedComposite referencedComposite) {
this(referencedComposite, 0);
}
/**
* Expandable composite that matches given matchers.
*
* @param matchers the matchers
*/
public DefaultExpandableComposite(Matcher<?>... matchers) {
this(null, matchers);
}
/**
* Expandable composite that matches given matchers.
*
* @param referencedComposite the referenced composite
* @param matchers the matchers
*/
public DefaultExpandableComposite(ReferencedComposite referencedComposite, Matcher<?>... matchers) {
this(referencedComposite, 0, matchers);
}
/**
* Represents expandable composite with the specified <var>index</var> that matches given matchers.
*
* @param index expandable composite index
* @param matchers the matchers
*/
public DefaultExpandableComposite(int index, Matcher<?>... matchers) {
this(null, index);
}
/**
* Represents expandable composite inside the specified
* {@link ReferencedComposite} with the specified <var>index</var> that matches given matchers.
*
* @param referencedComposite the referenced composite
* @param index expandable composite index
* @param matchers the matchers
*/
public DefaultExpandableComposite(ReferencedComposite referencedComposite, int index, Matcher<?>... matchers) {
super(referencedComposite, index, MatcherBuilder.getInstance().addMatcher(matchers, classMatcher));
}
/**
* Represents expandable composite with the specified <var>text</var>.
*
* @param text expandable composite text
*/
public DefaultExpandableComposite(String text) {
this(null, text);
}
/**
* Represents expandable composite inside the specified
* {@link ReferencedComposite} with the specified <var>text</var>.
*
* @param referencedComposite the referenced composite
* @param text expandable composite text
*/
public DefaultExpandableComposite(ReferencedComposite referencedComposite, String text) {
this(referencedComposite, 0, new WithMnemonicTextMatcher(text));
}
/**
* The purpose of this class is to match with {@link Widget}
* that has the {@link ExpandableComposite} type.
* Is more strict as {@link ClassMatcher} because it doesn't match
* {@link Widget} with type extending the {@link ExpandableComposite}.
*
* @author Radoslav Rabara
*
*/
private static class StrictClassMatcher extends BaseMatcher<Object> {
@Override
public boolean matches(Object item) {
return ExpandableComposite.class == item.getClass();
}
@Override
public void describeTo(Description description) {
description.appendText("with the ExpandableComposite type");
}
@Override
public String toString() {
return "Matcher matching widget with the ExpandableComposite type";
}
}
}