On 8/29/11 8:28 AM, Mikel Ugarte wrote:
> Hi,
>
> I'm doing some tests with SWTBot, and I need to set a value in a tree
> cell which renderer is a ComboBox ?
> Does anyone already do that ?
> Can we get the tree item's cell renderer ?
> Thanks
There's a test (http://goo.gl/r2757) in SWTBot that clicks on a cell and
edits the contents of a textbox in that tablecell. You'd need something
similar for combobox.
I found an answer to my question on the patch proposed in this eclipse's bug :
[HTTPS]bugs[dot]eclipse[dot]org/bugs/show_bug[dot]cgi?id=282408
/**
* Return the cell editor control associated to the TreeItem.
*
* @param item the tree item
* @param clazz Text or CCombo are the only one supported for now
* @return The associated SWTBot adapter for the control.
*/
public static AbstractSWTBot< ? extends Widget > getCellEditor(final SWTBotTreeItem item,
final Class< ? extends Widget > clazz) {
return UIThreadRunnable.syncExec(item.display, new Result< AbstractSWTBot< ? extends Widget > >() {
@Override
public AbstractSWTBot< ? extends Widget > run() {
if (!clazz.equals(Text.class) && !clazz.equals(CCombo.class)) {
throw new IllegalArgumentException("The class " + clazz.toString() + " is not supported yet!");
}
AbstractSWTBot< ? extends Widget > botEditorWidget;
final SWTBot bot = new SWTBot(item.widget.getParent());
final Matcher< ? extends Widget > matcher = widgetOfType(clazz);
final Widget editorWidget = bot.widget(matcher);
botEditorWidget = null;
if (clazz.equals(Text.class)) {
botEditorWidget = new SWTBotText((Text) editorWidget, matcher);
} else if (clazz.equals(CCombo.class)) {
botEditorWidget = new SWTBotCCombo((CCombo) editorWidget, matcher);
}
return botEditorWidget;
}
});
}
The method only works for cCombo and Text fields, but it covers my needs