Custom action [message #1039562] |
Fri, 12 April 2013 05:48  |
Eclipse User |
|
|
|
Hi,
I am using Jubula 2.0.0.2013281048 (nightly build) installed into Eclipse 4.2
I would like to add a new action to SWT.Label. For example to check the tooltipText. I know it is possible to check it with the "checkProperty" but this example is just to make my problem more easy to explain.
I have already created a new tester class for Composite with action which is working fine.
This is what I did in the label case to add a new action:
1. I added this to the ComponentConfiguration.xml
<toolkitComponent type="org.eclipse.swt.widgets.Label2" visible="true">
<realizes>guidancer.abstract.SwtLabel</realizes>
<testerClass>org.eclipse.jubula.rc.swt.tester.MyLabelTester</testerClass>
<componentClass name="org.eclipse.swt.widgets.Label" />
<action name="M8CompSystem.CheckTooltip" >
<method>rcCheckTooltip</method>
<param name="M8CompSystem.TooltipText">
<type>java.lang.String</type>
</param>
<param name="CompSystem.Operator">
<type>java.lang.String</type>
<defaultValue>equals</defaultValue>
<valueSet>
<element name="CompSystem.Equals" value="equals"/>
<element name="CompSystem.NotEquals" value="not equals"/>
<element name="CompSystem.MatchesRegExp" value="matches"/>
<element name="CompSystem.SimpleMatch" value="simple match"/>
</valueSet>
</param>
</action>
</toolkitComponent>
2. Created MyLabelTester which extends the org.eclipse.jubula.rc.common.tester.LabelTester
3. Added
public void rcCheckTooltip(String expectedTooltip,String operator) {...}
4. Implemented IAdapterFactory
public class MyExtensionAdapterFactory implements IAdapterFactory
{
@Override
public Class[] getSupportedClasses()
{
return new Class[]{Label.class};
}
@Override
public Object getAdapter(Class targetedClass,Object objectToAdapt)
{
if (targetedClass.isAssignableFrom(IComponent.class))
{
if (objectToAdapt instanceof Label)
{
return new ControlAdapter(objectToAdapt);
}
}
return null;
}
}
5. When I want to add a new test for the Label "New Test Step" I can select the my toolkit component which names the SWT.Label to Label2 and from the "Action" combo I can select my action to check the tooltip.
But when I run the test I got an error message "Operation not supperted by the selected toolkit."
For me it seems that not my MyLabelTest class is used but the original LabelTester.
I looked at the org.eclipse.jubula.rc.common.adaptable.AdapterFactoryRegistry.getAdapter(). If this is the code which decides which adapter to use then I think always the first one will be given back. For the same class more adapters are mapped and probably my M8ExtensionAdapterFactory is at the end of the list.
public Object getAdapter(Class targetAdapterClass,Object objectToAdapt)
{
Collection registeredFactories = null;
Class superClass = objectToAdapt.getClass();
while ((registeredFactories == null) && (superClass != Object.class))
{
registeredFactories = (Collection) this.m_registrationMap.get(superClass);
superClass = superClass.getSuperclass();
}
if (registeredFactories == null)
{
return null;
}
Iterator iterator = registeredFactories.iterator();
while (iterator.hasNext())
{
IAdapterFactory adapterFactory = (IAdapterFactory) iterator.next();
Object object = adapterFactory.getAdapter(targetAdapterClass,objectToAdapt);
if (object != null)
{
return object;
}
}
return null;
}
Is there a way to use MyExtensionAdapterFactory with the SWT.Label?
Thanks in advance
Gabor
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.30230 seconds