Reputation: 193
I am trying to get the Text from a Composite in Eclipse using the SWTbot API.
I have Composite which contains Main Group and That Main Group Contains Child Groups.
The problem i am facing is i am not able to get the Text Inside the Composite, is there a way in Eclipse to get that Text.
I have attached the Image of my Composite, in which i want to get all the text like name,Min Version etc.
Please help, Its kind of blocker for my project.
Upvotes: 2
Views: 1222
Reputation: 170733
Not directly, but you can do it in this way:
public getContainedText(Control c) {
return getContainedText(c, new ArrayList<String>());
}
private getContainedText(Control c, List<String> strings) {
if (c instanceof Label) {
strings.add(((Label) c).getText();
} else if (c instanceof Text) {
strings.add(((Text) c).getText();
}
// and so on for other control types you want to handle
// and for text you are interested in.
// Or as an approximation, use reflection to check if
// c has getText method and call it, but this will miss
// List, Combo, etc.
if (c instanceof Composite) {
for (Control child : ((Composite) c).getChildren()) {
getContainedText(child, strings);
}
}
}
Upvotes: 1