How to obtain a component of the screen. [message #512306] |
Thu, 04 February 2010 16:08 |
Caio Bulgarelli Messages: 16 Registered: February 2010 |
Junior Member |
|
|
During the MACRO, I need to call "hooks" in order to do some Java verifications (JUnit).
For example: If a Button is enabled or if the Text is correct...
I found out this diagram "Googling" on the Web:
Figure 1. An SWT application from different perspectives.
OK, Now I need a help.
I need to get a String in TextBox inside a Shell.
I got success, but my code was a little confused. =/
Look:
A part of MACRO (XML):
...
<command descriptive="Android" type="item-expand" referenceId="21" value="true">
<item referenceId="22"/>
</command>
<command descriptive="Launch" type="item-select" referenceId="21">
<item referenceId="23"/>
</command>
<command type="verification" contextId=" shell/org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDia log " location="/PluginProject/src" resource="pluginproject.VerificationHookClass003" hook="checkSettings:Qorg.eclipse.swt.widgets.Shell;"/>
<command descriptive="OK" type="select" referenceId="25"/>
</shell>
...
A part of JUnit (JAVA):
public void checkSettings(org.eclipse.swt.widgets.Shell arg0)
throws Exception
{
...
Point p1 = new Point (130, 0); //The 1º TextBox
Point p2 = new Point (130, 24); // The 2º TextBox
Control[] c = arg0.getChildren(); //in oder to get all Components of Shell
//Call function to get the Text inside in the 1º TextBox
recursiveFunction(c, p1);
assertEquals(s, "-no-window");
System.out.println("" + s);
//Call function to get the Text inside in the 2º TextBox
recursiveFunction(c, p2);
assertEquals(s, "android.process.acore");
System.out.println("" + s);
}
/**
* This function collects all components inside a Wizard.
* @param c
* @param p
*/
private void recursiveFunction(Control[] c, Point p) {
for (int k=0 ; k<c.length ; k++)
{
if( ( c[k]) instanceof Text && p.equals(c[k].getLocation())){
s = ((Text) c[k]).getText();
}
else if( ( c[k]) instanceof Composite )
recursiveFunction( ((Composite) c[k]).getChildren(), p );
}
}
The Result is:
OK, I did... However, Can someone resolve in a better way? Without using "points"?
Thanks a lot!
--
Caio Bulgarelli
R&D - CM - MOTODEV
MOTOROLA BRAZIL
|
|
|
|
Powered by
FUDForum. Page generated in 0.03045 seconds